From bb85aa74f07e2cebb7f888a1817eba6f2f4308a6 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 11 Aug 2017 18:02:18 +0000 Subject: [PATCH] re PR c/81795 (Stray "originally defined here" when using -Wc++-compat with #pragma GCC diagnostic push/pop) PR c/81795 * c-decl.c (pushtag): Only print inform if the warning was printed. (grokdeclarator): Likewise. * gcc.dg/pr81795.c: New test. From-SVN: r251056 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-decl.c | 18 ++++++++---------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr81795.c | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr81795.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 6e29334..cd0c128 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2017-08-11 Marek Polacek + + PR c/81795 + * c-decl.c (pushtag): Only print inform if the warning was printed. + (grokdeclarator): Likewise. + 2017-08-10 David Malcolm * c-parser.c (c_parser_error): Rename to... diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index d21fbc5..323d448 100644 --- a/gcc/c/c-decl.c +++ b/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 a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 71b7c62..056953e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-11 Marek Polacek + + PR c/81795 + * gcc.dg/pr81795.c: New test. + 2017-08-11 Thomas Koenig PR fortran/60355 diff --git a/gcc/testsuite/gcc.dg/pr81795.c b/gcc/testsuite/gcc.dg/pr81795.c new file mode 100644 index 0000000..b035bd0 --- /dev/null +++ b/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 -- 2.7.4