summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2012-01-17 22:49:58 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2012-01-17 22:49:58 +0000
commit43144e72b5197c2e17a5586a59d41afe177d5055 (patch)
tree249aae0d63ae399170f7236687925619db7757e9 /clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
parentfb0b1f1f1f4db6d9743c8284c01fe09d30b64770 (diff)
downloadbcm5719-llvm-43144e72b5197c2e17a5586a59d41afe177d5055.tar.gz
bcm5719-llvm-43144e72b5197c2e17a5586a59d41afe177d5055.zip
Template argument deduction for std::initializer_list arguments from initializer lists.
llvm-svn: 148352
Diffstat (limited to 'clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp')
-rw-r--r--clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp22
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}}
+}
OpenPOWER on IntegriCloud