This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR c++/70106 (type of parenthesized qualified-id has wrong cv-qualifiers)


Here's another force_paren_expr issue.  Hopefully I described the issue
adequately in the inline comments that are part of the patch.  The
relevant function that builds the temporary SCOPE_REF is
finish_non_static_data_member.

Does this patch look OK to commit after bootstrap + regtest?

gcc/cp/ChangeLog:

	PR c++70106
	* semantics.c (force_paren_expr): Just build a PAREN_EXPR when
	processing_template_decl and EXPR is a SCOPE_REF.

gcc/testsuite/ChangeLog:

	PR c++70106
	* g++.dg/cpp1y/paren3.C: New test.
---
 gcc/cp/semantics.c                  | 10 +++++++++-
 gcc/testsuite/g++.dg/cpp1y/paren3.C | 30 ++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/paren3.C

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index a9dbf16..874dbe2 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -1649,7 +1649,15 @@ force_paren_expr (tree expr)
 
   if (TREE_CODE (expr) == COMPONENT_REF)
     REF_PARENTHESIZED_P (expr) = true;
-  else if (type_dependent_expression_p (expr))
+  else if (type_dependent_expression_p (expr)
+	   /* When processing_template_decl, a SCOPE_REF may actually be
+	      referring to a non-static data member of the current class, in
+	      which case its TREE_TYPE may not be properly cv-qualified (the
+	      cv-qualifiers of the implicit *this object haven't yet been taken
+	      into account) so we have to delay building a static_cast until
+	      instantiation.  */
+	   || (processing_template_decl
+	       && TREE_CODE (expr) == SCOPE_REF))
     expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr);
   else if (VAR_P (expr) && DECL_HARD_REGISTER (expr))
     /* We can't bind a hard register variable to a reference.  */;
diff --git a/gcc/testsuite/g++.dg/cpp1y/paren3.C b/gcc/testsuite/g++.dg/cpp1y/paren3.C
new file mode 100644
index 0000000..48359b0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/paren3.C
@@ -0,0 +1,30 @@
+// PR c++/70106
+// { dg-do compile { target c++14 } }
+
+template <typename>
+struct A
+{
+  int x;
+
+  void foo () const {
+    (A::x);
+  };
+};
+
+struct B
+{
+  int x;
+
+  template <typename>
+  void foo () const {
+    (B::x);
+  };
+};
+
+void
+foo ()
+{
+  A<int> ().foo ();
+  B ().foo<int> ();
+}
+
-- 
2.8.0.rc1.12.gfce6d53


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]