Pretty trivial patch -- these two informs weren't properly guarded so they'd trigger even if the warning was disabled via #pragma.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-08-11 Marek Polacek <pola...@redhat.com> PR c/81795 * c-decl.c (pushtag): Only print inform if the warning was printed. (grokdeclarator): Likewise. * gcc.dg/pr81795.c: New test. diff --git gcc/c/c-decl.c gcc/c/c-decl.c index d21fbc5883e..323d4480609 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -1557,11 +1557,10 @@ pushtag (location_t loc, tree name, tree type) && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl)) != TYPE_MAIN_VARIANT (type))) { - warning_at (loc, OPT_Wc___compat, - ("using %qD as both a typedef and a tag is " - "invalid in C++"), - b->decl); - if (b->locus != UNKNOWN_LOCATION) + if (warning_at (loc, OPT_Wc___compat, + ("using %qD as both a typedef and a tag is " + "invalid in C++"), b->decl) + && b->locus != UNKNOWN_LOCATION) inform (b->locus, "originally defined here"); } } @@ -6596,11 +6595,10 @@ grokdeclarator (const struct c_declarator *declarator, || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type)) { - warning_at (declarator->id_loc, OPT_Wc___compat, - ("using %qD as both a typedef and a tag is " - "invalid in C++"), - decl); - if (b->locus != UNKNOWN_LOCATION) + if (warning_at (declarator->id_loc, OPT_Wc___compat, + ("using %qD as both a typedef and a tag is " + "invalid in C++"), decl) + && b->locus != UNKNOWN_LOCATION) inform (b->locus, "originally defined here"); } } diff --git gcc/testsuite/gcc.dg/pr81795.c gcc/testsuite/gcc.dg/pr81795.c index e69de29bb2d..b035bd0b530 100644 --- gcc/testsuite/gcc.dg/pr81795.c +++ gcc/testsuite/gcc.dg/pr81795.c @@ -0,0 +1,14 @@ +/* PR c/81795 */ +/* { dg-do compile } */ +/* { dg-options "-Wc++-compat" } */ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wc++-compat" + +struct S { int f; }; /* { dg-bogus "note: originally defined here" } */ +typedef int S; /* { dg-bogus "invalid in C\[+\]\[+\]" } */ + +typedef int T; /* { dg-bogus "note: originally defined here" } */ +struct T { int f; }; /* { dg-bogus "invalid in C\[+\]\[+\]" } */ + +#pragma GCC diagnostic pop Marek