Consider the following code:
class A { private: int a; public: A(int a) : a(a) { } }; class B : public A { private: int b; bool init() { b = 0; return true; } public:
Now, trying to compile this code with clang ...
$ clang++ test.cpp -fsyntax-only test.cpp:19:20: warning: field 'b' is uninitialized when used here [-Wuninitialized] B() : A(init() ? b : 0) {} ^ 1 warning generated.
GCC does not print any warnings, even with -Wall -Wextra and -pedantic .
c ++ undefined-behavior constructor clang ++
Thomas
source share