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.
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);
}
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)
--- /dev/null
+// 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&;