diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2012-01-17 22:49:58 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2012-01-17 22:49:58 +0000 |
commit | 84760e3a5d885ab19b5d11aafe78dfdfe2911e3a (patch) | |
tree | 6b03a458e920990e683e5a0fd81664411595d563 /test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp | |
parent | bb95e51a3668c50133b989467cd44ba4d8a42e8a (diff) |
Template argument deduction for std::initializer_list arguments from initializer lists.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp')
-rw-r--r-- | test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp index 87e7e8462b..a08a04806c 100644 --- a/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -32,6 +32,11 @@ namespace std { }; } +template <typename T, typename U> +struct same_type { static const bool value = false; }; +template <typename T> +struct same_type<T, T> { static const bool value = true; }; + struct one { char c[1]; }; struct two { char c[2]; }; @@ -87,3 +92,20 @@ void overloaded_call() { // But here, user-defined is worst in both cases. ov2({1, 2, D()}); // expected-error {{ambiguous}} } + +template <typename T> +T deduce(std::initializer_list<T>); // expected-note {{conflicting types for parameter 'T' ('int' vs. 'double')}} +template <typename T> +T deduce_ref(const std::initializer_list<T>&); // expected-note {{conflicting types for parameter 'T' ('int' vs. 'double')}} + +void argument_deduction() { + static_assert(same_type<decltype(deduce({1, 2, 3})), int>::value, "bad deduction"); + static_assert(same_type<decltype(deduce({1.0, 2.0, 3.0})), double>::value, "bad deduction"); + + deduce({1, 2.0}); // expected-error {{no matching function}} + + static_assert(same_type<decltype(deduce_ref({1, 2, 3})), int>::value, "bad deduction"); + static_assert(same_type<decltype(deduce_ref({1.0, 2.0, 3.0})), double>::value, "bad deduction"); + + deduce_ref({1, 2.0}); // expected-error {{no matching function}} +} |