Patchwork [C++] PR 58647

login
register
mail settings
Submitter Paolo Carlini
Date Nov. 27, 2013, 10:22 a.m.
Message ID <5295C801.703@oracle.com>
Download mbox | patch
Permalink /patch/294551/
State New
Headers show

Comments

Paolo Carlini - Nov. 27, 2013, 10:22 a.m.
Hi,

On 11/26/2013 08:10 PM, Jason Merrill wrote:
> 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.
Thus something like the below? Passes testing.

Thanks,
Paolo.

////////////////////////////
Jason Merrill - Nov. 27, 2013, 3:35 p.m.
On 11/27/2013 05:22 AM, Paolo Carlini wrote:
> Thus something like the below? Passes testing.

Yep.  With a comment that we can only get there in checking mode via 
build_non_dependent_expr, because any expression that calls or takes the 
address of the function will have pull a FUNCTION_DECL out of the 
COMPONENT_REF.

Jason

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 205433)
+++ cp/semantics.c	(working copy)
@@ -9601,6 +9601,12 @@  cxx_eval_constant_expression (const constexpr_call
       break;
 
     case COMPONENT_REF:
+      if (is_overloaded_fn (t))
+	{
+	  gcc_checking_assert (allow_non_constant);
+	  *non_constant_p = true;
+	  return t;
+	}
       r = cxx_eval_component_reference (call, t, allow_non_constant, addr,
 					non_constant_p, overflow_p);
       break;
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;
+}