On Wed, 22 Jun 2022 at 12:30, Ronny Meeus via Gcc-help <gcc-help@xxxxxxxxxxx> wrote: > > Hello > > I have a small test program (see below) that uses a member variable > (a) of a derived class (A) as a parameter when calling the constructor > of the base class (A_base). > In fact this is "wrong" code since the base class constructor is > called with an un-initialized variable as input. > > I would expect that the compiler generates a warning/error for this > since the behavior completely depends on the contents of the memory > where the object was allocated from. > In the example code I use a placement new to actually show that the > value seen in the constructor of the base class is the value I used to > fill the memory with. > > I tried it with different gcc versions but none of these are > generating a warning/error for this while other tools like coverity or > sonarqube just report the issue ... > Is it expected that there is no warning generated or do I need to pass > extra compiler options to generate this warning? > > I compile the program like this: > $ g++ -Wall -Wextra -std=gnu++11 /tmp/a.cc You didn't say which version of GCC you're using, but GCC 12 warns about this now: w.C: In constructor 'A::A()': w.C:16:17: warning: member 'A::a' is used uninitialized [-Wuninitialized] 16 | A(): A_base(a) { | ^ Older versions do not warn.