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
모든 옵션을 포함하여 전체 컴파일 명령을 표시합니다. '-std ='옵션은 특히 결과에 영향을 미칠 것입니다. 또한 g ++의 아주 오래된 버전입니다. –