diff mbox

[/,RFC] PR C++/55944

Message ID 50FEBBA6.1060801@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Jan. 22, 2013, 4:17 p.m. UTC
Hi,

today I had a look to this PR, maybe it's simple enough to be fixed at 
this time. The issue is that we ICE in check_initializer in:

            init = build_functional_cast (type, init, tf_none);
-          if (init != error_mark_node)
+          if (TREE_CODE (init) == TARGET_EXPR)
              TARGET_EXPR_DIRECT_INIT_P (init) = true;

because init is a CAST_EXPR, not a TARGET_EXPR. The reason is simple: we 
return very early from build_functional_cast, because 
processing_template_decl is true and we simply build and return a 
CAST_EXPR. Is it then Ok to tweak the code per the above? It works for 
the testcase and passes the testsuite. The other possibility I have in 
mind is doing something entirely different in check_initializer itself 
when processing_template_decl is true?!?

Thanks!
Paolo.

/////////////////////////

Comments

Jason Merrill Jan. 22, 2013, 6:29 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 195374)
+++ cp/decl.c	(working copy)
@@ -5693,7 +5693,7 @@  check_initializer (tree decl, tree init, int flags
 		       && (!init || TREE_CODE (init) == TREE_LIST))
 		{
 		  init = build_functional_cast (type, init, tf_none);
-		  if (init != error_mark_node)
+		  if (TREE_CODE (init) == TARGET_EXPR)
 		    TARGET_EXPR_DIRECT_INIT_P (init) = true;
 		}
 	      init_code = NULL_TREE;
Index: testsuite/g++.dg/cpp0x/constexpr-static10.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-static10.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-static10.C	(working copy)
@@ -0,0 +1,19 @@ 
+// PR c++/55944
+// { dg-options -std=c++11 }
+
+template<class T>
+struct Test
+{
+  constexpr Test(T val) : value(val) {}
+  static void test()
+  {
+    static constexpr Test<int> x(42); // ICE
+  }
+  T value;
+};
+
+int main()
+{
+  static constexpr Test<int> x(42); // OK
+  Test<double>::test();
+}