diff mbox

C++ PATCH for c++/50024 (ICE with new int{})

Message ID 4E53C82B.8010008@redhat.com
State New
Headers show

Commit Message

Jason Merrill Aug. 23, 2011, 3:32 p.m. UTC
maybe_constant_value was failing to recognize that we can't ask for the 
constant value of an initializer list because it has no type.  After 
fixing that, we still incorrectly rejected the testcase, so I had to fix 
a couple of other spots as well.

Tested x86_64-pc-linux-gnu, applying to trunk and perhaps 4.6.
diff mbox

Patch

commit 1738cacbeb65b9fb0e155fa7a1369e647674082c
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Aug 19 00:52:38 2011 -0400

    	PR c++/50024
    	* semantics.c (maybe_constant_value): Don't try to fold { }.
    	* pt.c (build_non_dependent_expr): Don't wrap { }.
    	* init.c (build_value_init): Allow scalar value-init in templates.

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 4fa627b..847f519 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -330,7 +330,7 @@  build_value_init (tree type, tsubst_flags_t complain)
      constructor.  */
 
   /* The AGGR_INIT_EXPR tweaking below breaks in templates.  */
-  gcc_assert (!processing_template_decl);
+  gcc_assert (!processing_template_decl || SCALAR_TYPE_P (type));
 
   if (CLASS_TYPE_P (type))
     {
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ed4fe72..3f9a4c0 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19669,6 +19669,10 @@  build_non_dependent_expr (tree expr)
   if (TREE_CODE (expr) == THROW_EXPR)
     return expr;
 
+  /* Don't wrap an initializer list, we need to be able to look inside.  */
+  if (BRACE_ENCLOSED_INITIALIZER_P (expr))
+    return expr;
+
   if (TREE_CODE (expr) == COND_EXPR)
     return build3 (COND_EXPR,
 		   TREE_TYPE (expr),
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 1f6b49a..2f62e35 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7542,6 +7542,7 @@  maybe_constant_value (tree t)
 
   if (type_dependent_expression_p (t)
       || type_unknown_p (t)
+      || BRACE_ENCLOSED_INITIALIZER_P (t)
       || !potential_constant_expression (t)
       || value_dependent_expression_p (t))
     {
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C
new file mode 100644
index 0000000..97f0399
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C
@@ -0,0 +1,15 @@ 
+// PR c++/50024
+// { dg-options -std=c++0x }
+
+template< class T >
+struct Container
+{
+  Container(){
+    int* ptr = new int{};
+  }
+};
+
+int main() {
+    Container< int > c;
+}
+