]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: parenthesized -> resolving to static data member [PR98283]
authorPatrick Palka <ppalka@redhat.com>
Sun, 7 May 2023 15:57:22 +0000 (11:57 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sun, 7 May 2023 15:57:22 +0000 (11:57 -0400)
Here we're neglecting to propagate parenthesized-ness when the
member access (this->m) resolves to a static data member (and
thus finish_class_member_access_expr yields a VAR_DECL instead
of a COMPONENT_REF).

PR c++/98283

gcc/cp/ChangeLog:

* pt.cc (tsubst_copy_and_build) <case COMPONENT_REF>: Propagate
REF_PARENTHESIZED_P more generally via force_paren_expr.
* semantics.cc (force_paren_expr): Document default argument.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/paren6.C: New test.

gcc/cp/pt.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp1y/paren6.C [new file with mode: 0644]

index ee4a2f31343015f61a40221cb6da2fe16d5fb4ef..de95e128c7295542703a0ace68ab9c3241b6a367 100644 (file)
@@ -21520,8 +21520,8 @@ tsubst_copy_and_build (tree t,
        r = finish_class_member_access_expr (object, member,
                                             /*template_p=*/false,
                                             complain);
-       if (TREE_CODE (r) == COMPONENT_REF)
-         REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t);
+       if (REF_PARENTHESIZED_P (t))
+         r = force_paren_expr (r);
        RETURN (r);
       }
 
index 474da71bff62adc7b2629090d4f5b1d1844f3f52..13c6582b62899204e6715a866b12d35eda19d875 100644 (file)
@@ -2070,7 +2070,7 @@ finish_mem_initializers (tree mem_inits)
    right result.  If EVEN_UNEVAL, do this even in unevaluated context.  */
 
 tree
-force_paren_expr (tree expr, bool even_uneval)
+force_paren_expr (tree expr, bool even_uneval /* = false */)
 {
   /* This is only needed for decltype(auto) in C++14.  */
   if (cxx_dialect < cxx14)
diff --git a/gcc/testsuite/g++.dg/cpp1y/paren6.C b/gcc/testsuite/g++.dg/cpp1y/paren6.C
new file mode 100644 (file)
index 0000000..812a99c
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/98283
+// { dg-do compile { target c++14 } }
+
+struct A {
+  static int m;
+};
+
+template<class T>
+struct B : T {
+  decltype(auto) f() { return (this->m);  }
+};
+
+using type = decltype(B<A>().f());
+using type = int&;