diff mbox

[C++] PR 31671

Message ID 52570087.3010003@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 10, 2013, 7:31 p.m. UTC
Hi,

On 10/10/2013 08:26 PM, Jason Merrill wrote:
> 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.
Sorry. Having figured out where the problem was, I messed up very badly 
when I prepared the actual patch for submission. The below makes much 
more sense to me.

Thanks,
Paolo.

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

	PR c++/31671
	* pt.c (convert_nontype_argument): Set expr_type to
	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. 11, 2013, 3:55 a.m. UTC | #1
On 10/10/2013 03:31 PM, Paolo Carlini wrote:
> On 10/10/2013 08:26 PM, Jason Merrill wrote:
>> 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?

> Sorry. Having figured out where the problem was, I messed up very badly
> when I prepared the actual patch for submission. The below makes much
> more sense to me.

> +	      expr_type = TREE_TYPE (probe_type);

Again, won't that set expr_type to the value it already had?  I'd prefer 
to just have a comment that we're leaving it alone.

Jason
Paolo Carlini Oct. 11, 2013, 8:51 a.m. UTC | #2
Hi,

On 10/11/2013 05:55 AM, Jason Merrill wrote:
> On 10/10/2013 03:31 PM, Paolo Carlini wrote:
>> On 10/10/2013 08:26 PM, Jason Merrill wrote:
>>> 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?
>
>> Sorry. Having figured out where the problem was, I messed up very badly
>> when I prepared the actual patch for submission. The below makes much
>> more sense to me.
>
>> +          expr_type = TREE_TYPE (probe_type);
>
> Again, won't that set expr_type to the value it already had?  I'd 
> prefer to just have a comment that we're leaving it alone.
Sorry forgot about that. No, that line isn't redundant.

The 6th time we get there when compiling the testcase, that is when we 
are converting to int&, at that line this is expr_type:

  <reference_type 0x7ffff68587e0
     type <integer_type 0x7ffff6858738 int readonly type_6 SI
    ...

whereas this is TREE_TYPE (probe_type):

  <integer_type 0x7ffff6858738 int readonly type_6 SI
     size <integer_cst 0x7ffff6700440 type <integer_type 0x7ffff670a0a8 
bitsizetype> constant 32>
    ...

Thus, if you think it makes the logic easier to follow we could likely 
do (only lightly tested):

     expr_type = TREE_TYPE (expr_type);

but we can't possibly leave expr_type alone.

Thanks,
Paolo.
Jason Merrill Oct. 11, 2013, 1:57 p.m. UTC | #3
On 10/11/2013 04:51 AM, Paolo Carlini wrote:
> The 6th time we get there when compiling the testcase, that is when we
> are converting to int&, at that line this is expr_type:
>
>   <reference_type 0x7ffff68587e0
>      type <integer_type 0x7ffff6858738 int readonly type_6 SI

Aha.  The patch is OK then.

Jason
diff mbox

Patch

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 203392)
+++ cp/pt.c	(working copy)
@@ -5611,7 +5611,7 @@  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 (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();
+}