Этот код test.cc
#include <iostream>
int main(){
int a = 10;
bool b {a};
bool c (a);
std::cout << a
<< " "
<< b
<< " "
<< std::endl;
return 0;
}
В clang или gcc
$clang++ -w test.cc
<source>:4:13: error: non-constant-expression cannot be narrowed from type 'int' to 'bool' in initializer list [-Wc++11-narrowing]
bool b {a};
^
<source>:4:13: note: insert an explicit cast to silence this issue
bool b {a};
^
static_cast<bool>( )
1 error generated.
$g++ -w test.cc ; ./a.out
10 1
Clang просто выдает сообщение об ошибке в строке 4, но пропускает строку 5. В то время как в GCC он хорошо компилируется.
Воспроизведено в godbolt: https://godbolt.org/z/rzxTSg
Мне интересно, в чем разница между использованием "b {a};" и "с (а);" для инициализации значения.
Думаю, я мог что-то упустить, может кто-нибудь помочь мне? Спасибо ~