diff mbox

[C++] PR 31671

Message ID 52569E93.7040803@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 10, 2013, 12:33 p.m. UTC
Hi,

I think that in order to resolve this very old accepts-invalid, we can 
simply adjust the expr to the cv-qualifiers of probe_type. I also double 
checked that thing are fine for other combinations of cv-qualified 
reference types as parameter and as argument.

Tested x86_64-linux.

Thanks,
Paolo.

////////////////////
/cp
2013-10-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/31671
	* pt.c (convert_nontype_argument): Adjust TREE_TYPE (expr) to
	the cv-qualifiers of TREE_TYPE (probe_type).

/testsuite
2013-10-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/31671
	* g++.dg/template/nontype26.C: New.

Comments

Jason Merrill Oct. 10, 2013, 6:26 p.m. UTC | #1
On 10/10/2013 08:33 AM, Paolo Carlini wrote:
> +	      expr_type = TREE_TYPE (expr) = cp_build_qualified_type
> +		(TREE_TYPE (expr), cp_type_quals (TREE_TYPE (probe_type)));

Won't that end up being the same as the contents of expr_type before 
this statement?  Can we just remove this assignment?

Also, clobbering TREE_TYPE (expr) strikes me as a bad idea.

Jason
diff mbox

Patch

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 203341)
+++ cp/pt.c	(working copy)
@@ -5611,7 +5611,8 @@  convert_nontype_argument (tree type, tree expr, ts
 		   TREE_TYPE (TREE_TYPE (addr)))))
 	    {
 	      expr = TREE_OPERAND (addr, 0);
-	      expr_type = TREE_TYPE (expr);
+	      expr_type = TREE_TYPE (expr) = cp_build_qualified_type
+		(TREE_TYPE (expr), cp_type_quals (TREE_TYPE (probe_type)));
 	    }
 	}
     }
Index: testsuite/g++.dg/template/nontype26.C
===================================================================
--- testsuite/g++.dg/template/nontype26.C	(revision 0)
+++ testsuite/g++.dg/template/nontype26.C	(working copy)
@@ -0,0 +1,20 @@ 
+// PR c++/31671
+
+template<int& i> void doit() {
+  i = 0;
+}
+
+template<const int& i> class X {
+public:
+    void foo() {
+      doit<i>();  // { dg-error "cv-qualification|no matching" }
+    }
+};
+
+int i = 0;
+
+X<i> x;
+
+int main() {
+  x.foo();
+}