]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PR c++/70106 (type of parenthesized qualified-id has wrong cv-qualifiers)
authorppalka <ppalka@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 12 Mar 2016 02:05:17 +0000 (02:05 +0000)
committerppalka <ppalka@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 12 Mar 2016 02:05:17 +0000 (02:05 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234159 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/paren3.C [new file with mode: 0644]

index 46174cc967a4143b6665f461aa2323ecc8d19b8d..94e44275507baaf26e3f1542dcf75aafaf5b1107 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-12  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/70106
+       * semantics.c (force_paren_expr): Just build a PAREN_EXPR when
+       processing_template_decl and EXPR is a SCOPE_REF.
+
 2016-03-10  Patrick Palka  <ppalka@gcc.gnu.org>
            Jakub Jelinek  <jakub@redhat.com>
 
index fd83c46e950cd59c079f6f57776966ce5a666c5e..1574e60199e4747e679ffc4062a9165623bf56fd 100644 (file)
@@ -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.  */;
index a2eac07f3ec6590ae3ba5b0b951f351e2a5c11ca..515dbc75d2f72e4ce0b1fb01d7d559bf2d32942f 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-12  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/70106
+       * g++.dg/cpp1y/paren3.C: New test.
+
 2016-03-11  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        PR target/70131
diff --git a/gcc/testsuite/g++.dg/cpp1y/paren3.C b/gcc/testsuite/g++.dg/cpp1y/paren3.C
new file mode 100644 (file)
index 0000000..850be2c
--- /dev/null
@@ -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> ();
+}
+