following code nie skompilować z gcc:nie można używać jednolitego inicjalizacji w liście inicjującej konstruktora z try/catch
struct test {
int x;
test() try : x{123} {
}
catch (...) {
}
};
int main() {}
błędów:
prog.cpp:3:25: error: expected unqualified-id before ‘{’ token
test() try : x{123} {
^
prog.cpp:5:5: error: expected unqualified-id before ‘catch’
catch (...) {
^
prog.cpp: In constructor ‘test::test()’:
prog.cpp:3:23: error: expected ‘{’ at end of input
test() try : x{123} {
^
prog.cpp:3:23: error: expected ‘catch’ at end of input
prog.cpp:3:23: error: expected ‘(’ at end of input
prog.cpp:3:23: error: expected type-specifier at end of input
prog.cpp:3:23: error: expected ‘)’ at end of input
prog.cpp:3:23: error: expected ‘{’ at end of input
Zmiana x{123}
do x(123)
pomaga. Czy to ma (nie) działać w ten sposób?
Clang [kompiluje to] (http://coliru.stacked-crooked.com/a/0e8921393e3a52f1) bez błędów – Praetorian
Wszystko, co można zrobić z aparatami ortodontycznymi i C++ 11 jest bardzo może mieć niepełne i wstawione narożne przypadki kompilatorów przez jakiś czas ... –
@KerrekSB Myślałem, że to błąd na początku, ale w książce Stroustrupa używa on jednolitej inicjalizacji w konstruktorach, z wyjątkiem sytuacji, gdy jest próba/catch, więc to mnie trochę zaintrygowało. – catscradle