summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2017-11-02 18:26:29 +0000
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2017-11-02 18:26:29 +0000
commitbbbf4a06b0da2b48324b099b8568a4de6d0baf7a (patch)
treebd548651e16769c30fa4864f708eda2a2847a8fd
parentbb0142e0a086dae6e4602f55502620fe25957700 (diff)
downloadgcc-bbbf4a06b0da2b48324b099b8568a4de6d0baf7a.tar.gz
[PR c++/82710] false positive paren warning
https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00119.html PR c++/82710 * decl.c (grokdeclarator): Don't warn when parens protect a return type from a qualified name. PR c++/82710 * g++.dg/warn/pr82710.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254349 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/decl.c13
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/warn/pr82710.C32
4 files changed, 51 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d3ffadfb1fb..7a7a58941e6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2017-11-02 Nathan Sidwell <nathan@acm.org>
+
+ PR c++/82710
+ * decl.c (grokdeclarator): Don't warn when parens protect a return
+ type from a qualified name.
+
2017-11-01 Nathan Sidwell <nathan@acm.org>
* cp-tree.h (enum cp_identifier_kind): Delete cik_newdel_op.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d88c78f348b..62bd3daef74 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10788,18 +10788,25 @@ grokdeclarator (const cp_declarator *declarator,
attr_flags);
}
+ inner_declarator = declarator->declarator;
+
/* We don't want to warn in parmeter context because we don't
yet know if the parse will succeed, and this might turn out
to be a constructor call. */
if (decl_context != PARM
- && declarator->parenthesized != UNKNOWN_LOCATION)
+ && 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
+ && inner_declarator->kind == cdk_id
+ && inner_declarator->u.id.qualifying_scope))
warning_at (declarator->parenthesized, OPT_Wparentheses,
"unnecessary parentheses in declaration of %qs", name);
if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
break;
- inner_declarator = declarator->declarator;
-
switch (declarator->kind)
{
case cdk_array:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 641a9cca5be..bc4a20752c2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2017-11-02 Nathan Sidwell <nathan@acm.org>
+ PR c++/82710
+ * g++.dg/warn/pr82710.C: New.
+
* g++.dg/lang-dump.C: New.
2017-11-02 Richard Biener <rguenther@suse.de>
diff --git a/gcc/testsuite/g++.dg/warn/pr82710.C b/gcc/testsuite/g++.dg/warn/pr82710.C
new file mode 100644
index 00000000000..a1f9247129e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/pr82710.C
@@ -0,0 +1,32 @@
+// { dg-additional-options -Wparentheses }
+
+// the MVP warning triggered on a friend decl. */
+class X;
+
+namespace here
+{
+ // these friends
+ X friendFunc1();
+ X *friendFunc2 ();
+ int friendFunc3 ();
+}
+
+namespace nm
+{
+ namespace here
+ {
+ // Not these friends
+ void friendFunc1 ();
+ void friendFunc2 ();
+ void friendFunc3 ();
+ }
+
+ class TestClass
+ {
+ friend X (::here::friendFunc1 ()); // parens are needed
+ friend X *(::here::friendFunc2 ()); // { dg-warning "" }
+ friend X *::here::friendFunc2 ();
+ friend int (::here::friendFunc3 ()); // { dg-warning "" }
+ };
+}
+