int main() {
struct WorkItem {
int node;
unsigned predecessorIndex = 0;
};
auto x = WorkItem { 0 };
return 0;
}
をフィールドを持つ構造体を初期化することはできません。このコードではなく、GCCと、クランと罰金コンパイル:はなぜMSVCとGCCはデフォルト値で
source_file.cpp: In function ‘int main()’:
source_file.cpp:9:25: error: no matching function for call to ‘main()::WorkItem::WorkItem()’ auto x = WorkItem { 0 }; ^
source_file.cpp:9:25: note: candidates are:
source_file.cpp:4:10: note: main()::WorkItem::WorkItem() struct WorkItem { ^
source_file.cpp:4:10: note: candidate expects 0 arguments, 1 provided
source_file.cpp:4:10: note: constexpr main()::WorkItem::WorkItem(const main()::WorkItem&)
source_file.cpp:4:10: note: no known conversion for argument 1 from ‘int’ to ‘const main()::WorkItem&’
source_file.cpp:4:10: note: constexpr main()::WorkItem::WorkItem(main()::WorkItem&&)
source_file.cpp:4:10: note: no known conversion for argument 1 from ‘int’ to ‘main()::WorkItem&&’
またはMSVC:
source_file.cpp(9): error C2440: 'initializing': cannot convert from 'initializer list' to 'main::WorkItem'
source_file.cpp(9): note: No constructor could take the source type, or constructor overload resolution was ambiguous
Clangは標準的な観点から、このコードを誤ってコンパイルしていますか、またはMSVCとGCCが間違っていますか? また、なぜ= 0
を削除するとGCCとMSVCをコンパイルできますか?例えば。
int main() {
struct WorkItem {
int node;
unsigned predecessorIndex = 0;
};
auto x = WorkItem { 0 };
return 0;
}
GCCバージョン:4.9.3 クランバージョン:3.7.0 MSVCバージョン:デフォルトメンバ初期化子と19.00.24215.1
すべてのオプションを含むcompileコマンド全体を表示します。 '-std ='オプションは特に結果に影響します。また、それはg ++の非常に古いバージョンです。 –