Since the -Wparentheses extension regarding Most Vexing Parse we started
warning on e.g. "reinterpret_cast<int(*)>(&a)".  I don't think the warning was
meant to warn in this situation, since in reinterpret_cast there's no decl/expr
disambiguation, is it?

It seems we should simply disable the warning in TYPENAME context.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-01-03  Marek Polacek  <pola...@redhat.com>

        PR c++/83592
        * decl.c (grokdeclarator): Don't warn about MVP in typename context.

        * g++.dg/warn/mvp2.C: New test.

diff --git gcc/cp/decl.c gcc/cp/decl.c
index f7b03e13303..b1c50961169 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -10866,10 +10866,11 @@ grokdeclarator (const cp_declarator *declarator,
 
       inner_declarator = declarator->declarator;
 
-      /* We don't want to warn in parmeter context because we don't
+      /* We don't want to warn in parameter 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
+         && decl_context != TYPENAME
          && declarator->parenthesized != UNKNOWN_LOCATION
          /* If the type is class-like and the inner name used a
             global namespace qualifier, we need the parens.
diff --git gcc/testsuite/g++.dg/warn/mvp2.C gcc/testsuite/g++.dg/warn/mvp2.C
index e69de29bb2d..9b2793c5622 100644
--- gcc/testsuite/g++.dg/warn/mvp2.C
+++ gcc/testsuite/g++.dg/warn/mvp2.C
@@ -0,0 +1,24 @@
+// PR c++/83592
+// { dg-do compile }
+// { dg-options "-Wparentheses" }
+
+// Test that -Wparentheses does not give bogus warnings in
+// typename context.
+
+int *
+foo (long &a)
+{
+  return reinterpret_cast<int (*)> (&a);
+}
+
+int *
+bar (long &a)
+{
+  return (int (*)) &a;
+}
+
+int *
+baz (int &a)
+{
+  return static_cast<int (*const)> (&a);
+}

        Marek

Reply via email to