From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- .../test/CXX/temp/temp.decls/temp.variadic/p4.cpp | 193 +++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp (limited to 'clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp') diff --git a/clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp b/clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp new file mode 100644 index 0000000..d8294a1 --- /dev/null +++ b/clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp @@ -0,0 +1,193 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fexceptions -fcxx-exceptions -verify %s + +template struct tuple; +template struct int_c; + +template +struct identity { + typedef T type; +}; + +template +struct is_same { + static const bool value = false; +}; + +template +struct is_same { + static const bool value = true; +}; + +// FIXME: Several more bullets to go + +// In a function parameter pack, the pattern is the parameter-declaration +// without the ellipsis. +namespace PR11850 { + template struct S { + int f(T...a, int b) { return b; } + }; + S<> s; + S t; + int k = s.f(0); + int l = t.f(&k, 'x', 5.9, 4); + + template struct A { + template struct B { + template struct C { + C(As..., Bs..., int &k, Cs...); + }; + }; + }; + A<>::B<>::C<> c000(k); + A::B<>::C c101(1, k, 3); + A<>::B::C c011(1, k, 3); + A::B::C<> c110(1, 2, k); + A::B::C c222(1, 2, 3, 4, k, 5, 6); + A::B<>::C<> c300(1, 2, 3, k); + + int &f(); + char &f(void*); + template struct U { + template struct V { + auto g(A...a, B...b) -> decltype(f(a...)); + }; + }; + U<>::V v0; + U::V<> v1; + int &v0f = v0.g(0); + char &v1f = v1.g(0); +} +namespace PR12096 { + void Foo(int) {} + void Foo(int, int) = delete; + template struct Var { + Var(const Args &...args, int *) { Foo(args...); } + }; + Var var(1, 0); +} + +// In an initializer-list (8.5); the pattern is an initializer-clause. +// Note: this also covers expression-lists, since expression-list is +// just defined as initializer-list. +void five_args(int, int, int, int, int); // expected-note{{candidate function not viable: requires 5 arguments, but 6 were provided}} + +template +void initializer_list_expansion() { + int values[5] = { Values... }; // expected-error{{excess elements in array initializer}} + five_args(Values...); // expected-error{{no matching function for call to 'five_args'}} +} + +template void initializer_list_expansion<1, 2, 3, 4, 5>(); +template void initializer_list_expansion<1, 2, 3, 4, 5, 6>(); // expected-note{{in instantiation of function template specialization 'initializer_list_expansion<1, 2, 3, 4, 5, 6>' requested here}} + +namespace PR8977 { + struct A { }; + template void f(Args... args) { + // An empty expression-list performs value initialization. + constexpr T t(args...); + }; + + template void f(); +} + +// In a base-specifier-list (Clause 10); the pattern is a base-specifier. +template +struct HasMixins : public Mixins... { + HasMixins(); + HasMixins(const HasMixins&); + HasMixins(int i); +}; + +struct A { }; // expected-note{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A' for 1st argument}} \ +// expected-note{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A' for 1st argument}} \ +// expected-note{{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}} +struct B { }; +struct C { }; +struct D { }; + +A *checkA = new HasMixins; +B *checkB = new HasMixins; +D *checkD = new HasMixins; +C *checkC = new HasMixins; // expected-error{{cannot initialize a variable of type 'C *' with an rvalue of type 'HasMixins *'}} +HasMixins<> *checkNone = new HasMixins<>; + +template +struct BrokenMixins : public Mixins... { }; // expected-error{{pack expansion does not contain any unexpanded parameter packs}} + +// In a mem-initializer-list (12.6.2); the pattern is a mem-initializer. +template +HasMixins::HasMixins(): Mixins()... { } + +template +HasMixins::HasMixins(const HasMixins &other): Mixins(other)... { } + +template +HasMixins::HasMixins(int i): Mixins(i)... { } // expected-error{{no matching constructor for initialization of 'A'}} + +void test_has_mixins() { + HasMixins ab; + HasMixins ab2 = ab; + HasMixins ab3(17); // expected-note{{in instantiation of member function 'HasMixins::HasMixins' requested here}} +} + +template +struct X { + T member; + + X() : member()... { } // expected-error{{pack expansion for initialization of member 'member'}} +}; + +// There was a bug in the delayed parsing code for the +// following case. +template +struct DelayedParseTest : T... +{ + int a; + DelayedParseTest(T... i) : T{i}..., a{10} {} +}; + + +// In a template-argument-list (14.3); the pattern is a template-argument. +template +struct tuple_of_refs { + typedef tuple types; +}; + +tuple *t_int_ref_float_ref; +tuple_of_refs::types *t_int_ref_float_ref_2 = t_int_ref_float_ref; + +template +struct extract_nested_types { + typedef tuple types; +}; + +tuple *t_int_float; +extract_nested_types, identity >::types *t_int_float_2 + = t_int_float; + +template +struct tuple_of_ints { + typedef tuple...> type; +}; + +int check_temp_arg_1[is_same::type, + tuple, int_c<2>, int_c<3>, int_c<4>, + int_c<5>>>::value? 1 : -1]; + +// In a dynamic-exception-specification (15.4); the pattern is a type-id. +template +struct f_with_except { + virtual void f() throw(Types...); // expected-note{{overridden virtual function is here}} +}; + +struct check_f_with_except_1 : f_with_except { + virtual void f() throw(int, float); +}; + +struct check_f_with_except_2 : f_with_except { + virtual void f() throw(int); +}; + +struct check_f_with_except_3 : f_with_except { + virtual void f() throw(int, float, double); // expected-error{{exception specification of overriding function is more lax than base version}} +}; -- cgit v1.2.3