Patchwork [C++] PR 58647

login
register
mail settings
Submitter Paolo Carlini
Date Nov. 26, 2013, 10:40 a.m.
Message ID <52947AB3.5000300@oracle.com>
Download mbox | patch
Permalink /patch/294292/
State New
Headers show

Comments

Paolo Carlini - Nov. 26, 2013, 10:40 a.m.
Hi,

On 11/23/2013 11:35 PM, Jason Merrill wrote:
> On 10/20/2013 12:07 PM, Paolo Carlini wrote:
>>      case COMPONENT_REF:
>> +      if (is_overloaded_fn (TREE_OPERAND (t, 1)))
>> +    return t;
>
> Hmm, I'd be inclined to strip the COMPONENT_REF in this case to 
> produce something that's actually usable as a constant.  Does that work?
I see. Thus I tested successfully the below (which, for the testcase, 
forwards a BASELINK) or you mean something more complex?

Thanks,
Paolo.

//////////////////
Jason Merrill - Nov. 26, 2013, 3:30 p.m.
On 11/26/2013 05:40 AM, Paolo Carlini wrote:
> Hi,
>
> On 11/23/2013 11:35 PM, Jason Merrill wrote:
>> On 10/20/2013 12:07 PM, Paolo Carlini wrote:
>>>      case COMPONENT_REF:
>>> +      if (is_overloaded_fn (TREE_OPERAND (t, 1)))
>>> +    return t;
>>
>> Hmm, I'd be inclined to strip the COMPONENT_REF in this case to
>> produce something that's actually usable as a constant.  Does that work?
> I see. Thus I tested successfully the below (which, for the testcase,
> forwards a BASELINK) or you mean something more complex?

A BASELINK isn't useful as a constant, either; I was thinking of the 
FUNCTION_DECL itself.  Perhaps

gcc_checking_assert (!really_overloaded_fn
return get_first_fn

Jason
Paolo Carlini - Nov. 26, 2013, 4:43 p.m.
Hi,

On 11/26/2013 04:30 PM, Jason Merrill wrote:
> A BASELINK isn't useful as a constant, either; I was thinking of the 
> FUNCTION_DECL itself.  Perhaps
>
> gcc_checking_assert (!really_overloaded_fn
> return get_first_fn
We have got a bunch of testcases, for example constexpr-ex4.C - attached 
for your convenience - which trigger the assert !really_overloaded_fn 
(t) ... What do you suggest?

Thanks,
Paolo.

///////
Jason Merrill - Nov. 26, 2013, 7:10 p.m.
On 11/26/2013 11:43 AM, Paolo Carlini wrote:
> We have got a bunch of testcases, for example constexpr-ex4.C - attached
> for your convenience - which trigger the assert !really_overloaded_fn
> (t) ... What do you suggest?

Aha.  Well, in that case we really can't get a constant value, so I'd 
assert allow_non_constant, set *non_constant_p, and return t.

Actually, I'd do that any time we get a function COMPONENT_REF, since 
that will only ever happen under the checking maybe_constant_value call 
anyway.  So a small expansion of your original patch.

Jason

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 205382)
+++ cp/semantics.c	(working copy)
@@ -9601,8 +9601,13 @@  cxx_eval_constant_expression (const constexpr_call
       break;
 
     case COMPONENT_REF:
-      r = cxx_eval_component_reference (call, t, allow_non_constant, addr,
-					non_constant_p, overflow_p);
+      if (is_overloaded_fn (TREE_OPERAND (t, 1)))
+	r = cxx_eval_constant_expression (call, TREE_OPERAND (t, 1),
+					  allow_non_constant, addr,
+					  non_constant_p, overflow_p);
+      else
+	r = cxx_eval_component_reference (call, t, allow_non_constant, addr,
+					  non_constant_p, overflow_p);
       break;
 
     case BIT_FIELD_REF:
Index: testsuite/g++.dg/parse/crash66.C
===================================================================
--- testsuite/g++.dg/parse/crash66.C	(revision 0)
+++ testsuite/g++.dg/parse/crash66.C	(working copy)
@@ -0,0 +1,11 @@ 
+// PR c++/58647
+
+struct A
+{
+  static void foo();
+};
+
+template<typename> void bar()
+{
+  A().foo;
+}