diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-02-21 07:22:31 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-02-21 07:22:31 +0000 |
commit | c6011fab81a4f72fc6a35c3b0b3d88fa57822a96 (patch) | |
tree | 38930c42b027e7d02061e201ae92102491e4bb6e /test/SemaTemplate | |
parent | 735b586081cd2e830b82fe1edd19a173e3512a60 (diff) |
When deducing an array bound from the length of an initializer list, don't
assume the bound has a non-dependent integral type.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295698 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r-- | test/SemaTemplate/deduction.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index a1180f0988..216b8347be 100644 --- a/test/SemaTemplate/deduction.cpp +++ b/test/SemaTemplate/deduction.cpp @@ -494,3 +494,45 @@ namespace dependent_template_template_param_non_type_param_type { // FIXME: This should be accepted, but we somehow fail to deduce W. A<0> a(qn); // expected-error {{no matching constructor for initialization}} } + +namespace dependent_list_deduction { + template<typename T, T V> void a(const int (&)[V]) { + static_assert(is_same<T, decltype(sizeof(0))>::value, ""); + static_assert(V == 3, ""); + } + template<typename T, T V> void b(const T (&)[V]) { + static_assert(is_same<T, int>::value, ""); + static_assert(V == 3, ""); + } + template<typename T, T V> void c(const T (&)[V]) { + static_assert(is_same<T, decltype(sizeof(0))>::value, ""); + static_assert(V == 3, ""); + } + void d() { + a({1, 2, 3}); +#if __cplusplus <= 201402L + // expected-error@-2 {{no match}} expected-note@-15 {{couldn't infer template argument 'T'}} +#endif + b({1, 2, 3}); + c({{}, {}, {}}); +#if __cplusplus <= 201402L + // expected-error@-2 {{no match}} expected-note@-12 {{couldn't infer template argument 'T'}} +#endif + } + + template<typename ...T> struct X; + template<int ...T> struct Y; + template<typename ...T, T ...V> void f(const T (&...p)[V]) { + static_assert(is_same<X<T...>, X<int, char, char>>::value, ""); + static_assert(is_same<Y<V...>, Y<3, 2, 4>>::value, ""); + } + template<typename ...T, T ...V> void g(const T (&...p)[V]) { // expected-note {{deduced incomplete pack}} + static_assert(is_same<X<T...>, X<int, decltype(sizeof(0))>>::value, ""); + static_assert(is_same<Y<V...>, Y<2, 3>>::value, ""); + } + void h() { + f({1, 2, 3}, {'a', 'b'}, "foo"); + // FIXME: Deduction in this case should succeed. + g({1, 2}, {{}, {}, {}}); // expected-error {{no match}} + } +} |