http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60742
Bug ID: 60742 Summary: ill-formed declarator (array) in selection statement not caught appropriately Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: filip.roseen at gmail dot com Created attachment 32527 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32527&action=edit testcase.cpp int main () { if (int a[3] = {1,2,3}) { (void)a; } } ------------------------------------------------------------- [stmt.select]p2: > The rules for conditions apply both to selction-statements and to > the for and while statements (6.5) __The declarator shall not > specify a function or an array.__ If the auto type-specifier appears > in the decl-specifier-seq, the type of the identifier being > declared is deduced from the initializer as described in 7.1.6.4. ------------------------------------------------------------- H20:/tmp% g++ -std=c++11 -pedantic-errors testcase.cpp; H20:/tmp% g++ -std=c++11 -pedantic-errors -Waddress testcase.cpp; testcase.cpp: In function ‘int main()’: testcase.cpp:2:25: warning: the address of ‘a’ will always evaluate as ‘true’ [-Waddress] if (int a[3] = {1,2,3}) { ------------------------------------------------------------- As seen above a diagnostic is only issued if we do `-Waddress` (or some warning flag that includes the mentioned one). The problem isn't actually with the address of `a` always evaluting to `true`, the major problem is that this kind of code is ill-formed; gcc should therefore reject it. [ Note: `clang` and `icc` both handles this correctly (ie. rejects it) ]