diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-11-11 01:36:17 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-11-11 01:36:17 +0000 |
commit | 42b10572443e3f3f3c4a113f88ad4e9b504df900 (patch) | |
tree | b826b89beb307ed24b6ffedf840c5605ccabb3f4 /clang/test | |
parent | 754cd11d9019e62a4c6a0aee62159e707f6f51d9 (diff) | |
download | bcm5719-llvm-42b10572443e3f3f3c4a113f88ad4e9b504df900.tar.gz bcm5719-llvm-42b10572443e3f3f3c4a113f88ad4e9b504df900.zip |
N3922: direct-list-initialization of an auto-typed variable no longer deduces a
std::initializer_list<T> type. Instead, the list must contain a single element
and the type is deduced from that.
In Clang 3.7, we warned by default on all the cases that would change meaning
due to this change. In Clang 3.8, we will support only the new rules -- per
the request in N3922, this change is applied as a Defect Report against earlier
versions of the C++ standard.
This change is not entirely trivial, because for lambda init-captures we
previously did not track the difference between direct-list-initialization and
copy-list-initialization. The difference was not previously observable, because
the two forms of initialization always did the same thing (the elements of the
initializer list were always copy-initialized regardless of the initialization
style used for the init-capture).
llvm-svn: 252688
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/drs/dr13xx.cpp | 12 | ||||
-rw-r--r-- | clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp | 5 | ||||
-rw-r--r-- | clang/test/Parser/cxx0x-lambda-expressions.cpp | 2 | ||||
-rw-r--r-- | clang/test/Parser/objcxx0x-lambda-expressions.mm | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp | 6 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx1y-init-captures.cpp | 6 |
6 files changed, 21 insertions, 12 deletions
diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp index 29b39cbb95a..37c144eb0e0 100644 --- a/clang/test/CXX/drs/dr13xx.cpp +++ b/clang/test/CXX/drs/dr13xx.cpp @@ -7,9 +7,9 @@ namespace dr1346 { // dr1346: 3.5 auto a(1); // expected-error 0-1{{extension}} auto b(1, 2); // expected-error {{multiple expressions}} expected-error 0-1{{extension}} #if __cplusplus >= 201103L - auto c({}); // expected-error {{parenthesized initializer list}} expected-error {{cannot deduce}} - auto d({1}); // expected-error {{parenthesized initializer list}} expected-error {{<initializer_list>}} - auto e({1, 2}); // expected-error {{parenthesized initializer list}} expected-error {{<initializer_list>}} + auto c({}); // expected-error {{parenthesized initializer list}} + auto d({1}); // expected-error {{parenthesized initializer list}} + auto e({1, 2}); // expected-error {{parenthesized initializer list}} #endif template<typename...Ts> void f(Ts ...ts) { // expected-error 0-1{{extension}} auto x(ts...); // expected-error {{empty}} expected-error 0-1{{extension}} @@ -21,9 +21,9 @@ namespace dr1346 { // dr1346: 3.5 [a(1)] {} (); // expected-error 0-1{{extension}} [b(1, 2)] {} (); // expected-error {{multiple expressions}} expected-error 0-1{{extension}} #if __cplusplus >= 201103L - [c({})] {} (); // expected-error {{parenthesized initializer list}} expected-error {{cannot deduce}} expected-error 0-1{{extension}} - [d({1})] {} (); // expected-error {{parenthesized initializer list}} expected-error {{<initializer_list>}} expected-error 0-1{{extension}} - [e({1, 2})] {} (); // expected-error {{parenthesized initializer list}} expected-error {{<initializer_list>}} expected-error 0-1{{extension}} + [c({})] {} (); // expected-error {{parenthesized initializer list}} expected-error 0-1{{extension}} + [d({1})] {} (); // expected-error {{parenthesized initializer list}} expected-error 0-1{{extension}} + [e({1, 2})] {} (); // expected-error {{parenthesized initializer list}} expected-error 0-1{{extension}} #endif } #endif diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp index 1228c74b070..63e51a76144 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp @@ -48,7 +48,8 @@ auto bad_init_2 = [a(1, 2)] {}; // expected-error {{initializer for lambda captu auto bad_init_3 = [&a(void_fn())] {}; // expected-error {{cannot form a reference to 'void'}} auto bad_init_4 = [a(void_fn())] {}; // expected-error {{has incomplete type 'void'}} auto bad_init_5 = [a(overload_fn)] {}; // expected-error {{cannot deduce type for lambda capture 'a' from initializer of type '<overloaded function}} -auto bad_init_6 = [a{overload_fn}] {}; // expected-error {{cannot deduce type for lambda capture 'a' from initializer list}} expected-warning {{will change meaning in a future version of Clang}} +auto bad_init_6 = [a{overload_fn}] {}; // expected-error {{cannot deduce type for lambda capture 'a' from initializer list}} +auto bad_init_7 = [a{{1}}] {}; // expected-error {{cannot deduce type for lambda capture 'a' from nested initializer list}} template<typename...T> void pack_1(T...t) { (void)[a(t...)] {}; } // expected-error {{initializer missing for lambda capture 'a'}} template void pack_1<>(); // expected-note {{instantiation of}} @@ -61,7 +62,7 @@ auto a = [a(4), b = 5, &c = static_cast<const int&&>(0)] { using T = decltype(c); using T = const int &; }; -auto b = [a{0}] {}; // expected-error {{include <initializer_list>}} expected-warning {{will change meaning in a future version of Clang}} +auto b = [a{0}] {}; // OK, per N3922 struct S { S(); S(S&&); }; template<typename T> struct remove_reference { typedef T type; }; diff --git a/clang/test/Parser/cxx0x-lambda-expressions.cpp b/clang/test/Parser/cxx0x-lambda-expressions.cpp index c2bf6fd3960..7deeb219c9e 100644 --- a/clang/test/Parser/cxx0x-lambda-expressions.cpp +++ b/clang/test/Parser/cxx0x-lambda-expressions.cpp @@ -61,7 +61,7 @@ class C { int z; void init_capture() { [n(0)] () mutable -> int { return ++n; }; // expected-warning{{extension}} - [n{0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}} expected-warning{{will change meaning in a future version}} + [n{0}] { return; }; // expected-warning{{extension}} [n = 0] { return ++n; }; // expected-error {{captured by copy in a non-mutable}} expected-warning{{extension}} [n = {0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}} [a([&b = z]{})](){}; // expected-warning 2{{extension}} diff --git a/clang/test/Parser/objcxx0x-lambda-expressions.mm b/clang/test/Parser/objcxx0x-lambda-expressions.mm index c6ed121f8b4..0f3e9481a72 100644 --- a/clang/test/Parser/objcxx0x-lambda-expressions.mm +++ b/clang/test/Parser/objcxx0x-lambda-expressions.mm @@ -21,7 +21,7 @@ class C { [foo(bar)] () {}; [foo = bar] () {}; - [foo{bar}] () {}; // expected-error {{<initializer_list>}} expected-warning {{will change meaning}} + [foo{bar}] () {}; [foo = {bar}] () {}; // expected-error {{<initializer_list>}} [foo(bar) baz] () {}; // expected-error {{called object type 'int' is not a function}} diff --git a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp index 9456dd713aa..3d119643710 100644 --- a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -117,8 +117,10 @@ void argument_deduction() { void auto_deduction() { auto l = {1, 2, 3, 4}; - auto l2 {1, 2, 3, 4}; // expected-warning {{will change meaning in a future version of Clang}} + auto l2 {1, 2, 3, 4}; // expected-error {{initializer for variable 'l2' with type 'auto' contains multiple expressions}} + auto l3 {1}; static_assert(same_type<decltype(l), std::initializer_list<int>>::value, ""); + static_assert(same_type<decltype(l3), int>::value, ""); auto bl = {1, 2.0}; // expected-error {{cannot deduce}} for (int i : {1, 2, 3, 4}) {} @@ -190,7 +192,7 @@ namespace rdar11948732 { } namespace PR14272 { - auto x { { 0, 0 } }; // expected-error {{cannot deduce actual type for variable 'x' with type 'auto' from initializer list}} + auto x { { 0, 0 } }; // expected-error {{cannot deduce type for variable 'x' with type 'auto' from nested initializer list}} } namespace initlist_of_array { diff --git a/clang/test/SemaCXX/cxx1y-init-captures.cpp b/clang/test/SemaCXX/cxx1y-init-captures.cpp index 203e28d7c3f..d36882d8e5d 100644 --- a/clang/test/SemaCXX/cxx1y-init-captures.cpp +++ b/clang/test/SemaCXX/cxx1y-init-captures.cpp @@ -190,3 +190,9 @@ int run() { } } + +namespace N3922 { + struct X { X(); explicit X(const X&); int n; }; + auto a = [x{X()}] { return x.n; }; // ok + auto b = [x = {X()}] {}; // expected-error{{<initializer_list>}} +} |