Community
cancel
Showing results for 
Search instead for 
Did you mean: 
AWESim
Beginner
71 Views

Warning 2022 Effective C++: Initializer Lists

I have tried many ways of enabling just warning #2022 on my builds with the Intel Compiler. This warning deals with initializer lists matching their declaration in the class. It is my understanding that the C++ standard dictates that when using an initializer list for a constructor, the order in which class members are initialized must match the order in which they are declared in the class declaration. Any deviation results in undefined behavior. I would prefer that the compiler at least warn me about the initializer list being out of order from the class declaration. The only way I have enabled this warning is with the -weffec++ command line option; however, this make the compiler spit out a bunch of warnings that I am not so interested about (only really interested in this specific effective c++ warning at this time).

Any suggestions?
0 Kudos
3 Replies
Judith_W_Intel
Employee
71 Views

I think you mean warning #2023 not #2022, right? The one that looks like:

sptxl8-483> cat t.cpp

struct C {
int i;
C(): j(5), i(3) {;}
int j;
};
sptxl8-484> icpc -Weffc++ -c t.cpp
t.cpp(4): warning #2023: Effective C++ Item 13 initialize fields in order they are declared
C(): j(5), i(3) {;}
^
Anyway since we are not going to make users who don't care about the effective C++ checking pay the price for doing thesemanticanalysis you need to turn on -Weffc++ to execute the code that does the checking.

Once you have added the -Weffc++ option your only choice is to individually disable the warningsyou don't care about (using -diag-disable:number). It looks like there are a total of about 40 separate warnings so it might be painful to disable them all individually but that is your only choice. The effective C++ warningsare in the range from warning 2012 up to and including warning number 2049.

Judy

jimdempseyatthecove
Black Belt
71 Views

Judy,

What about

#pragma warning( enable : 2023 )

Jim
Judith_W_Intel
Employee
71 Views


You can't just enable the warning without also using the -Weffc++ switch, because the warning will only be reached if the effective C++ code checking is turned on. Without the -Weffc++ optionwe don't evenexecute the sections of code that would detect the warning. And once you turn on the -Weffc++ switch then by default you get all the effective c++ warnings.