diff options
Diffstat (limited to 'clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp')
-rw-r--r-- | clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp index 87e7e8462ba..a08a04806ca 100644 --- a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/clang/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}} +} |