Patchwork [C++,Patch/RFC] PR 57092

login
register
mail settings
Submitter Paolo Carlini
Date April 30, 2013, 8:49 p.m.
Message ID <51802E57.9010407@oracle.com>
Download mbox | patch
Permalink /patch/240688/
State New
Headers show

Comments

Paolo Carlini - April 30, 2013, 8:49 p.m.
Hi,

On 04/30/2013 08:57 PM, Jason Merrill wrote:
> On 04/30/2013 11:59 AM, Paolo Carlini wrote:
>> Currently, in some cases (see, eg, template/canon-type-9.C) we have that
>> id is true and DECLTYPE_TYPE_EXPR (t) is a TEMPLATE_PARM_INDEX but the
>> tsubst_copy_and_build call returns a TEMPLATE_PARM_INDEX again, not an
>> ADDR_EXPR, not an expression
>
> Good point, this can happen for partial instantiations, when 
> processing_template_decl is still true.  We want to keep the 
> DECLTYPE_TYPE around until the expression instantiates to something 
> non-instantiation-dependent.
I see...
> Hmm.  Maybe the right answer is to just add a default: case to 
> finish_decltype_type and trust that it will be right.
Ok. Then shall we do something like the below?

Thanks,
Paolo.

//////////////////
Jason Merrill - May 1, 2013, 1:26 a.m.
On 04/30/2013 04:49 PM, Paolo Carlini wrote:
> Ok. Then shall we do something like the below?

Yeah, just add a comment explaining that it's there to handle 
instantiated template non-type arguments.

Jason

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 198469)
+++ cp/semantics.c	(working copy)
@@ -5416,8 +5416,8 @@  finish_decltype_type (tree expr, bool id_expressio
           break;
 
         default:
-	  gcc_unreachable ();
-          return error_mark_node;
+          type = TREE_TYPE (expr);
+          break;
         }
     }
   else
Index: testsuite/g++.dg/cpp0x/decltype53.C
===================================================================
--- testsuite/g++.dg/cpp0x/decltype53.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/decltype53.C	(working copy)
@@ -0,0 +1,11 @@ 
+// PR c++/57092
+// { dg-do compile { target c++11 } }
+
+template <void (*F)(int)>
+class B {
+  decltype(F) v;
+};
+
+void foo(int) {}
+
+B<foo> o;