re PR c++/47453 ([DR 1214] Various non-conforming behaviors with braced-init-list...
authorJason Merrill <jason@redhat.com>
Fri, 5 Aug 2011 19:15:25 +0000 (15:15 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 5 Aug 2011 19:15:25 +0000 (15:15 -0400)
PR c++/47453
* typeck.c (build_x_compound_expr_from_list): Also complain
about ({...}).

From-SVN: r177480

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist13.C
gcc/testsuite/g++.dg/cpp0x/initlist50.C
gcc/testsuite/g++.dg/cpp0x/initlist56.C [new file with mode: 0644]

index 46eee7e8dbd8382fbcd11f253326260a09e40d85..ea66fa1dbcee07a9868accf2c8d9cae5e37499cb 100644 (file)
@@ -1,5 +1,9 @@
 2011-08-05  Jason Merrill  <jason@redhat.com>
 
+       PR c++/47453
+       * typeck.c (build_x_compound_expr_from_list): Also complain
+       about ({...}).
+
        PR c++/49812
        * typeck.c (cp_build_unary_op) [POSTINCREMENT_EXPR]: Strip cv-quals.
 
index f53deb985a62386b40087f1f762fa190dfdc29fd..a1f67613adcaaeba8bc77fa972c8e1118c08731d 100644 (file)
@@ -5470,6 +5470,16 @@ build_x_compound_expr_from_list (tree list, expr_list_kind exp,
 {
   tree expr = TREE_VALUE (list);
 
+  if (BRACE_ENCLOSED_INITIALIZER_P (expr)
+      && !CONSTRUCTOR_IS_DIRECT_INIT (expr))
+    {
+      if (complain & tf_error)
+       pedwarn (EXPR_LOC_OR_HERE (expr), 0, "list-initializer for "
+                "non-class type must not be parenthesized");
+      else
+       return error_mark_node;
+    }
+
   if (TREE_CHAIN (list))
     {
       if (complain & tf_error)
index 6ba618327bedcdc420e93dbc55857e7e208ab42f..dfa765f7050c172319d81af75cbb555cd1c39e85 100644 (file)
@@ -1,5 +1,8 @@
 2011-08-05  Jason Merrill  <jason@redhat.com>
 
+       PR c++/47453
+       * g++.dg/cpp0x/initlist56.C: New.
+
        PR c++/49812
        * g++.dg/overload/rvalue2.C: New.
 
index 9ed6c74419ff8744009cc1ecd21e6df87e97c2d9..bc5ee2c3aecfd0fee3a5521bb5e9f0dc4fe15acb 100644 (file)
@@ -4,5 +4,5 @@
 
 #include <complex>
 
-__complex__ int i ({0});
-std::complex<int> i2 ({0});
+__complex__ int i {0};
+std::complex<int> i2 {0};
index ef4e72c7cfa62073cb2e5cff40e8420df298d5aa..5cb23e2db3e3038d8f898287c75b76d05900fb3a 100644 (file)
@@ -8,7 +8,7 @@ struct A2 {
 
 template <class T> struct B {
   T ar[1];
-  B(T t):ar({t}) {}
+  B(T t):ar{t} {}
 };
 
 int main(){
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist56.C b/gcc/testsuite/g++.dg/cpp0x/initlist56.C
new file mode 100644 (file)
index 0000000..862b41b
--- /dev/null
@@ -0,0 +1,37 @@
+// PR c++/47453
+// { dg-options "-std=c++0x -pedantic-errors" }
+
+// invalid
+int a({0});                    // { dg-error "" }
+
+// invalid
+int const &b({0});             // { dg-error "" }
+
+// invalid
+struct A1 { int a[2]; A1(); };
+A1::A1():a({1, 2}) { }         // { dg-error "" }
+
+struct A { explicit A(int, int); A(int, long); };
+
+// invalid
+A c({1, 2});                   // { dg-error "" }
+
+// valid (by copy constructor).
+A d({1, 2L});
+
+// valid
+A e{1, 2};
+
+#include <initializer_list>
+
+struct B {
+  template<typename ...T>
+  B(std::initializer_list<int>, T ...);
+};
+
+// invalid (the first phase only considers init-list ctors)
+// (for the second phase, no constructor is viable)
+B f{1, 2, 3};                  // { dg-error "" }
+
+// valid (T deduced to <>).
+B g({1, 2, 3});