summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2019-08-31 00:05:50 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2019-08-31 00:05:50 +0000
commit082754176f2ec785535f4bf65a804fdebbca21b2 (patch)
tree84e407dfe81d93905ac98916acf5076af5f1e93f /clang/test
parent33e17db59105fc9be904135a8e921e0c01348a2c (diff)
downloadbcm5719-llvm-082754176f2ec785535f4bf65a804fdebbca21b2.tar.gz
bcm5719-llvm-082754176f2ec785535f4bf65a804fdebbca21b2.zip
[c++20] Disallow template argument deduction from a braced-init-list
containing designators. The C++20 wording doesn't actually say what happens in this case, but treating this as a non-deduced context seems like the most natural behavior. (We might want to consider deducing through array designators as an extension in the future, but will need to be careful to deduce the array bound properly if we do so. That's not permitted herein.) llvm-svn: 370555
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp15
-rw-r--r--clang/test/SemaTemplate/deduction.cpp7
2 files changed, 20 insertions, 2 deletions
diff --git a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
index 9a82ec4a7bd..b5d6bd68f1f 100644
--- a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
+++ b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
@@ -29,9 +29,9 @@ namespace std {
typedef const _E* iterator;
typedef const _E* const_iterator;
- initializer_list() : __begin_(nullptr), __size_(0) {}
+ constexpr initializer_list() : __begin_(nullptr), __size_(0) {}
- size_t size() const {return __size_;}
+ constexpr size_t size() const {return __size_;}
const _E* begin() const {return __begin_;}
const _E* end() const {return __begin_ + __size_;}
};
@@ -354,3 +354,14 @@ namespace no_conversion_after_auto_list_deduction {
struct Y { using T = std::initializer_list<Y>(*)(); operator T(); };
auto (*y)() = { Y() }; // expected-error {{from initializer list}}
}
+
+namespace designated_init {
+ constexpr auto a = {.a = 1, .b = 2}; // expected-error {{cannot deduce}}
+ constexpr auto b = {[0] = 1, [4] = 2}; // expected-error {{cannot deduce}} expected-warning {{C99}}
+ constexpr auto c = {1, [4] = 2}; // expected-error {{cannot deduce}} expected-warning 2{{C99}} expected-note {{here}}
+ constexpr auto d = {1, [0] = 2}; // expected-error {{cannot deduce}} expected-warning 2{{C99}} expected-note {{here}}
+
+ // If we ever start accepting the above, these assertions should pass.
+ static_assert(c.size() == 5, "");
+ static_assert(d.size() == 1, "");
+}
diff --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp
index be86f18729d..64fef8e5f52 100644
--- a/clang/test/SemaTemplate/deduction.cpp
+++ b/clang/test/SemaTemplate/deduction.cpp
@@ -539,3 +539,10 @@ namespace dependent_list_deduction {
#endif
}
}
+
+namespace designators {
+ template<typename T, int N> constexpr int f(T (&&)[N]) { return N; } // expected-note 2{{couldn't infer template argument 'T'}}
+ static_assert(f({1, 2, [20] = 3}) == 3, ""); // expected-error {{no matching function}} expected-warning 2{{C99}} expected-note {{}}
+
+ static_assert(f({.a = 1, .b = 2}) == 3, ""); // expected-error {{no matching function}}
+}
OpenPOWER on IntegriCloud