Disabling -Wmissing-field-initializers for GCC?

Kevin Funk krf at gmx.de
Tue Feb 4 10:35:41 UTC 2014


Hey,

Sergey's code causes some warnings when compiling with GCC:

/home/krf/devel/src/kdevplatform/language/codegen/basicrefactoring.cpp:212:17: 
warning: missing initializer for member 
‘KDevelop::BasicRefactoring::NameAndCollector::newName’ [-Wmissing-field-
initializers]
         return {};
                 ^

IMO, the code is fine, and GCC is being overly picky about this. IMO, using {} 
clearly states that I want all members to be default initialized and want to 
be done with it. Notably, Clang doesn't throw such a warning.

Example test.cpp:
struct S { int i; int j; };
int main()
{
    S a{}; (void)a;
    S b{0,}; (void)b;
}

% g++ -std=c++11 -Wextra test.cpp      
test.cpp: In function ‘int main()’:
test.cpp:4:9: warning: missing initializer for member ‘S::i’ [-Wmissing-field-
initializers]
     S a{}; (void)a;
         ^
test.cpp:4:9: warning: missing initializer for member ‘S::j’ [-Wmissing-field-
initializers]
test.cpp:5:11: warning: missing initializer for member ‘S::j’ [-Wmissing-
field-initializers]
     S b{0,}; (void)b;
           ^

=> GCC being very noisy.

% clang++ -std=c++11 -Wextra test.cpp
test.cpp:5:11: warning: missing field 'j' initializer [-Wmissing-field-
initializers]
    S b{0,}; (void)b;
          ^

=> Clang being more reasonable here, only throws a warning for the second 
case.

Doesn't look like GCC is going to change that behavior [1] soonish, so I'd 
propose getting rid off the warning for GCC, given that we are going to use 
brace-initialization more and more.

Opinions?

-- 
Kevin Funk


More information about the KDevelop-devel mailing list