【发布时间】:2022-01-04 16:14:12
【问题描述】:
最新的 Visual Studio 2019 使用/Wall 命令行开关(启用所有警告)编译以下代码:
struct A{};
void f( const std::array<A, 2> & ) {}
int main() {
A x, y;
f( { x, y } );
}
打印警告:
warning C5246: 'std::array<A,2>::_Elems': the initialization of a subobject should be wrapped in braces
但是 GCC 和 Clang 都接受具有最迂腐错误检查的代码,演示:https://gcc.godbolt.org/z/Ps6K6jK1G
确实,所有编译器都接受调用f( { { x, y } } );
MSVC 是否建议它支持更简单的形式而无需额外的大括号?
【问题讨论】:
标签: c++ visual-studio language-lawyer compiler-warnings