From a93ee058fa3f2b0569e43b425293f28858eebfaf Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 3 Nov 2017 13:16:06 +0000 Subject: [PATCH] [PR c++/82710] false positive paren warning https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00186.html PR c++/82710 * decl.c (grokdeclarator): Protect MAYBE_CLASS things from paren warning too. PR c++/82710 * g++.dg/warn/pr82710.C: More cases. From-SVN: r254371 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 14 ++++++++------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/pr82710.C | 18 +++++++++++++++++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e7ea5da008a..590e3221c8c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-11-03 Nathan Sidwell + + PR c++/82710 + * decl.c (grokdeclarator): Protect MAYBE_CLASS things from paren + warning too. + 2017-11-02 Paolo Carlini PR c++/81957 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 7c6f85724df..0ce8f2d3435 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10795,13 +10795,15 @@ grokdeclarator (const cp_declarator *declarator, to be a constructor call. */ if (decl_context != PARM && declarator->parenthesized != UNKNOWN_LOCATION - /* If the type is a class and the inner name used a global - namespace qualifier, we need the parens. Unfortunately - all we can tell is that a qualified name was used. */ - && !(CLASS_TYPE_P (type) - && inner_declarator + /* If the type is class-like and the inner name used a + global namespace qualifier, we need the parens. + Unfortunately all we can tell is whether a qualified name + was used or not. */ + && !(inner_declarator && inner_declarator->kind == cdk_id - && inner_declarator->u.id.qualifying_scope)) + && inner_declarator->u.id.qualifying_scope + && (MAYBE_CLASS_TYPE_P (type) + || TREE_CODE (type) == ENUMERAL_TYPE))) warning_at (declarator->parenthesized, OPT_Wparentheses, "unnecessary parentheses in declaration of %qs", name); if (declarator->kind == cdk_id || declarator->kind == cdk_decomp) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8159009a85a..e40224e5564 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-03 Nathan Sidwell + + PR c++/82710 + * g++.dg/warn/pr82710.C: More cases. + 2017-11-03 Richard Sandiford * gcc.dg/pr82809.c: New test. diff --git a/gcc/testsuite/g++.dg/warn/pr82710.C b/gcc/testsuite/g++.dg/warn/pr82710.C index a1f9247129e..93585eacf99 100644 --- a/gcc/testsuite/g++.dg/warn/pr82710.C +++ b/gcc/testsuite/g++.dg/warn/pr82710.C @@ -1,7 +1,10 @@ -// { dg-additional-options -Wparentheses } +// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wparentheses -Wno-non-template-friend" } // the MVP warning triggered on a friend decl. */ class X; +enum class Q {}; // C++ 11ness +enum R {}; namespace here { @@ -9,6 +12,9 @@ namespace here X friendFunc1(); X *friendFunc2 (); int friendFunc3 (); + int bob (); + Q bill (); + R ben (); } namespace nm @@ -19,6 +25,9 @@ namespace nm void friendFunc1 (); void friendFunc2 (); void friendFunc3 (); + int bob (); + Q bill (); + R ben (); } class TestClass @@ -28,5 +37,12 @@ namespace nm friend X *::here::friendFunc2 (); friend int (::here::friendFunc3 ()); // { dg-warning "" } }; + + template class X + { + friend typename T::frob (::here::bob ()); + friend Q (::here::bill ()); + friend R (::here::ben ()); + }; } -- 2.30.2