re PR c++/50024 ([C++0x] [4.7 Regression] crash when using braced initialization...
authorJason Merrill <jason@redhat.com>
Tue, 23 Aug 2011 16:03:01 +0000 (12:03 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 23 Aug 2011 16:03:01 +0000 (12:03 -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.

From-SVN: r177994

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C [new file with mode: 0644]

index 524a685da24bc25ffb810f879c042cf8a5d9f77d..0f60bcb313a0e74eda4adfe06322a9b7e7d3cd5f 100644 (file)
@@ -1,3 +1,10 @@
+2011-08-23  Jason Merrill  <jason@redhat.com>
+
+       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.
+
 2011-08-23  Jason Merrill  <jason@redhat.com>
 
        * semantics.c (potential_constant_expression_1): Allow 'this'.
index 4fa627ba8c01c8b98ab9c31ce428e58472558494..847f5199f1b4a2ea60b9fc91f742c2b97532b063 100644 (file)
@@ -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))
     {
index ed4fe726c205aa22673407a9b8c379fc8ee511c6..3f9a4c042243acfa8b6536100332fc08d34dfa82 100644 (file)
@@ -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),
index 1f6b49a847224e0556a0b333acfd0cb7ffd858be..2f62e351139dba3b4666848969acabb4cb69202f 100644 (file)
@@ -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))
     {
index e3c521cd143afaee6e5da0cb16dc126c9778d2a6..fe3688826e134e9515533a9e8c5892b3249ede8c 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-23  Jason Merrill  <jason@redhat.com>
+
+       PR c++/50024
+       * g++.dg/cpp0x/constexpr-initlist5.C: New.
+
 2011-08-23  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/50158
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C
new file mode 100644 (file)
index 0000000..97f0399
--- /dev/null
@@ -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;
+}
+