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). --- clang/test/SemaTemplate/default-arguments.cpp | 138 ++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 clang/test/SemaTemplate/default-arguments.cpp (limited to 'clang/test/SemaTemplate/default-arguments.cpp') diff --git a/clang/test/SemaTemplate/default-arguments.cpp b/clang/test/SemaTemplate/default-arguments.cpp new file mode 100644 index 0000000..6391369 --- /dev/null +++ b/clang/test/SemaTemplate/default-arguments.cpp @@ -0,0 +1,138 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +template struct X; // expected-note{{template is declared here}} + +X *x1; +X *x2; + +X<> *x3; // expected-error{{too few template arguments for class template 'X'}} + +template struct X; + +X<> *x4; + +template struct Z { }; +template struct Z<>; + +// PR4362 +template struct a { }; +template<> struct a { static const bool v = true; }; + +template::v> struct p { }; // expected-error {{no member named 'v'}} + +template struct p; // expected-note {{in instantiation of default argument for 'p' required here}} +template struct p; + +// PR5187 +template +struct A; + +template +struct A; + +template +struct A { + void f(A); +}; + +template +struct B { }; + +template<> +struct B { + typedef B type; +}; + +// Nested default arguments for template parameters. +template struct X1 { }; + +template +struct X2 { + template::type> // expected-error{{no type named}} + struct Inner1 { }; + + template::value> // expected-error{{no member named 'value'}} + struct NonType1 { }; + + template + struct Inner2 { }; + + template + struct Inner3 { + template + struct VeryInner { }; + + template + struct NonType2 { }; + }; +}; + +X2 x2i; +X2::Inner1 x2iif; + +X2::Inner1<> x2bad; // expected-note{{instantiation of default argument}} + +X2::NonType1<'a'> x2_nontype1; +X2::NonType1<> x2_nontype1_bad; // expected-note{{instantiation of default argument}} + +// Check multi-level substitution into template type arguments +X2::Inner3::VeryInner<> vi; +X2::Inner3::NonType2<> x2_deep_nontype; + +template +struct is_same { static const bool value = false; }; + +template +struct is_same { static const bool value = true; }; + +int array1[is_same<__typeof__(vi), + X2::Inner3::VeryInner >::value? 1 : -1]; + +int array2[is_same<__typeof(x2_deep_nontype), + X2::Inner3::NonType2 >::value? 1 : -1]; + +// Template template parameter defaults +template class X = X2> struct X3 { }; +int array3[is_same, X3 >::value? 1 : -1]; + +struct add_pointer { + template + struct apply { + typedef T* type; + }; +}; + +template class X = T::template apply> + struct X4; +int array4[is_same, + X4 >::value? 1 : -1]; + +template struct X5 {}; // expected-note{{has a different type 'int'}} +template struct X5b {}; +template class B = X5> // expected-error{{template template argument has different}} \ + // expected-note{{previous non-type template parameter}} + struct X6 {}; + +X6 x6a; +X6 x6b; // expected-note{{while checking a default template argument}} +X6 x6c; + + +template class X = B > struct X7; // expected-error{{must be a class template}} + +namespace PR9643 { + template class allocator {}; + template > class vector {}; + + template > class container, + typename DT> + container
initializer(const DT& d) { + return container
(); + } + + void f() { + vector > v = initializer(5); + } +} -- cgit v1.2.3