From: Marek Polacek Date: Fri, 11 Aug 2017 18:02:18 +0000 (+0000) Subject: re PR c/81795 (Stray "originally defined here" when using -Wc++-compat with #pragma... X-Git-Tag: upstream/12.2.0~37662 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb85aa74f07e2cebb7f888a1817eba6f2f4308a6;p=platform%2Fupstream%2Fgcc.git 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 --- 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