Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/issue150.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // Core issue 150: Template template parameters and default arguments template<typename T, typename U> struct is_same { static const bool value = false; }; template<typename T> struct is_same<T, T> { static const bool value = true; }; namespace PR9353 { template<class _T, class Traits> class IM; template <class T, class Trt, template<class _T, class Traits = int> class IntervalMap> void foo(IntervalMap<T,Trt>* m) { typedef IntervalMap<int> type; } void f(IM<int, int>* m) { foo(m); } } namespace PR9400 { template<template <typename T, typename = T > class U> struct A { template<int> U<int> foo(); }; template <typename T, typename = T> struct s { }; void f() { A<s> x; x.foo<2>(); } } namespace MultiReplace { template<typename Z, template<typename T, typename U = T *, typename V = U const> class TT> struct X { typedef TT<Z> type; }; template<typename T, typename = int, typename = float> struct Y { }; int check0[is_same<X<int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1]; } namespace MultiReplacePartial { template<typename First, typename Z, template<typename T, typename U = T *, typename V = U const> class TT> struct X { typedef TT<Z> type; }; template<typename Z, template<typename T, typename U = T *, typename V = U const> class TT> struct X<int, Z, TT> { typedef TT<Z> type; }; template<typename T, typename = int, typename = float> struct Y { }; int check0[is_same<X<int, int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1]; } namespace PR9016 { template<typename > struct allocator ; template<typename > struct less ; template<class T, template<class> class Compare, class Default, template<class> class Alloc> struct interval_set { }; template <class X, template<class> class = less> struct interval_type_default { typedef X type; }; template <class T, template<class _T, template<class> class Compare = PR9016::less, class = typename interval_type_default<_T,Compare>::type, template<class> class = allocator> class IntervalSet> struct ZZZ { IntervalSet<T> IntervalSetT; }; template <class T, template<class _T, template<class> class Compare = PR9016::less, class = typename interval_type_default<_T,Compare>::type, template<class> class = allocator> class IntervalSet> void int40() { IntervalSet<T> IntervalSetT; } void test() { ZZZ<int, interval_set> zzz; int40<int, interval_set>(); } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/enum-bool.cpp
// %RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o %t enum E : bool { A }; template <E> struct S { struct Inner { Inner() {} }; }; template class S<A>;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-var-template.cpp
// RUN: %clang_cc1 -verify -std=c++1y %s namespace PR17846 { template <typename T> constexpr T pi = T(3.14); template <typename T> constexpr T tau = 2 * pi<T>; constexpr double tau_double = tau<double>; static_assert(tau_double == 6.28, ""); } namespace PR17848 { template<typename T> constexpr T var = 12345; template<typename T> constexpr T f() { return var<T>; } constexpr int k = f<int>(); static_assert(k == 12345, ""); } namespace NonDependent { template<typename T> constexpr T a = 0; template<typename T> constexpr T b = a<int>; static_assert(b<int> == 0, ""); } namespace InstantiationDependent { int f(int); void f(char); template<int> constexpr int a = 1; template<typename T> constexpr T b = a<sizeof(sizeof(f(T())))>; // expected-error {{invalid application of 'sizeof' to an incomplete type 'void'}} static_assert(b<int> == 1, ""); static_assert(b<char> == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}} template<typename T> void f() { static_assert(a<sizeof(sizeof(f(T())))> == 0, ""); // expected-error {{static_assert failed}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/default-arguments.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T, int N = 2> struct X; // expected-note{{template is declared here}} X<int, 1> *x1; X<int> *x2; X<> *x3; // expected-error{{too few template arguments for class template 'X'}} template<typename U = float, int M> struct X; X<> *x4; template<typename T = int> struct Z { }; template struct Z<>; // PR4362 template<class T> struct a { }; template<> struct a<int> { static const bool v = true; }; template<class T, bool = a<T>::v> struct p { }; // expected-error {{no member named 'v'}} template struct p<bool>; // expected-note {{in instantiation of default argument for 'p<bool>' required here}} template struct p<int>; // PR5187 template<typename T, typename U> struct A; template<typename T, typename U = T> struct A; template<typename T, typename U> struct A { void f(A<T>); }; template<typename T> struct B { }; template<> struct B<void> { typedef B<void*> type; }; // Nested default arguments for template parameters. template<typename T> struct X1 { }; template<typename T> struct X2 { template<typename U = typename X1<T>::type> // expected-error{{no type named 'type' in 'X1<int>'}} \ // expected-error{{no type named 'type' in 'X1<char>'}} struct Inner1 { }; // expected-note{{template is declared here}} template<T Value = X1<T>::value> // expected-error{{no member named 'value' in 'X1<int>'}} \ // expected-error{{no member named 'value' in 'X1<char>'}} struct NonType1 { }; // expected-note{{template is declared here}} template<T Value> struct Inner2 { }; template<typename U> struct Inner3 { template<typename X = T, typename V = U> struct VeryInner { }; template<T Value1 = sizeof(T), T Value2 = sizeof(U), T Value3 = Value1 + Value2> struct NonType2 { }; }; }; X2<int> x2i; // expected-note{{in instantiation of template class 'X2<int>' requested here}} X2<int>::Inner1<float> x2iif; X2<int>::Inner1<> x2bad; // expected-error{{too few template arguments for class template 'Inner1'}} X2<int>::NonType1<'a'> x2_nontype1; X2<int>::NonType1<> x2_nontype1_bad; // expected-error{{too few template arguments for class template 'NonType1'}} // Check multi-level substitution into template type arguments X2<int>::Inner3<float>::VeryInner<> vi; X2<char>::Inner3<int>::NonType2<> x2_deep_nontype; // expected-note{{in instantiation of template class 'X2<char>' requested here}} template<typename T, typename U> struct is_same { static const bool value = false; }; template<typename T> struct is_same<T, T> { static const bool value = true; }; int array1[is_same<__typeof__(vi), X2<int>::Inner3<float>::VeryInner<int, float> >::value? 1 : -1]; int array2[is_same<__typeof(x2_deep_nontype), X2<char>::Inner3<int>::NonType2<sizeof(char), sizeof(int), sizeof(char)+sizeof(int)> >::value? 1 : -1]; // Template template parameter defaults template<template<typename T> class X = X2> struct X3 { }; int array3[is_same<X3<>, X3<X2> >::value? 1 : -1]; struct add_pointer { template<typename T> struct apply { typedef T* type; }; }; template<typename T, template<typename> class X = T::template apply> struct X4; int array4[is_same<X4<add_pointer>, X4<add_pointer, add_pointer::apply> >::value? 1 : -1]; template<int> struct X5 {}; // expected-note{{has a different type 'int'}} template<long> struct X5b {}; template<typename T, template<T> class B = X5> // expected-error{{template template argument has different}} \ // expected-note{{previous non-type template parameter}} struct X6 {}; X6<int> x6a; X6<long> x6b; // expected-note{{while checking a default template argument}} X6<long, X5b> x6c; template<template<class> class X = B<int> > struct X7; // expected-error{{must be a class template}} namespace PR9643 { template<typename T> class allocator {}; template<typename T, typename U = allocator<T> > class vector {}; template<template<typename U, typename = allocator<U> > class container, typename DT> container<DT> initializer(const DT& d) { return container<DT>(); } void f() { vector<int, allocator<int> > v = initializer<vector>(5); } } namespace PR16288 { template<typename X> struct S { template<typename T = int, typename U> // expected-warning {{C++11}} void f(); }; template<typename X> template<typename T, typename U> void S<X>::f() {} } namespace DR1635 { template <class T> struct X { template <class U = typename T::type> static void f(int) {} // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} \ // expected-warning {{C++11}} static void f(...) {} }; int g() { X<int>::f(0); } // expected-note {{in instantiation of template class 'DR1635::X<int>' requested here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-default-2.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T, T Value> struct Constant; // expected-note{{template parameter is declared here}} \ // FIXME: bad location expected-error{{a non-type template parameter cannot have type 'float'}} Constant<int, 5> *c1; int x; float f(int, double); Constant<int&, x> *c2; Constant<int*, &x> *c3; Constant<float (*)(int, double), f> *c4; Constant<float (*)(int, double), &f> *c5; Constant<float (*)(int, int), f> *c6; // expected-error{{non-type template argument of type 'float (int, double)' cannot be converted to a value of type 'float (*)(int, int)'}} Constant<float, 0> *c7; // expected-note{{while substituting}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-type.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s int* f(int); float *f(...); template<typename T> struct X { typedef typeof(T*) typeof_type; typedef typeof(f(T())) typeof_expr; }; int *iptr0; float *fptr0; X<int>::typeof_type &iptr1 = iptr0; X<int>::typeof_expr &iptr2 = iptr0; X<float*>::typeof_expr &fptr1 = fptr0; namespace rdar13094134 { template <class> class X { typedef struct { Y *y; // expected-error{{unknown type name 'Y'}} } Y; }; X<int> xi; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/overload-uneval.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused %s // expected-no-diagnostics // Tests that overload resolution is treated as an unevaluated context. // PR5541 struct Foo { Foo *next; }; template <typename> struct Bar { }; template <typename T> class Wibble { typedef Bar<T> B; static inline B *concrete(Foo *node) { int a[sizeof(T) ? -1 : -1]; return reinterpret_cast<B *>(node); } public: class It { Foo *i; public: inline operator B *() const { return concrete(i); } inline bool operator!=(const It &o) const { return i != o.i; } }; }; void f() { Wibble<void*>::It a, b; a != b; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/fun-template-def.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // Tests that dependent expressions are always allowed, whereas non-dependent // are checked as usual. #include <stddef.h> // Fake typeid, lacking a typeinfo header. namespace std { class type_info {}; } struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}} template<typename T> int f0(T x) { return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2; } template <typename T, typename U> T f1(T t1, U u1, int i1) { T t2 = i1; t2 = i1 + u1; ++u1; u1++; int i2 = u1; i1 = t1[u1]; i1 *= t1; i1(u1, t1); // error u1(i1, t1); U u2 = (T)i1; static_cast<void>(static_cast<U>(reinterpret_cast<T>( dynamic_cast<U>(const_cast<T>(i1))))); new U(i1, t1); new int(t1, u1); new (t1, u1) int; delete t1; dummy d1 = sizeof(t1); // expected-error {{no viable conversion}} dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}} dummy d3 = __alignof(u1); // expected-error {{no viable conversion}} i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}} return u1; } template<typename T> void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}} void f3() { f2<int*>(0); f2<int>(0); // expected-error {{no matching function for call to 'f2'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ackermann.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // template<unsigned M, unsigned N> // struct Ackermann { // enum { // value = M ? (N ? Ackermann<M-1, Ackermann<M, N-1> >::value // : Ackermann<M-1, 1>::value) // : N + 1 // }; // }; template<unsigned M, unsigned N> struct Ackermann { enum { value = Ackermann<M-1, Ackermann<M, N-1>::value >::value }; }; template<unsigned M> struct Ackermann<M, 0> { enum { value = Ackermann<M-1, 1>::value }; }; template<unsigned N> struct Ackermann<0, N> { enum { value = N + 1 }; }; template<> struct Ackermann<0, 0> { enum { value = 1 }; }; int g0[Ackermann<3, 4>::value == 125 ? 1 : -1];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-complete.cpp
// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify %s // RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -verify %s // Tests various places where requiring a complete type involves // instantiation of that type. template<typename T> struct X { X(T); #ifdef MSABI // expected-error@+2{{data member instantiated with function type 'long (long)'}} #endif T f; // expected-error{{data member instantiated with function type 'float (int)'}} \ // expected-error{{data member instantiated with function type 'int (int)'}} \ // expected-error{{data member instantiated with function type 'char (char)'}} \ // expected-error{{data member instantiated with function type 'short (short)'}} \ // expected-error{{data member instantiated with function type 'float (float)'}} }; X<int> f() { return 0; } struct XField { X<float(int)> xf; // expected-note{{in instantiation of template class 'X<float (int)>' requested here}} }; void test_subscript(X<double> *ptr1, X<int(int)> *ptr2, int i) { (void)ptr1[i]; (void)ptr2[i]; // expected-note{{in instantiation of template class 'X<int (int)>' requested here}} } void test_arith(X<signed char> *ptr1, X<unsigned char> *ptr2, X<char(char)> *ptr3, X<short(short)> *ptr4) { (void)(ptr1 + 5); (void)(5 + ptr2); (void)(ptr3 + 5); // expected-note{{in instantiation of template class 'X<char (char)>' requested here}} (void)(5 + ptr4); // expected-note{{in instantiation of template class 'X<short (short)>' requested here}} } void test_new() { (void)new X<float>(0); (void)new X<float(float)>; // expected-note{{in instantiation of template class 'X<float (float)>' requested here}} } void test_memptr(X<long> *p1, long X<long>::*pm1, X<long(long)> *p2, #ifdef MSABI long (X<long(long)>::*pm2)(long)) { // expected-note{{in instantiation of template class 'X<long (long)>' requested here}} #else long (X<long(long)>::*pm2)(long)) { #endif (void)(p1->*pm1); } // Reference binding to a base template<typename T> struct X1 { }; template<typename T> struct X2 : public T { }; void refbind_base(X2<X1<int> > &x2) { X1<int> &x1 = x2; } // Enumerate constructors for user-defined conversion. template<typename T> struct X3 { X3(T); }; void enum_constructors(X1<float> &x1) { X3<X1<float> > x3 = x1; } namespace PR6376 { template<typename T, typename U> struct W { }; template<typename T> struct X { template<typename U> struct apply { typedef W<T, U> type; }; }; template<typename T, typename U> struct Y : public X<T>::template apply<U>::type { }; template struct Y<int, float>; } namespace TemporaryObjectCopy { // Make sure we instantiate classes when we create a temporary copy. template<typename T> struct X { X(T); }; template<typename T> void f(T t) { const X<int> &x = X<int>(t); } template void f(int); } namespace PR7080 { template <class T, class U> class X { typedef char true_t; class false_t { char dummy[2]; }; static true_t dispatch(U); static false_t dispatch(...); static T trigger(); public: enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) }; }; template <class T> class rv : public T { }; bool x = X<int, rv<int>&>::value; } namespace pr7199 { template <class T> class A; // expected-note {{template is declared here}} template <class T> class B { class A<T>::C field; // expected-error {{implicit instantiation of undefined template 'pr7199::A<int>'}} }; template class B<int>; // expected-note {{in instantiation}} } namespace PR8425 { template <typename T> class BaseT {}; template <typename T> class DerivedT : public BaseT<T> {}; template <typename T> class FromT { public: operator DerivedT<T>() const { return DerivedT<T>(); } }; void test() { FromT<int> ft; BaseT<int> bt(ft); } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/destructor-template.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s template<typename A> class s0 { template<typename B> class s1 : public s0<A> { ~s1() {} s0<A> ms0; }; }; struct Incomplete; template<typename T> void destroy_me(T me) { me.~T(); } template void destroy_me(Incomplete*); namespace PR6152 { template<typename T> struct X { void f(); }; template<typename T> struct Y { }; template<typename T> void X<T>::f() { Y<T> *y; y->template Y<T>::~Y(); y->template Y<T>::~Y<T>(); y->~Y(); } template struct X<int>; } namespace cvquals { template<typename T> void f(int *ptr) { ptr->~T(); } template void f<const volatile int>(int *); } namespace PR7239 { template<class E> class A { }; class B { void f() { A<int>* x; x->A<int>::~A<int>(); } }; } namespace PR7904 { struct Foo {}; template <class T> Foo::~Foo() { // expected-error{{destructor cannot be declared as a template}} T t; T &pT = t; pT; } Foo f; } namespace rdar13140795 { template <class T> class shared_ptr {}; template <typename T> struct Marshal { static int gc(); }; template <typename T> int Marshal<T>::gc() { shared_ptr<T> *x; x->template shared_ptr<T>::~shared_ptr(); return 0; } void test() { Marshal<int>::gc(); } } namespace PR16852 { template<typename T> struct S { int a; T x; }; template<typename T> decltype(S<T>().~S()) f(); // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} void g() { f(); } // expected-error {{no matching function for call to 'f'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-overload-candidates.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // This is the function actually selected during overload resolution, and the // only one defined. template <typename T> void f(T*, int) {} template <typename T> struct S; template <typename T> struct S_ : S<T> { typedef int type; }; // expected-note{{in instantiation}} template <typename T> struct S { // Force T to have a complete type here so we can observe instantiations with // incomplete types. T t; // expected-error{{field has incomplete type}} }; // Provide a bad class and an overload that instantiates templates with it. class NoDefinition; // expected-note{{forward declaration}} template <typename T> S_<NoDefinition>::type f(T*, NoDefinition*); // expected-note{{in instantiation}} void test(int x) { f(&x, 0); } // Ensure that we instantiate an overloaded function if it's selected by // overload resolution when initializing a function pointer. template<typename T> struct X { static T f() { T::error; } // expected-error {{has no members}} static T f(bool); }; void (*p)() = &X<void>::f; // expected-note {{instantiation of}} namespace PR13098 { struct A { A(int); void operator++() {} void operator+(int) {} void operator+(A) {} void operator[](int) {} void operator[](A) {} }; struct B : A { using A::operator++; using A::operator+; using A::operator[]; }; template<typename T> void f(B b) { ++b; b + 0; b[0]; } template void f<void>(B); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/qualified-id.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // PR5061 namespace a { template <typename T> class C {}; } namespace b { template<typename T> void f0(a::C<T> &a0) { } } namespace test1 { int a = 0; template <class T> class Base { }; template <class T> class Derived : public Base<T> { int foo() { return test1::a; } }; } namespace test2 { class Impl { public: int foo(); }; template <class T> class Magic : public Impl { int foo() { return Impl::foo(); } }; } namespace PR6063 { template <typename T> void f(T, T); namespace detail { using PR6063::f; } template <typename T> void g(T a, T b) { detail::f(a, b); } } namespace PR12291 { template <typename T> class Outer2 { template <typename V> template <typename W> class Outer2<V>::Inner; // expected-error{{nested name specifier 'Outer2<V>::' for declaration does not refer into a class, class template or class template partial specialization}} }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/member-access-ambig.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-comparison %s // PR8439 class A { }; class B { public: A & m; }; class Base { public: B &f(); }; class Derived1 : public Base { }; class Derived2 : public Base { }; class X : public B, public Derived2, public Derived1 { public: virtual void g(); }; void X::g() { m.f<int>(); // expected-error{{no member named 'f' in 'A'}} \ // expected-error{{expected '(' for function-style cast}} \ // expected-error{{expected expression}} } namespace PR11134 { template<typename Derived> class A; template<typename Derived> class B : A<Derived> { typedef A<Derived> Base; using Base::member; int member; }; } namespace AddrOfMember { struct A { int X; }; typedef int (A::*P); template<typename T> struct S : T { void f() { P(&T::X) // expected-error {{cannot cast from type 'int *' to member pointer type 'P'}} == &A::X; } }; void g() { S<A>().f(); // ok, &T::X is 'int (A::*)', not 'int *', even though T is a base class } struct B : A { static int X; }; void h() { S<B>().f(); // expected-note {{here}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/implicit-instantiation-1.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T, typename U> struct X { T f(T x, U y) { return x + y; } unsigned g(T x, U y) { return sizeof(f(x, y)); } }; void test(X<int, int> *xii, X<int*, int> *xpi, X<int, int*> *xip) { (void)xii->f(1, 2); (void)xpi->f(0, 2); (void)sizeof(xip->f(2, 0)); // okay: does not instantiate (void)xip->g(2, 0); // okay: does not instantiate } template<typename T, typename U> T add(T t, U u) { return t + u; // expected-error{{invalid operands}} } void test_add(char *cp, int i, int *ip) { char* cp2 = add(cp, i); add(cp, cp); // expected-note{{instantiation of}} (void)sizeof(add(ip, ip)); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/explicit-instantiation.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions %s // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions -std=c++11 %s template void *; // expected-error{{expected unqualified-id}} template typedef void f0; // expected-error{{explicit instantiation of typedef}} int v0; // expected-note{{refers here}} template int v0; // expected-error{{does not refer}} template<typename T> struct X0 { static T value; T f0(T x) { return x + 1; // expected-error{{invalid operands}} } T *f0(T *, T *) { return T(); } // expected-warning 0-1 {{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} expected-error 0-1 {{cannot initialize return object of type 'int *' with an rvalue of type 'int'}} template <typename U> T f0(T, U) { return T(); } // expected-note-re {{candidate template ignored: could not match 'int (int, U){{( __attribute__\(\(thiscall\)\))?}}' against 'int (int){{( __attribute__\(\(thiscall\)\))?}} const'}} \ // expected-note {{candidate template ignored: could not match 'int' against 'int *'}} }; template<typename T> T X0<T>::value; // expected-error{{no matching constructor}} template int X0<int>::value; struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} expected-note 0-1 {{candidate constructor (the implicit move constructor)}} NotDefaultConstructible(int); // expected-note{{candidate constructor}} }; template NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}} template int X0<int>::f0(int); template int* X0<int>::f0(int*, int*); // expected-note{{in instantiation of member function 'X0<int>::f0' requested here}} template int X0<int>::f0(int, float); template int X0<int>::f0(int) const; // expected-error{{does not refer}} template int* X0<int>::f0(int*, float*); // expected-error{{does not refer}} struct X1 { }; typedef int X1::*MemPtr; template MemPtr X0<MemPtr>::f0(MemPtr); // expected-note{{requested here}} struct X2 { int f0(int); // expected-note{{refers here}} template<typename T> T f1(T) { return T(); } template<typename T> T* f1(T*) { return 0; } template<typename T, typename U> void f2(T, U*) { } // expected-note{{candidate}} template<typename T, typename U> void f2(T*, U) { } // expected-note{{candidate}} }; template int X2::f0(int); // expected-error{{not an instantiation}} template int *X2::f1(int *); // okay template void X2::f2(int *, int *); // expected-error{{ambiguous}} template <typename T> void print_type() {} // expected-note {{candidate template ignored: could not match 'void ()' against 'void (float *)'}} template void print_type<int>(); template void print_type<float>(); template <typename T> void print_type(T *) {} // expected-note {{candidate template ignored: could not match 'void (int *)' against 'void (float *)'}} template void print_type(int*); template void print_type<int>(float*); // expected-error{{does not refer}} void print_type(double*); template void print_type<double>(double*); // PR5069 template<int I> void foo0 (int (&)[I + 1]) { } template void foo0<2> (int (&)[3]); namespace explicit_instantiation_after_implicit_instantiation { template <int I> struct X0 { static int x; }; template <int I> int X0<I>::x; void test1() { (void)&X0<1>::x; } template struct X0<1>; } template<typename> struct X3 { }; inline template struct X3<int>; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}} static template struct X3<float>; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}} namespace PR7622 { template<typename,typename=int> struct basic_streambuf; template<typename,typename> struct basic_streambuf{friend bob<>()}; // expected-error{{unknown type name 'bob'}} \ // expected-error{{expected member name or ';' after declaration specifiers}} template struct basic_streambuf<int>; } // Test that we do not crash. class TC1 { class TC2 { template // FIXME: error here. void foo() { } }; }; namespace PR8020 { template <typename T> struct X { X() {} }; template<> struct X<int> { X(); }; template X<int>::X() {} // expected-error{{function cannot be defined in an explicit instantiation}} } namespace PR10086 { template void foobar(int i) {} // expected-error{{function cannot be defined in an explicit instantiation}} int func() { foobar(5); } } namespace undefined_static_data_member { template<typename T> struct A { static int a; // expected-note {{here}} template<typename U> static int b; // expected-note {{here}} expected-warning {{extension}} }; struct B { template<typename U> static int c; // expected-note {{here}} expected-warning {{extension}} }; template int A<int>::a; // expected-error {{explicit instantiation of undefined static data member 'a' of class template 'undefined_static_data_member::A<int>'}} template int A<int>::b<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::A<int>::b<int>'}} template int B::c<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::B::c<int>'}} template<typename T> struct C { static int a; template<typename U> static int b; // expected-warning {{extension}} }; struct D { template<typename U> static int c; // expected-warning {{extension}} }; template<typename T> int C<T>::a; template<typename T> template<typename U> int C<T>::b; // expected-warning {{extension}} template<typename U> int D::c; // expected-warning {{extension}} template int C<int>::a; template int C<int>::b<int>; template int D::c<int>; } // expected-note@+1 3-4 {{explicit instantiation refers here}} template <class T> void Foo(T i) throw(T) { throw i; } // expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}} template void Foo(int a) throw(char); // expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}} template void Foo(double a) throw(); // expected-error@+1 1 {{exception specification in explicit instantiation does not match instantiated one}} template void Foo(long a) throw(long, char); template void Foo(float a); #if __cplusplus >= 201103L // expected-error@+1 0-1 {{exception specification in explicit instantiation does not match instantiated one}} template void Foo(double a) noexcept; #endif #if __cplusplus >= 201103L namespace PR21942 { template <int> struct A { virtual void foo() final; }; template <> void A<0>::foo() {} // expected-note{{overridden virtual function is here}} struct B : A<0> { virtual void foo() override; // expected-error{{declaration of 'foo' overrides a 'final' function}} }; } #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-local-class.cpp
// RUN: %clang_cc1 -verify -std=c++11 %s // RUN: %clang_cc1 -verify -std=c++11 -fdelayed-template-parsing %s template<typename T> void f0() { struct X; typedef struct Y { T (X::* f1())(int) { return 0; } } Y2; Y2 y = Y(); } template void f0<int>(); // PR5764 namespace PR5764 { struct X { template <typename T> void Bar() { typedef T ValueType; struct Y { Y() { V = ValueType(); } ValueType V; }; Y y; } }; void test(X x) { x.Bar<int>(); } } // Instantiation of local classes with virtual functions. namespace local_class_with_virtual_functions { template <typename T> struct X { }; template <typename T> struct Y { }; template <typename T> void f() { struct Z : public X<Y<T>*> { virtual void g(Y<T>* y) { } void g2(int x) {(void)x;} }; Z z; (void)z; } struct S { }; void test() { f<S>(); } } namespace PR8801 { template<typename T> void foo() { class X; typedef int (X::*pmf_type)(); class X : public T { }; pmf_type pmf = &T::foo; } struct Y { int foo(); }; template void foo<Y>(); } namespace TemplatePacksAndLambdas { template <typename ...T> int g(T...); struct S { template <typename ...T> static void f(int f = g([]{ static T t; return ++t; }()...)) {} }; void h() { S::f<int, int, int>(); } } namespace PR9685 { template <class Thing> void forEach(Thing t) { t.func(); } template <typename T> void doIt() { struct Functor { void func() { (void)i; } int i; }; forEach(Functor()); } void call() { doIt<int>(); } } namespace PR12702 { struct S { template <typename F> bool apply(F f) { return f(); } }; template <typename> struct T { void foo() { struct F { int x; bool operator()() { return x == 0; } }; S().apply(F()); } }; void call() { T<int>().foo(); } } namespace PR17139 { template <class T> void foo(const T &t) { t.foo(); } template <class F> void bar(F *f) { struct B { F *fn; void foo() const { fn(); } } b = { f }; foo(b); } void go() {} void test() { bar(go); } } namespace PR17740 { class C { public: template <typename T> static void foo(T function); template <typename T> static void bar(T function); template <typename T> static void func(T function); }; template <typename T> void C::foo(T function) { function(); } template <typename T> void C::bar(T function) { foo([&function]() { function(); }); } template <typename T> void C::func(T function) { struct Struct { T mFunction; Struct(T function) : mFunction(function) {}; void operator()() { mFunction(); }; }; bar(Struct(function)); } void call() { C::func([]() {}); } } namespace PR14373 { struct function { template <typename _Functor> function(_Functor __f) { __f(); } }; template <typename Func> function exec_func(Func f) { struct functor { functor(Func f) : func(f) {} void operator()() const { func(); } Func func; }; return functor(f); } struct Type { void operator()() const {} }; int call() { exec_func(Type()); return 0; } } namespace PR18907 { template <typename> class C : public C<int> {}; // expected-error{{within its own definition}} template <typename X> void F() { struct A : C<X> {}; } struct B { void f() { F<int>(); } }; } namespace PR23194 { struct X { int operator()() const { return 0; } }; struct Y { Y(int) {} }; template <bool = true> int make_seed_pair() noexcept { struct state_t { X x; Y y{x()}; }; return 0; } int func() { return make_seed_pair(); } } namespace PR18653 { // Forward declarations template<typename T> void f1() { void g1(struct x1); struct x1 {}; } template void f1<int>(); template<typename T> void f1a() { void g1(union x1); union x1 {}; } template void f1a<int>(); template<typename T> void f2() { void g2(enum x2); // expected-error{{ISO C++ forbids forward references to 'enum' types}} enum x2 { nothing }; } template void f2<int>(); template<typename T> void f3() { void g3(enum class x3); enum class x3 { nothing }; } template void f3<int>(); template<typename T> void f4() { void g4(struct x4 {} x); // expected-error{{'x4' cannot be defined in a parameter type}} } template void f4<int>(); template<typename T> void f4a() { void g4(union x4 {} x); // expected-error{{'x4' cannot be defined in a parameter type}} } template void f4a<int>(); template <class T> void f(); template <class T> struct S1 { void m() { f<class newclass>(); f<union newunion>(); } }; template struct S1<int>; template <class T> struct S2 { void m() { f<enum new_enum>(); // expected-error{{ISO C++ forbids forward references to 'enum' types}} } }; template struct S2<int>; template <class T> struct S3 { void m() { f<enum class new_enum>(); } }; template struct S3<int>; template <class T> struct S4 { struct local {}; void m() { f<local>(); } }; template struct S4<int>; template <class T> struct S4a { union local {}; void m() { f<local>(); } }; template struct S4a<int>; template <class T> struct S5 { enum local { nothing }; void m() { f<local>(); } }; template struct S5<int>; template <class T> struct S7 { enum class local { nothing }; void m() { f<local>(); } }; template struct S7<int>; template <class T> void fff(T *x); template <class T> struct S01 { struct local { }; void m() { local x; fff(&x); } }; template struct S01<int>; template <class T> struct S01a { union local { }; void m() { local x; fff(&x); } }; template struct S01a<int>; template <class T> struct S02 { enum local { nothing }; void m() { local x; fff(&x); } }; template struct S02<int>; template <class T> struct S03 { enum class local { nothing }; void m() { local x; fff(&x); } }; template struct S03<int>; template <class T> struct S04 { void m() { struct { } x; fff(&x); } }; template struct S04<int>; template <class T> struct S04a { void m() { union { } x; fff(&x); } }; template struct S04a<int>; template <class T> struct S05 { void m() { enum { nothing } x; fff(&x); } }; template struct S05<int>; template <class T> struct S06 { void m() { class { virtual void mmm() {} } x; fff(&x); } }; template struct S06<int>; } namespace PR20625 { template <typename T> void f() { struct N { static constexpr int get() { return 42; } }; constexpr int n = N::get(); static_assert(n == 42, "n == 42"); } void g() { f<void>(); } } namespace PR21332 { template<typename T> void f1() { struct S { // expected-note{{in instantiation of member class 'S' requested here}} void g1(int n = T::error); // expected-error{{type 'int' cannot be used prior to '::' because it has no members}} }; } template void f1<int>(); // expected-note{{in instantiation of function template specialization 'PR21332::f1<int>' requested here}} template<typename T> void f2() { struct S { // expected-note{{in instantiation of member class 'S' requested here}} void g2() noexcept(T::error); // expected-error{{type 'int' cannot be used prior to '::' because it has no members}} }; } template void f2<int>(); // expected-note{{in instantiation of function template specialization 'PR21332::f2<int>' requested here}} template<typename T> void f3() { enum S { val = T::error; // expected-error{{expected '}' or ','}} expected-error{{type 'int' cannot be used prior to '::' because it has no members}} }; } template void f3<int>(); //expected-note{{in instantiation of function template specialization 'PR21332::f3<int>' requested here}} template<typename T> void f4() { enum class S { val = T::error; // expected-error{{expected '}' or ','}} expected-error{{type 'int' cannot be used prior to '::' because it has no members}} }; } template void f4<int>(); // expected-note{{in instantiation of function template specialization 'PR21332::f4<int>' requested here}} template<typename T> void f5() { class S { // expected-note {{in instantiation of default member initializer 'PR21332::f5()::S::val' requested here}} int val = T::error; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} }; } template void f5<int>(); // expected-note {{in instantiation of function template specialization 'PR21332::f5<int>' requested here}} template<typename T> void f6() { class S { // expected-note {{in instantiation of member function 'PR21332::f6()::S::get' requested here}} void get() { class S2 { // expected-note {{in instantiation of member class 'S2' requested here}} void g1(int n = T::error); // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} }; } }; } template void f6<int>(); // expected-note{{in instantiation of function template specialization 'PR21332::f6<int>' requested here}} template<typename T> void f7() { struct S { void g() noexcept(undefined_val); }; // expected-error{{use of undeclared identifier 'undefined_val'}} } template void f7<int>(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp
// RUN: %clang_cc1 -std=c++1y -fms-compatibility -fno-spell-checking -fsyntax-only -verify %s template <class T> class A { public: void f(T a) { }// expected-note {{must qualify identifier to find this declaration in dependent base class}} void g();// expected-note {{must qualify identifier to find this declaration in dependent base class}} }; template <class T> class B : public A<T> { public: void z(T a) { f(a); // expected-warning {{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } }; template class B<int>; // expected-note {{requested here}} template class B<char>; void test() { B<int> b; b.z(3); } struct A2 { template<class T> void f(T) { XX; //expected-error {{use of undeclared identifier 'XX'}} A2::XX; //expected-error {{no member named 'XX' in 'A2'}} } }; template void A2::f(int); template<class T0> struct A3 { template<class T1> void f(T1) { XX; //expected-error {{use of undeclared identifier 'XX'}} } }; template void A3<int>::f(int); template<class T0> struct A4 { void f(char) { XX; //expected-error {{use of undeclared identifier 'XX'}} } }; template class A4<int>; namespace lookup_dependent_bases_id_expr { template<class T> class A { public: int var; }; template<class T> class B : public A<T> { public: void f() { var = 3; // expected-warning {{use of undeclared identifier 'var'; unqualified lookup into dependent bases of class template 'B' is a Microsoft extension}} } }; template class B<int>; } namespace lookup_dependent_base_class_static_function { template <class T> class A { public: static void static_func();// expected-note {{must qualify identifier to find this declaration in dependent base class}} void func();// expected-note {{must qualify identifier to find this declaration in dependent base class}} }; template <class T> class B : public A<T> { public: static void z2(){ static_func(); // expected-warning {{use of identifier 'static_func' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} func(); // expected-warning {{use of identifier 'func' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} expected-error {{call to non-static member function without an object argument}} } }; template class B<int>; // expected-note {{requested here}} } namespace lookup_dependent_base_class_default_argument { template<class T> class A { public: static int f1(); // expected-note {{must qualify identifier to find this declaration in dependent base class}} int f2(); // expected-note {{must qualify identifier to find this declaration in dependent base class}} }; template<class T> class B : public A<T> { public: void g1(int p = f1());// expected-warning {{use of identifier 'f1' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} void g2(int p = f2());// expected-warning {{use of identifier 'f2' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} expected-error {{call to non-static member function without an object argument}} }; void foo() { B<int> b; b.g1(); // expected-note {{required here}} b.g2(); // expected-note {{required here}} } } namespace lookup_dependent_base_class_friend { template <class T> class B { public: static void g(); // expected-note {{must qualify identifier to find this declaration in dependent base class}} }; template <class T> class A : public B<T> { public: friend void foo(A<T> p){ g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } }; int main2() { A<int> a; foo(a); // expected-note {{requested here}} } } namespace lookup_dependent_base_no_typo_correction { class C { public: int m_hWnd; }; template <class T> class A : public T { public: void f(int hWnd) { m_hWnd = 1; // expected-warning {{use of undeclared identifier 'm_hWnd'; unqualified lookup into dependent bases of class template 'A' is a Microsoft extension}} } }; template class A<C>; } namespace PR12701 { class A {}; class B {}; template <class T> class Base { public: bool base_fun(void* p) { return false; } // expected-note {{must qualify identifier to find this declaration in dependent base class}} operator T*() const { return 0; } }; template <class T> class Container : public Base<T> { public: template <typename S> bool operator=(const Container<S>& rhs) { return base_fun(rhs); // expected-warning {{use of identifier 'base_fun' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } }; void f() { Container<A> text_provider; Container<B> text_provider2; text_provider2 = text_provider; // expected-note {{in instantiation of function template specialization}} } } // namespace PR12701 namespace PR16014 { struct A { int a; static int sa; }; template <typename T> struct B : T { int foo() { return a; } // expected-warning {{lookup into dependent bases}} int *bar() { return &a; } // expected-warning {{lookup into dependent bases}} int baz() { return T::a; } int T::*qux() { return &T::a; } static int T::*stuff() { return &T::a; } static int stuff1() { return T::sa; } static int *stuff2() { return &T::sa; } static int stuff3() { return sa; } // expected-warning {{lookup into dependent bases}} static int *stuff4() { return &sa; } // expected-warning {{lookup into dependent bases}} }; template <typename T> struct C : T { int foo() { return b; } // expected-error {{no member named 'b' in 'PR16014::C<PR16014::A>'}} expected-warning {{lookup into dependent bases}} int *bar() { return &b; } // expected-error {{no member named 'b' in 'PR16014::C<PR16014::A>'}} expected-warning {{lookup into dependent bases}} int baz() { return T::b; } // expected-error {{no member named 'b' in 'PR16014::A'}} int T::*qux() { return &T::b; } // expected-error {{no member named 'b' in 'PR16014::A'}} int T::*fuz() { return &U::a; } // expected-error {{use of undeclared identifier 'U'}} \ // expected-warning {{unqualified lookup into dependent bases of class template 'C'}} }; template struct B<A>; template struct C<A>; // expected-note-re 1+ {{in instantiation of member function 'PR16014::C<PR16014::A>::{{.*}}' requested here}} template <typename T> struct D : T { struct Inner { int foo() { // FIXME: MSVC can find this in D's base T! Even worse, if ::sa exists, // clang will use it instead. return sa; // expected-error {{use of undeclared identifier 'sa'}} } }; }; template struct D<A>; } namespace PR19233 { template <class T> struct A : T { void foo() { ::undef(); // expected-error {{no member named 'undef' in the global namespace}} } void bar() { ::UndefClass::undef(); // expected-error {{no member named 'UndefClass' in the global namespace}} } void baz() { B::qux(); // expected-error {{use of undeclared identifier 'B'}} \ // expected-warning {{unqualified lookup into dependent bases of class template 'A'}} } }; struct B { void qux(); }; struct C : B { }; template struct A<C>; // No error! B is a base of A<C>, and qux is available. struct D { }; template struct A<D>; // expected-note {{in instantiation of member function 'PR19233::A<PR19233::D>::baz' requested here}} } namespace nonmethod_missing_this { template <typename T> struct Base { int y = 42; }; template <typename T> struct Derived : Base<T> { int x = y; // expected-warning {{lookup into dependent bases}} auto foo(int j) -> decltype(y * j) { // expected-warning {{lookup into dependent bases}} return y * j; // expected-warning {{lookup into dependent bases}} } int bar() { return [&] { return y; }(); // expected-warning {{lookup into dependent bases}} } }; template struct Derived<int>; } namespace typedef_in_base { template <typename T> struct A { typedef T NameFromBase; }; template <typename T> struct B : A<T> { NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}} }; static_assert(sizeof(B<int>) == 4, ""); } namespace struct_in_base { template <typename T> struct A { struct NameFromBase {}; }; template <typename T> struct B : A<T> { NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}} }; static_assert(sizeof(B<int>) == 1, ""); } namespace enum_in_base { template <typename T> struct A { enum NameFromBase { X }; }; template <typename T> struct B : A<T> { NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}} }; static_assert(sizeof(B<int>) == sizeof(A<int>::NameFromBase), ""); } namespace two_types_in_base { template <typename T> struct A { typedef T NameFromBase; }; // expected-note {{member found by ambiguous name lookup}} template <typename T> struct B { struct NameFromBase { T m; }; }; // expected-note {{member found by ambiguous name lookup}} template <typename T> struct C : A<T>, B<T> { NameFromBase m; // expected-error {{member 'NameFromBase' found in multiple base classes of different types}} expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} }; static_assert(sizeof(C<int>) == 4, ""); // expected-note {{in instantiation of template class 'two_types_in_base::C<int>' requested here}} } namespace type_and_decl_in_base { template <typename T> struct A { typedef T NameFromBase; }; template <typename T> struct B { static const T NameFromBase = 42; }; template <typename T> struct C : A<T>, B<T> { NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}} }; } namespace classify_type_from_base { template <typename T> struct A { struct NameFromBase {}; }; template <typename T> struct B : A<T> { A<NameFromBase> m; // expected-warning {{found via unqualified lookup into dependent bases}} }; } namespace classify_nontype_from_base { // MSVC does not do lookup of non-type declarations from dependent template base // classes. The extra lookup only applies to types. template <typename T> struct A { void NameFromBase() {} }; template <void (*F)()> struct B { }; template <typename T> struct C : A<T> { B<C::NameFromBase> a; // correct B<NameFromBase> b; // expected-error {{use of undeclared identifier 'NameFromBase'}} }; } namespace template_in_base { template <typename T> struct A { template <typename U> struct NameFromBase { U x; }; }; template <typename T> struct B : A<T> { // Correct form. typename B::template NameFromBase<T> m; }; template <typename T> struct C : A<T> { // Incorrect form. NameFromBase<T> m; // expected-error {{unknown type name 'NameFromBase'}} //expected-error@-1 {{expected member name or ';' after declaration specifiers}} }; } namespace type_in_inner_class_in_base { template <typename T> struct A { struct B { typedef T NameFromBase; }; }; template <typename T> struct C : A<T>::B { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}} } namespace type_in_inner_template_class_in_base { template <typename T> struct A { template <typename U> struct B { typedef U InnerType; }; }; template <typename T> struct C : A<T>::template B<T> { NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}} }; } namespace have_nondependent_base { template <typename T> struct A { // Nothing, lookup should fail. }; template <typename T> struct B : A<T> { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}} struct C : A<int> { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}} } namespace type_in_base_of_dependent_base { struct A { typedef int NameFromBase; }; template <typename T> struct B : A {}; template <typename T> struct C : B<T> { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } namespace type_in_second_dependent_base { template <typename T> struct A {}; template<typename T> struct B { typedef T NameFromBase; }; template <typename T> struct D : A<T>, B<T> { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } namespace type_in_second_non_dependent_base { struct A {}; struct B { typedef int NameFromBase; }; template<typename T> struct C : A, B {}; template <typename T> struct D : C<T> { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } namespace type_in_virtual_base_of_dependent_base { template <typename T> struct A { typedef T NameFromBase; }; template <typename T> struct B : virtual A<T> {}; template <typename T> struct C : B<T>, virtual A<T> { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} C<int> c; } namespace type_in_base_of_multiple_dependent_bases { template <typename T> struct A { typedef T NameFromBase; }; template <typename T> struct B : public A<T> {}; template <typename T> struct C : B<T>, public A<T> { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} expected-warning {{direct base 'A<int>' is inaccessible due to ambiguity:}} C<int> c; // expected-note {{in instantiation of template class 'type_in_base_of_multiple_dependent_bases::C<int>' requested here}} } namespace type_in_dependent_base_of_non_dependent_type { template<typename T> struct A { typedef int NameFromBase; }; template<typename T> struct B : A<T> { struct C; template<typename TT> struct D : C { NameFromBase m; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} }; struct E : C { NameFromBase m; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} }; }; template<typename T> struct B<T>::C : B { NameFromBase m; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} }; template<typename T> struct F : B<T>::C { NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}} }; } namespace lookup_in_function_contexts { template <typename T> struct A { typedef T NameFromBase; }; template <typename T> struct B : A<T> { // expected-warning@+1 {{lookup into dependent bases}} static auto lateSpecifiedFunc() -> decltype(NameFromBase()) { return {}; } static void memberFunc() { NameFromBase x; // expected-warning {{lookup into dependent bases}} } static void funcLocalClass() { struct X { NameFromBase x; // expected-warning {{lookup into dependent bases}} } y; } void localClassMethod() { struct X { void bar() { NameFromBase m; // expected-warning {{lookup into dependent bases}} } } x; x.bar(); } static void funcLambda() { auto l = []() { NameFromBase x; // expected-warning {{lookup into dependent bases}} }; l(); } static constexpr int constexprFunc() { NameFromBase x = {}; // expected-warning {{lookup into dependent bases}} return sizeof(x); } static auto autoFunc() { NameFromBase x; // expected-warning {{lookup into dependent bases}} return x; } }; // Force us to parse the methods. template struct B<int>; } namespace function_template_deduction { // Overloaded function templates. template <int N> int f() { return N; } template <typename T> int f() { return sizeof(T); } // Dependent base class with type. template <typename T> struct A { typedef T NameFromBase; }; template <typename T> struct B : A<T> { // expected-warning@+1 {{found via unqualified lookup into dependent bases}} int x = f<NameFromBase>(); }; // Dependent base class with enum. template <typename T> struct C { enum { NameFromBase = 4 }; }; template <typename T> struct D : C<T> { // expected-warning@+1 {{use of undeclared identifier 'NameFromBase'; unqualified lookup into dependent bases}} int x = f<NameFromBase>(); }; } namespace function_template_undef_impl { template<class T> void f() { Undef::staticMethod(); // expected-error {{use of undeclared identifier 'Undef'}} UndefVar.method(); // expected-error {{use of undeclared identifier 'UndefVar'}} } } namespace PR20716 { template <template <typename T> class A> struct B : A<int> { XXX x; // expected-error {{unknown type name}} }; template <typename T> struct C {}; template <typename T> using D = C<T>; template <typename T> struct E : D<T> { XXX x; // expected-error {{unknown type name}} }; } namespace PR23810 { void f(int); struct Base { void f(); // expected-note{{must qualify identifier to find this declaration in dependent base class}} }; template <typename T> struct Template : T { void member() { f(); // expected-warning {{found via unqualified lookup into dependent bases}} } }; void test() { Template<Base> x; x.member(); // expected-note{{requested here}} }; } namespace PR23823 { // Don't delay lookup in SFINAE context. template <typename T> decltype(g(T())) check(); // expected-note{{candidate template ignored: substitution failure [with T = int]: use of undeclared identifier 'g'}} decltype(check<int>()) x; // expected-error{{no matching function for call to 'check'}} void h(); template <typename T> decltype(h(T())) check2(); // expected-note{{candidate template ignored: substitution failure [with T = int]: no matching function for call to 'h'}} decltype(check2<int>()) y; // expected-error{{no matching function for call to 'check2'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-base-classes.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T, typename U> struct X0 : T::template apply<U> { X0(U u) : T::template apply<U>(u) { } }; template<typename T, typename U> struct X1 : T::apply<U> { }; // expected-error{{use 'template' keyword to treat 'apply' as a dependent template name}} template<typename T> struct X2 : vector<T> { }; // expected-error{{unknown template name 'vector'}} namespace PR6031 { template<typename T> struct A; template <class X> struct C { }; template <class TT> struct II { typedef typename A<TT>::type type; }; template <class TT> struct FI : II<TT> { C<typename FI::type> a; }; template <class TT> struct FI2 { C<typename FI2::type> a; // expected-error{{no type named 'type' in 'FI2<TT>'}} }; template<typename T> struct Base { class Nested { }; template<typename U> struct MemberTemplate { }; int a; }; template<typename T> struct HasDepBase : Base<T> { int foo() { class HasDepBase::Nested nested; typedef typename HasDepBase::template MemberTemplate<T>::type type; return HasDepBase::a; } }; template<typename T> struct NoDepBase { int foo() { class NoDepBase::Nested nested; // expected-error{{no class named 'Nested' in 'NoDepBase<T>'}} typedef typename NoDepBase::template MemberTemplate<T>::type type; // expected-error{{'MemberTemplate' following the 'template' keyword does not refer to a template}} \ // FIXME: expected-error{{unqualified-id}} return NoDepBase::a; // expected-error{{no member named 'a' in 'NoDepBase<T>'}} } }; } namespace Ambig { template<typename T> struct Base1 { typedef int type; // expected-note{{member found by ambiguous name lookup}} }; struct Base2 { typedef float type; // expected-note{{member found by ambiguous name lookup}} }; template<typename T> struct Derived : Base1<T>, Base2 { typedef typename Derived::type type; // expected-error{{member 'type' found in multiple base classes of different types}} type *foo(float *fp) { return fp; } }; Derived<int> di; // expected-note{{instantiation of}} } namespace PR6081 { template<typename T> struct A { }; template<typename T> class B : public A<T> { public: template< class X > void f0(const X & k) { this->template f1<int>()(k); } }; template<typename T> class C { public: template< class X > void f0(const X & k) { this->template f1<int>()(k); // expected-error{{'f1' following the 'template' keyword does not refer to a template}} \ // FIXME: expected-error{{unqualified-id}} \ // expected-error{{function-style cast or type construction}} \ // expected-error{{expected expression}} } }; } namespace PR6413 { template <typename T> class Base_A { }; class Base_B { }; template <typename T> class Derived : public virtual Base_A<T> , public virtual Base_B { }; } namespace PR5812 { template <class T> struct Base { Base* p; }; template <class T> struct Derived: public Base<T> { typename Derived::Base* p; // meaning Derived::Base<T> }; Derived<int> di; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/resolve-single-template-id.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s namespace std { class type_info {}; } void one() { } void two() { } // expected-note 4{{possible target for call}} void two(int) { } // expected-note 4{{possible target for call}} template<class T> void twoT() { } // expected-note 5{{possible target for call}} template<class T> void twoT(int) { } // expected-note 5{{possible target for call}} template<class T> void oneT() { } template<class T, class U> void oneT(U) { } /* The target can be an object or reference being initialized (8.5, 8.5.3), the left side of an assignment (5.17), a parameter of a function (5.2.2), a parameter of a user-defined operator (13.5), the return value of a function, operator function, or conversion (6.6.3), an explicit type conversion (5.2.3, 5.2.9, 5.4), or a non-type template-parameter (14.3.2) */ //#include <typeinfo> template<void (*p)(int)> struct test { }; int main() { one; // expected-warning {{expression result unused}} two; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} oneT<int>; // expected-warning {{expression result unused}} twoT<int>; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} typeid(oneT<int>); // expected-warning{{expression result unused}} sizeof(oneT<int>); // expected-error {{invalid application of 'sizeof' to a function type}} sizeof(twoT<int>); //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} decltype(oneT<int>)* fun = 0; *one; // expected-warning {{expression result unused}} *oneT<int>; // expected-warning {{expression result unused}} *two; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{indirection requires pointer operand}} *twoT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} !oneT<int>; // expected-warning {{expression result unused}} expected-warning {{address of function 'oneT<int>' will always evaluate to 'true'}} expected-note {{prefix with the address-of operator to silence this warning}} +oneT<int>; // expected-warning {{expression result unused}} -oneT<int>; //expected-error {{invalid argument type}} oneT<int> == 0; // expected-warning {{equality comparison result unused}} \ // expected-note {{use '=' to turn this equality comparison into an assignment}} \ // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \ // expected-note {{prefix with the address-of operator to silence this warning}} 0 == oneT<int>; // expected-warning {{equality comparison result unused}} \ // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \ // expected-note {{prefix with the address-of operator to silence this warning}} 0 != oneT<int>; // expected-warning {{inequality comparison result unused}} \ // expected-warning {{comparison of function 'oneT<int>' not equal to a null pointer is always true}} \ // expected-note {{prefix with the address-of operator to silence this warning}} (false ? one : oneT<int>); // expected-warning {{expression result unused}} void (*p1)(int); p1 = oneT<int>; int i = (int) (false ? (void (*)(int))twoT<int> : oneT<int>); //expected-error {{incompatible operand}} (twoT<int>) == oneT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}} bool b = oneT<int>; // expected-warning {{address of function 'oneT<int>' will always evaluate to 'true'}} expected-note {{prefix with the address-of operator to silence this warning}} void (*p)() = oneT<int>; test<oneT<int> > ti; void (*u)(int) = oneT<int>; b = (void (*)()) twoT<int>; one < one; //expected-warning {{self-comparison always evaluates to false}} \ //expected-warning {{relational comparison result unused}} oneT<int> < oneT<int>; //expected-warning {{self-comparison always evaluates to false}} \ //expected-warning {{relational comparison result unused}} two < two; //expected-error 2 {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{invalid operands to binary expression ('void' and 'void')}} twoT<int> < twoT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}} oneT<int> == 0; // expected-warning {{equality comparison result unused}} \ // expected-note {{use '=' to turn this equality comparison into an assignment}} \ // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \ // expected-note {{prefix with the address-of operator to silence this warning}} } struct rdar9108698 { template<typename> void f(); // expected-note{{possible target for call}} }; void test_rdar9108698(rdar9108698 x) { x.f<int>; // expected-error{{reference to non-static member function must be called}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/canonical-expr-type-0x.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s void f(); // Test typeof(expr) canonicalization template<typename T, T N> void f0(T x, decltype(f(N, x)) y) { } // expected-note{{previous}} template<typename T, T N> void f0(T x, decltype((f)(N, x)) y) { } template<typename U, U M> void f0(U u, decltype(f(M, u))) { } // expected-error{{redefinition}} // PR12438: Test sizeof...() canonicalization template<int> struct N {}; template<typename...T> N<sizeof...(T)> f1() {} // expected-note{{previous}} template<typename, typename...T> N<sizeof...(T)> f1() {} template<class...U> N<sizeof...(U)> f1() {} // expected-error{{redefinition}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/metafun-apply.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct add_pointer { template<typename T> struct apply { typedef T* type; }; }; struct add_reference { template<typename T> struct apply { typedef T& type; // expected-error{{cannot form a reference to 'void'}} }; }; struct bogus { struct apply { typedef int type; }; }; template<typename MetaFun, typename T> struct apply1 { typedef typename MetaFun::template apply<T>::type type; // expected-note{{in instantiation of template class 'add_reference::apply<void>' requested here}} \ // expected-error{{'apply' following the 'template' keyword does not refer to a template}} }; int i; apply1<add_pointer, int>::type ip = &i; apply1<add_reference, int>::type ir = i; apply1<add_reference, float>::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}} void test() { apply1<add_reference, void>::type t; // expected-note{{in instantiation of template class 'apply1<add_reference, void>' requested here}} apply1<bogus, int>::type t2; // expected-note{{in instantiation of template class 'apply1<bogus, int>' requested here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/recursive-template-instantiation.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> void f(T* t) { // expected-note{{could not match 'T *' against 'int'}} f(*t); // expected-error{{no matching function}}\ // expected-note 3{{requested here}} } void test_f(int ****p) { f(p); // expected-note{{requested here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/unresolved-construct.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // expected-no-diagnostics class A { public: A() {} template <class _F> explicit A(_F&& __f); A(A&&) {} A& operator=(A&&) {return *this;} }; template <class T> void f(T t) { A a; a = f(t); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-template-recover.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T, typename U, int N> struct X { void f(T* t) { t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}} t->f0<int>(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}} t->operator+<U const, 1>(); // expected-error{{use 'template' keyword to treat 'operator +' as a dependent template name}} t->f1<int const, 2>(); // expected-error{{use 'template' keyword to treat 'f1' as a dependent template name}} T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}} t->T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}} // FIXME: We can't recover from these yet (*t).f2<N>(); // expected-error{{expected expression}} (*t).f2<0>(); // expected-error{{expected expression}} } }; namespace PR9401 { // From GCC PR c++/45558 template <typename S, typename T> struct C { template <typename U> struct B { template <typename W> struct E { explicit E(const W &x) : w(x) {} const W &w; }; }; }; struct F; template <typename X> struct D { D() {} }; const D<F> g; template <typename S, typename T> struct A { template <typename U> struct B : C<S, T>::template B<U> { typedef typename C<S, T>::template B<U> V; static const D<typename V::template E<D<F> > > a; }; }; template <typename S, typename T> template <typename U> const D<typename C<S, T>::template B<U>::template E<D<F> > > A<S, T>::B<U>::a = typename C<S, T>::template B<U>::template E<D<F> >(g); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/delegating-constructors.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify namespace PR10457 { class string { string(const char* str, unsigned); public: template <unsigned N> string(const char (&str)[N]) : string(str) {} // expected-error{{constructor for 'string<6>' creates a delegation cycle}} }; void f() { string s("hello"); } struct Foo { Foo(int) { } template <typename T> Foo(T, int i) : Foo(i) { } }; void test_Foo() { Foo f(1, 1); } } namespace PR12890 { class Document { public: Document() = default; template <class T> explicit Document(T&& t) : Document() { } }; void f() { Document d(1); } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-expr-1.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-pc-linux-gnu template<int I, int J> struct Bitfields { int simple : I; // expected-error{{bit-field 'simple' has zero width}} int parens : (J); }; void test_Bitfields(Bitfields<0, 5> *b) { (void)sizeof(Bitfields<10, 5>); (void)sizeof(Bitfields<0, 1>); // expected-note{{in instantiation of template class 'Bitfields<0, 1>' requested here}} } template<int I, int J> struct BitfieldPlus { int bitfield : I + J; // expected-error{{bit-field 'bitfield' has zero width}} }; void test_BitfieldPlus() { (void)sizeof(BitfieldPlus<0, 1>); (void)sizeof(BitfieldPlus<-5, 5>); // expected-note{{in instantiation of template class 'BitfieldPlus<-5, 5>' requested here}} } template<int I, int J> struct BitfieldMinus { int bitfield : I - J; // expected-error{{bit-field 'bitfield' has negative width (-1)}} \ // expected-error{{bit-field 'bitfield' has zero width}} }; void test_BitfieldMinus() { (void)sizeof(BitfieldMinus<5, 1>); (void)sizeof(BitfieldMinus<0, 1>); // expected-note{{in instantiation of template class 'BitfieldMinus<0, 1>' requested here}} (void)sizeof(BitfieldMinus<5, 5>); // expected-note{{in instantiation of template class 'BitfieldMinus<5, 5>' requested here}} } template<int I, int J> struct BitfieldDivide { int bitfield : I / J; // expected-error{{expression is not an integral constant expression}} \ // expected-note{{division by zero}} }; void test_BitfieldDivide() { (void)sizeof(BitfieldDivide<5, 1>); (void)sizeof(BitfieldDivide<5, 0>); // expected-note{{in instantiation of template class 'BitfieldDivide<5, 0>' requested here}} } template<typename T, T I, int J> struct BitfieldDep { int bitfield : I + J; }; void test_BitfieldDep() { (void)sizeof(BitfieldDep<int, 1, 5>); } template<int I> struct BitfieldNeg { int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}} }; template<typename T, T I> struct BitfieldNeg2 { int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}} }; void test_BitfieldNeg() { (void)sizeof(BitfieldNeg<-5>); // okay (void)sizeof(BitfieldNeg<5>); // expected-note{{in instantiation of template class 'BitfieldNeg<5>' requested here}} (void)sizeof(BitfieldNeg2<int, -5>); // okay (void)sizeof(BitfieldNeg2<int, 5>); // expected-note{{in instantiation of template class 'BitfieldNeg2<int, 5>' requested here}} } template<typename T> void increment(T &x) { (void)++x; } struct Incrementable { Incrementable &operator++(); }; void test_increment(Incrementable inc) { increment(inc); } template<typename T> void add(const T &x) { (void)(x + x); } namespace PR6237 { template <typename T> void f(T t) { t++; } struct B { }; B operator++(B &, int); template void f(B); } struct Addable { Addable operator+(const Addable&) const; }; void test_add(Addable &a) { add(a); } struct CallOperator { int &operator()(int); double &operator()(double); }; template<typename Result, typename F, typename Arg1> Result test_call_operator(F f, Arg1 arg1) { // PR5266: non-dependent invocations of a function call operator. CallOperator call_op; int &ir = call_op(17); return f(arg1); } void test_call_operator(CallOperator call_op, int i, double d) { int &ir = test_call_operator<int&>(call_op, i); double &dr = test_call_operator<double&>(call_op, d); } template<typename T> void test_asm(T t) { asm ("nop" : "=r"(*t) : "r"(*t)); // expected-error {{indirection requires pointer operand ('int' invalid)}} } void test_asm() { int* a; test_asm(a); int b; test_asm(b); // expected-note {{in instantiation of function template specialization 'test_asm<int>' requested here}} } namespace PR6424 { template<int I> struct X { X() { int *ip = I; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} } }; template<int> struct Y { typedef X<7> X7; void f() { X7(); } // expected-note{{instantiation}} }; template void Y<3>::f(); template<int I> struct X2 { void *operator new(__SIZE_TYPE__) { int *ip = I; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} return ip; } }; template<int> struct Y2 { typedef X2<7> X; void f() { new X(); // expected-note{{instantiation of}} } }; template void Y2<3>::f(); template<typename T> void rdar10283928(int count) { (void)new char[count](); } template void rdar10283928<int>(int); } namespace PR10864 { template<typename T> class Vals {}; template<> class Vals<int> { public: static const int i = 1; }; template<> class Vals<float> { public: static const double i; }; template<typename T> void test_asm_tied(T o) { __asm("addl $1, %0" : "=r" (o) : "0"(Vals<T>::i)); // expected-error {{input with type 'double' matching output with type 'float'}} } void test_asm_tied() { test_asm_tied(1); test_asm_tied(1.f); // expected-note {{instantiation of}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/fibonacci.cpp
// RUN: %clang_cc1 -fsyntax-only %s template<unsigned I> struct FibonacciEval; template<unsigned I> struct Fibonacci { enum { value = FibonacciEval<I-1>::value + FibonacciEval<I-2>::value }; }; template<unsigned I> struct FibonacciEval { enum { value = Fibonacci<I>::value }; }; template<> struct Fibonacci<0> { enum { value = 0 }; }; template<> struct Fibonacci<1> { enum { value = 1 }; }; int array5[Fibonacci<5>::value == 5? 1 : -1]; int array10[Fibonacci<10>::value == 55? 1 : -1]; template<unsigned I> struct FibonacciEval2; template<unsigned I> struct Fibonacci2 { static const unsigned value = FibonacciEval2<I-1>::value + FibonacciEval2<I-2>::value; }; template<unsigned I> struct FibonacciEval2 { static const unsigned value = Fibonacci2<I>::value; }; template<> struct Fibonacci2<0> { static const unsigned value = 0; }; template<> struct Fibonacci2<1> { static const unsigned value = 1; }; int array5_2[Fibonacci2<5>::value == 5? 1 : -1]; int array10_2[Fibonacci2<10>::value == 55? 1 : -1]; template<unsigned I> struct Fibonacci3 { static const unsigned value = Fibonacci3<I-1>::value + Fibonacci3<I-2>::value; }; template<> struct Fibonacci3<0> { static const unsigned value = 0; }; template<> struct Fibonacci3<1> { static const unsigned value = 1; }; int array5_3[Fibonacci3<5>::value == 5? 1 : -1]; int array10_3[Fibonacci3<10>::value == 55? 1 : -1];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/overload-candidates.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> const T& min(const T&, const T&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}} void test_min() { (void)min(1, 2l); // expected-error{{no matching function for call to 'min'}} } template<typename R, typename T> R *dyn_cast(const T&); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}} void test_dyn_cast(int* ptr) { (void)dyn_cast(ptr); // expected-error{{no matching function for call to 'dyn_cast'}} } template<int I, typename T> void get(const T&); // expected-note{{candidate template ignored: invalid explicitly-specified argument for template parameter 'I'}} template<template<class T> class, typename T> void get(const T&); // expected-note{{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}} void test_get(void *ptr) { get<int>(ptr); // expected-error{{no matching function for call to 'get'}} } template<typename T> typename T::type get_type(const T&); // expected-note{{candidate template ignored: substitution failure [with T = int *]: type 'int *' cannot be used prior to '::'}} template<typename T> void get_type(T *, int[(int)sizeof(T) - 9] = 0); // expected-note{{candidate template ignored: substitution failure [with T = int]: array size is negative}} void test_get_type(int *ptr) { (void)get_type(ptr); // expected-error{{no matching function for call to 'get_type'}} } struct X { template<typename T> const T& min(const T&, const T&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}} }; void test_X_min(X x) { (void)x.min(1, 2l); // expected-error{{no matching member function for call to 'min'}} } namespace boost { template<bool, typename = void> struct enable_if {}; template<typename T> struct enable_if<true, T> { typedef T type; }; } template<typename T> typename boost::enable_if<sizeof(T) == 4, int>::type if_size_4(); // expected-note{{candidate template ignored: disabled by 'enable_if' [with T = char]}} int k = if_size_4<char>(); // expected-error{{no matching function}} namespace llvm { template<typename Cond, typename T = void> struct enable_if : boost::enable_if<Cond::value, T> {}; } template<typename T> struct is_int { enum { value = false }; }; template<> struct is_int<int> { enum { value = true }; }; template<typename T> typename llvm::enable_if<is_int<T> >::type if_int(); // expected-note{{candidate template ignored: disabled by 'enable_if' [with T = char]}} void test_if_int() { if_int<char>(); // expected-error{{no matching function}} } template<typename T> struct NonTemplateFunction { typename boost::enable_if<sizeof(T) == 4, int>::type f(); // expected-error{{no type named 'type' in 'boost::enable_if<false, int>'; 'enable_if' cannot be used to disable this declaration}} }; NonTemplateFunction<char> NTFC; // expected-note{{here}} namespace NS1 { template <class A> class array {}; } namespace NS2 { template <class A> class array {}; } template <class A> void foo(NS2::array<A>); // expected-note{{candidate template ignored: could not match 'NS2::array' against 'NS1::array'}} void test() { foo(NS1::array<int>()); // expected-error{{no matching function for call to 'foo'}} } namespace std { template<bool, typename = void> struct enable_if {}; template<typename T> struct enable_if<true, T> { typedef T type; }; template<typename T, T V> struct integral_constant { static const T value = V; }; typedef integral_constant<bool, false> false_type; typedef integral_constant<bool, true> true_type; }; namespace PR15673 { template<typename T> struct a_trait : std::false_type {}; template<typename T, typename Requires = typename std::enable_if<a_trait<T>::value>::type> // expected-warning {{C++11 extension}} // expected-note@-1 {{candidate template ignored: disabled by 'enable_if' [with T = int]}} void foo() {} void bar() { foo<int>(); } // expected-error {{no matching function for call to 'foo'}} template<typename T> struct some_trait : std::false_type {}; // FIXME: It would be nice to tunnel the 'disabled by enable_if' diagnostic through here. template<typename T> struct a_pony : std::enable_if<some_trait<T>::value> {}; template<typename T, typename Requires = typename a_pony<T>::type> // expected-warning {{C++11 extension}} // FIXME: The source location here is poor. void baz() { } // expected-note {{candidate template ignored: substitution failure [with T = int]: no type named 'type' in 'PR15673::a_pony<int>'}} void quux() { baz<int>(); } // expected-error {{no matching function for call to 'baz'}} // FIXME: This note doesn't make it clear which candidate we rejected. template <typename T> using unicorns = typename std::enable_if<some_trait<T>::value>::type; // expected-warning {{C++11 extension}} // expected-note@-1 {{candidate template ignored: disabled by 'enable_if' [with T = int]}} template<typename T, typename Requires = unicorns<T> > // expected-warning {{C++11 extension}} void wibble() {} void wobble() { wibble<int>(); } // expected-error {{no matching function for call to 'wibble'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-expr-5.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template <class A> int x(A x) { return x++; } int y() { return x<int>(1); } namespace PR5880 { template<typename T> struct A { static const int a = __builtin_offsetof(T, a.array[5].m); // expected-error{{no member named 'a' in 'HasM'}} }; struct HasM { float m; }; struct ArrayOfHasM { HasM array[10]; }; struct B { ArrayOfHasM a; }; A<B> x; A<HasM> x2; // expected-note{{in instantiation of}} template<typename T> struct AnonymousUnion { union { int i; float f; }; }; template<typename T> void test_anon_union() { int array1[__builtin_offsetof(AnonymousUnion<T>, f) == 0? 1 : -1]; int array2[__builtin_offsetof(AnonymousUnion<int>, f) == 0? 1 : -1]; } template void test_anon_union<int>(); } namespace AddrOfClassMember { template <typename T> struct S { int n; static void f() { +T::n; // expected-error {{invalid use of member}} } }; void g() { S<S<int> >::f(); } // expected-note {{in instantiation of}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-member-template.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> struct X0 { template<typename U> T f0(U); template<typename U> U& f1(T*, U); // expected-error{{pointer to a reference}} \ // expected-note{{candidate}} }; X0<int> x0i; X0<void> x0v; X0<int&> x0ir; // expected-note{{instantiation}} void test_X0(int *ip, double *dp) { X0<int> xi; int i1 = xi.f0(ip); double *&dpr = xi.f1(ip, dp); xi.f1(dp, dp); // expected-error{{no matching}} X0<void> xv; double *&dpr2 = xv.f1(ip, dp); } template<typename T> struct X1 { template<typename U> struct Inner0 { U x; T y; // expected-error{{void}} }; template<typename U> struct Inner1 { U x; // expected-error{{void}} T y; }; template<typename U> struct Inner2 { struct SuperInner { U z; // expected-error{{void}} }; }; template<typename U> struct Inner3 { void f0(T t, U u) { // expected-note{{passing argument to parameter 't' here}} (void)(t + u); // expected-error{{invalid operands}} } template<typename V> V f1(T t, U u, V) { return t + u; // expected-error{{cannot initialize return object}} } }; template<typename U> struct Inner4; }; template<typename T> template<typename U> struct X1<T>::Inner4 { template<typename V> V f2(T t, U u, V); static U value; }; template<typename T> template<typename U> U X1<T>::Inner4<U>::value; // expected-error{{reference variable}} template<typename T> template<typename U> template<typename V> V X1<T>::Inner4<U>::f2(T t, U u, V) { return t + u; // expected-error{{cannot initialize return object}} } void test_X1(int *ip, int i, double *dp) { X1<void>::Inner0<int> *xvip; // okay X1<void>::Inner0<int> xvi; // expected-note{{instantiation}} X1<int>::Inner1<void> *xivp; // okay X1<int>::Inner1<void> xiv; // expected-note{{instantiation}} X1<int>::Inner2<void>::SuperInner *xisivp; // okay X1<int>::Inner2<void>::SuperInner xisiv; // expected-note{{instantiation}} X1<int*>::Inner3<int> id3; id3.f0(ip, i); id3.f0(dp, i); // expected-error{{cannot initialize a parameter of type 'int *' with an lvalue of type 'double *'}} id3.f1(ip, i, ip); id3.f1(ip, i, dp); // expected-note{{instantiation}} X1<int*>::Inner3<double*> id3b; id3b.f0(ip, dp); // expected-note{{instantiation}} X1<int*>::Inner4<int> id4; id4.f2(ip, i, dp); // expected-note{{instantiation}} X1<int*>::Inner4<int>::value = 17; i = X1<int*>::Inner4<int&>::value; // expected-note{{instantiation}} } template<typename T> struct X2 { template<T *Ptr> // expected-error{{pointer to a reference}} struct Inner; template<T Value> // expected-error{{cannot have type 'float'}} struct Inner2; }; X2<int&> x2a; // expected-note{{instantiation}} X2<float> x2b; // expected-note{{instantiation}} namespace N0 { template<typename T> struct X0 { }; struct X1 { template<typename T> void f(X0<T>& vals) { g(vals); } template<typename T> void g(X0<T>& vals) { } }; void test(X1 x1, X0<int> x0i, X0<long> x0l) { x1.f(x0i); x1.f(x0l); } } namespace PR6239 { template <typename T> struct X0 { class type { typedef T E; template <E e> // subsitute T for E and bug goes away struct sfinae { }; template <class U> typename sfinae<&U::operator=>::type test(int); }; }; template <typename T> struct X1 { typedef T E; template <E e> // subsitute T for E and bug goes away struct sfinae { }; template <class U> typename sfinae<&U::operator=>::type test(int); }; } namespace PR7587 { template<typename> class X0; template<typename> struct X1; template<typename> class X2; template<typename T> class X3 { template< template<typename> class TT, typename U = typename X1<T>::type > struct Inner { typedef X2<TT<typename X1<T>::type> > Type; }; const typename Inner<X0>::Type minCoeff() const; }; template<typename T> class X3<T*> { template< template<typename> class TT, typename U = typename X1<T>::type > struct Inner { typedef X2<TT<typename X1<T>::type> > Type; }; const typename Inner<X0>::Type minCoeff() const; }; } namespace PR7669 { template<class> struct X { template<class> struct Y { template<int,class> struct Z; template<int Dummy> struct Z<Dummy,int> {}; }; }; void a() { X<int>::Y<int>::Z<0,int>(); } } namespace PR8489 { template <typename CT> class C { template<typename FT> void F() {} // expected-note{{FT}} }; void f() { C<int> c; c.F(); // expected-error{{no matching member function}} } } namespace rdar8986308 { template <bool> struct __static_assert_test; template <> struct __static_assert_test<true> {}; template <unsigned> struct __static_assert_check {}; namespace std { template <class _Tp, class _Up> struct __has_rebind { private: struct __two {char _; char __;}; template <class _Xp> static __two __test(...); template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0); public: static const bool value = sizeof(__test<_Tp>(0)) == 1; }; } template <class T> struct B1 {}; template <class T> struct B { template <class U> struct rebind {typedef B1<U> other;}; }; template <class T, class U> struct D1 {}; template <class T, class U> struct D { template <class V> struct rebind {typedef D1<V, U> other;}; }; int main() { typedef __static_assert_check<sizeof(__static_assert_test<((std::__has_rebind<B<int>, double>::value))>)> __t64; typedef __static_assert_check<sizeof(__static_assert_test<((std::__has_rebind<D<char, int>, double>::value))>)> __t64; } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/current-instantiation.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // This test concerns the identity of dependent types within the // canonical type system, specifically focusing on the difference // between members of the current instantiation and members of an // unknown specialization. This considers C++ [temp.type], which // specifies type equivalence within a template, and C++0x // [temp.dep.type], which defines what it means to be a member of the // current instantiation. template<typename T, typename U> struct X0 { typedef T T_type; typedef U U_type; void f0(T&); // expected-note{{previous}} void f0(typename X0::U_type&); void f0(typename X0::T_type&); // expected-error{{redecl}} void f1(T&); // expected-note{{previous}} void f1(typename X0::U_type&); void f1(typename X0<T, U>::T_type&); // expected-error{{redecl}} void f2(T&); // expected-note{{previous}} void f2(typename X0::U_type&); void f2(typename X0<T_type, U_type>::T_type&); // expected-error{{redecl}} void f3(T&); // expected-note{{previous}} void f3(typename X0::U_type&); void f3(typename ::X0<T_type, U_type>::T_type&); // expected-error{{redecl}} struct X1 { typedef T my_T_type; void g0(T&); // expected-note{{previous}} void g0(typename X0::U_type&); void g0(typename X0::T_type&); // expected-error{{redecl}} void g1(T&); // expected-note{{previous}} void g1(typename X0::U_type&); void g1(typename X0<T, U>::T_type&); // expected-error{{redecl}} void g2(T&); // expected-note{{previous}} void g2(typename X0::U_type&); void g2(typename X0<T_type, U_type>::T_type&); // expected-error{{redecl}} void g3(T&); // expected-note{{previous}} void g3(typename X0::U_type&); void g3(typename ::X0<T_type, U_type>::T_type&); // expected-error{{redecl}} void g4(T&); // expected-note{{previous}} void g4(typename X0::U_type&); void g4(typename X1::my_T_type&); // expected-error{{redecl}} void g5(T&); // expected-note{{previous}} void g5(typename X0::U_type&); void g5(typename X0::X1::my_T_type&); // expected-error{{redecl}} void g6(T&); // expected-note{{previous}} void g6(typename X0::U_type&); void g6(typename X0<T, U>::X1::my_T_type&); // expected-error{{redecl}} void g7(T&); // expected-note{{previous}} void g7(typename X0::U_type&); void g7(typename ::X0<typename X1::my_T_type, U_type>::X1::my_T_type&); // expected-error{{redecl}} void g8(T&); // expected-note{{previous}} void g8(typename X0<U, T_type>::T_type&); void g8(typename ::X0<typename X0<T_type, U>::X1::my_T_type, U_type>::X1::my_T_type&); // expected-error{{redecl}} }; }; template<typename T, typename U> struct X0<T*, U*> { typedef T T_type; typedef U U_type; typedef T* Tptr; typedef U* Uptr; void f0(T&); // expected-note{{previous}} void f0(typename X0::U_type&); void f0(typename X0::T_type&); // expected-error{{redecl}} void f1(T&); // expected-note{{previous}} void f1(typename X0::U_type&); void f1(typename X0<T*, U*>::T_type&); // expected-error{{redecl}} void f2(T&); // expected-note{{previous}} void f2(typename X0::U_type&); void f2(typename X0<T_type*, U_type*>::T_type&); // expected-error{{redecl}} void f3(T&); // expected-note{{previous}} void f3(typename X0::U_type&); void f3(typename ::X0<T_type*, U_type*>::T_type&); // expected-error{{redecl}} void f4(T&); // expected-note{{previous}} void f4(typename X0::U_type&); void f4(typename ::X0<Tptr, Uptr>::T_type&); // expected-error{{redecl}} void f5(X0*); // expected-note{{previous}} void f5(::X0<T, U>*); void f5(::X0<T*, U*>*); // expected-error{{redecl}} struct X2 { typedef T my_T_type; void g0(T&); // expected-note{{previous}} void g0(typename X0::U_type&); void g0(typename X0::T_type&); // expected-error{{redecl}} void g1(T&); // expected-note{{previous}} void g1(typename X0::U_type&); void g1(typename X0<T*, U*>::T_type&); // expected-error{{redecl}} void g2(T&); // expected-note{{previous}} void g2(typename X0::U_type&); void g2(typename X0<T_type*, U_type*>::T_type&); // expected-error{{redecl}} void g3(T&); // expected-note{{previous}} void g3(typename X0::U_type&); void g3(typename ::X0<T_type*, U_type*>::T_type&); // expected-error{{redecl}} void g4(T&); // expected-note{{previous}} void g4(typename X0::U_type&); void g4(typename X2::my_T_type&); // expected-error{{redecl}} void g5(T&); // expected-note{{previous}} void g5(typename X0::U_type&); void g5(typename X0::X2::my_T_type&); // expected-error{{redecl}} void g6(T&); // expected-note{{previous}} void g6(typename X0::U_type&); void g6(typename X0<T*, U*>::X2::my_T_type&); // expected-error{{redecl}} void g7(T&); // expected-note{{previous}} void g7(typename X0::U_type&); void g7(typename ::X0<typename X2::my_T_type*, U_type*>::X2::my_T_type&); // expected-error{{redecl}} void g8(T&); // expected-note{{previous}} void g8(typename X0<U, T_type>::T_type&); void g8(typename ::X0<typename X0<T_type*, U*>::X2::my_T_type*, U_type*>::X2::my_T_type&); // expected-error{{redecl}} }; }; template<typename T> struct X1 { static int *a; void f(float *b) { X1<T>::a = b; // expected-error{{incompatible}} X1<T*>::a = b; } }; namespace ConstantInCurrentInstantiation { template<typename T> struct X { static const int value = 2; static int array[value]; }; template<typename T> const int X<T>::value; template<typename T> int X<T>::array[X<T>::value] = { 1, 2 }; } namespace Expressions { template <bool b> struct Bool { enum anonymous_enum { value = b }; }; struct True : public Bool<true> {}; struct False : public Bool<false> {}; template <typename T1, typename T2> struct Is_Same : public False {}; template <typename T> struct Is_Same<T, T> : public True {}; template <bool b, typename T = void> struct Enable_If {}; template <typename T> struct Enable_If<true, T> { typedef T type; }; template <typename T> class Class { public: template <typename U> typename Enable_If<Is_Same<U, Class>::value, void>::type foo(); }; template <typename T> template <typename U> typename Enable_If<Is_Same<U, Class<T> >::value, void>::type Class<T>::foo() {} } namespace PR9255 { template<typename T> class X0 { public: class Inner1; class Inner2 { public: void f() { Inner1::f.g(); } }; }; } namespace rdar10194295 { template<typename XT> class X { public: enum Enum { Yes, No }; template<Enum> void foo(); template<Enum> class Inner; }; template<typename XT> template<typename X<XT>::Enum> void X<XT>::foo() { } template<typename XT> template<typename X<XT>::Enum> class X<XT>::Inner { }; } namespace RebuildDependentScopeDeclRefExpr { template<int> struct N {}; template<typename T> struct X { static const int thing = 0; N<thing> data(); N<thing> foo(); }; template<typename T> N<X<T>::thing> X<T>::data() {} // FIXME: We should issue a typo-correction here. template<typename T> N<X<T>::think> X<T>::foo() {} // expected-error {{no member named 'think' in 'X<T>'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ms-delayed-default-template-args.cpp
// RUN: %clang_cc1 -fms-compatibility -std=c++11 %s -verify // MSVC should compile this file without errors. namespace test_basic { template <typename T = Baz> // expected-warning {{using the undeclared type 'Baz' as a default template argument is a Microsoft extension}} struct Foo { T x; }; typedef int Baz; template struct Foo<>; } namespace test_namespace { namespace nested { template <typename T = Baz> // expected-warning {{using the undeclared type 'Baz' as a default template argument is a Microsoft extension}} struct Foo { static_assert(sizeof(T) == 4, "should get int, not double"); }; typedef int Baz; } typedef double Baz; template struct nested::Foo<>; } namespace test_inner_class_template { struct Outer { template <typename T = Baz> // expected-warning {{using the undeclared type 'Baz' as a default template argument is a Microsoft extension}} struct Foo { static_assert(sizeof(T) == 4, "should get int, not double"); }; typedef int Baz; }; typedef double Baz; template struct Outer::Foo<>; } namespace test_nontype_param { template <typename T> struct Bar { T x; }; typedef int Qux; template <Bar<Qux> *P> struct Foo { }; Bar<int> g; template struct Foo<&g>; } // MSVC accepts this, but Clang doesn't. namespace test_template_instantiation_arg { template <typename T> struct Bar { T x; }; template <typename T = Bar<Weber>> // expected-error {{use of undeclared identifier 'Weber'}} struct Foo { static_assert(sizeof(T) == 4, "Bar should have gotten int"); // FIXME: These diagnostics are bad. }; // expected-error {{expected ',' or '>' in template-parameter-list}} // expected-warning@-1 {{does not declare anything}} typedef int Weber; } #ifdef __clang__ // These are negative test cases that MSVC doesn't compile either. Try to use // unique undeclared identifiers so typo correction doesn't find types declared // above. namespace test_undeclared_nontype_parm_type { template <Zargon N> // expected-error {{unknown type name 'Zargon'}} struct Foo { int x[N]; }; typedef int Zargon; template struct Foo<4>; } namespace test_undeclared_nontype_parm_type_no_name { template <typename T, Asdf> // expected-error {{unknown type name 'Asdf'}} struct Foo { T x; }; template struct Foo<int, 0>; } namespace test_undeclared_type_arg { template <typename T> struct Foo { T x; }; template struct Foo<Yodel>; // expected-error {{use of undeclared identifier 'Yodel'}} } namespace test_undeclared_nontype_parm_arg { // Bury an undeclared type as a template argument to the type of a non-type // template parameter. template <typename T> struct Bar { T x; }; template <Bar<Xylophone> *P> // expected-error {{use of undeclared identifier 'Xylophone'}} // expected-note@-1 {{template parameter is declared here}} struct Foo { }; typedef int Xylophone; Bar<Xylophone> g; template struct Foo<&g>; // expected-error {{cannot be converted}} } #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/friend.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> struct A { struct B { }; friend struct B; }; void f() { A<int>::B b; } struct C0 { friend struct A<int>; }; namespace PR6770 { namespace N { int f1(int); } using namespace N; namespace M { float f1(float); } using M::f1; template<typename T> void f1(T, T); template <class T> void f() { friend class f; // expected-error{{'friend' used outside of class}} friend class f1; // expected-error{{'friend' used outside of class}} } } namespace friend_redecl_inline { // We had a bug where instantiating the foo friend declaration would check the // defined-ness of the most recent decl while checking if the canonical decl was // inlined. void foo(); void bar(); template <typename T> class C { friend void foo(); friend inline void bar(); }; inline void foo() {} inline void bar() {} C<int> c; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/elaborated-type-specifier.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace PR6915 { template <typename T> class D { enum T::X v; // expected-error{{use of 'X' with tag type that does not match previous declaration}} \ // expected-error{{no enum named 'X' in 'PR6915::D3'}} }; struct D1 { enum X { value }; }; struct D2 { class X { }; // expected-note{{previous use is here}} }; struct D3 { }; template class D<D1>; template class D<D2>; // expected-note{{in instantiation of}} template class D<D3>; // expected-note{{in instantiation of}} } template<typename T> struct DeclOrDef { enum T::foo; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}} enum T::bar { // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}} value }; }; namespace PR6649 { template <typename T> struct foo { class T::bar; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}} class T::bar { int x; }; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}} }; } namespace rdar8568507 { template <class T> struct A *makeA(T t); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/derived.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s template<typename T> class vector2 {}; template<typename T> class vector : vector2<T> {}; template<typename T> void Foo2(vector2<const T*> V) {} // expected-note{{candidate template ignored: can't deduce a type for 'T' that would make 'const T' equal 'int'}} template<typename T> void Foo(vector<const T*> V) {} // expected-note {{candidate template ignored: can't deduce a type for 'T' that would make 'const T' equal 'int'}} void test() { Foo2(vector2<int*>()); // expected-error{{no matching function for call to 'Foo2'}} Foo(vector<int*>()); // expected-error{{no matching function for call to 'Foo'}} } namespace rdar13267210 { template < typename T > class A { BaseTy; // expected-error{{C++ requires a type specifier for all declarations}} }; template < typename T, int N > class C: A < T > {}; class B { C<long, 16> ExternalDefinitions; C<long, 64> &Record; void AddSourceLocation(A<long> &R); // expected-note{{passing argument to parameter 'R' here}} void AddTemplateKWAndArgsInfo() { AddSourceLocation(Record); // expected-error{{non-const lvalue reference to type}} } }; } namespace PR16292 { class IncompleteClass; // expected-note{{forward declaration}} class BaseClass { IncompleteClass Foo; // expected-error{{field has incomplete type}} }; template<class T> class DerivedClass : public BaseClass {}; void* p = new DerivedClass<void>; } namespace rdar14183893 { class Typ { // expected-note {{not complete}} Typ x; // expected-error {{incomplete type}} }; template <unsigned C> class B : Typ {}; typedef B<0> TFP; class A { TFP m_p; void Enable() { 0, A(); } // expected-warning {{unused}} }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-default-assignment-operator.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename> struct PassRefPtr { }; template<typename T> struct RefPtr { RefPtr& operator=(const RefPtr&) { int a[sizeof(T) ? -1 : -1];} // expected-error 2 {{array with a negative size}} RefPtr& operator=(const PassRefPtr<T>&); }; struct A { RefPtr<int> a; }; // expected-note {{instantiation of member function 'RefPtr<int>::operator=' requested here}} struct B : RefPtr<float> { }; // expected-note {{in instantiation of member function 'RefPtr<float>::operator=' requested here}} void f() { A a1, a2; a1 = a2; B b1, b2; b1 = b2; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-sized_array.cpp
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s template<int N> void f() { int a[] = { 1, 2, 3, N }; unsigned numAs = sizeof(a) / sizeof(int); } template void f<17>(); template<int N> void f1() { int a0[] = {}; // expected-warning{{zero}} int a1[] = { 1, 2, 3, N }; int a3[sizeof(a1)/sizeof(int) != 4? 1 : -1]; // expected-error{{negative}} } namespace PR13788 { template <unsigned __N> struct S { int V; }; template <int N> void foo() { S<0> arr[N] = {{ 4 }}; } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-self.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s // Check that we deal with cases where the instantiation of a class template // recursively requires the instantiation of the same template. namespace test1 { template<typename T> struct A { struct B { // expected-note {{not complete until the closing '}'}} B b; // expected-error {{has incomplete type 'test1::A<int>::B'}} }; B b; // expected-note {{in instantiation of}} }; A<int> a; // expected-note {{in instantiation of}} } namespace test2 { template<typename T> struct A { struct B { struct C {}; char c[1 + C()]; // expected-error {{invalid operands to binary expression}} friend constexpr int operator+(int, C) { return 4; } }; B b; // expected-note {{in instantiation of}} }; A<int> a; // expected-note {{in instantiation of}} } namespace test3 { // PR12317 template<typename T> struct A { struct B { enum { Val = 1 }; char c[1 + Val]; // ok }; B b; }; A<int> a; } namespace test4 { template<typename T> struct M { typedef int type; }; template<typename T> struct A { struct B { // expected-note {{not complete until the closing '}'}} int k[typename A<typename M<T>::type>::B().k[0] + 1]; // expected-error {{incomplete type}} }; B b; // expected-note {{in instantiation of}} }; A<int> a; // expected-note {{in instantiation of}} } // FIXME: PR12298: Recursive constexpr function template instantiation leads to // stack overflow. #if 0 namespace test5 { template<typename T> struct A { constexpr T f(T k) { return g(k); } constexpr T g(T k) { return k ? f(k-1)+1 : 0; } }; // This should be accepted. constexpr int x = A<int>().f(5); } namespace test6 { template<typename T> constexpr T f(T); template<typename T> constexpr T g(T t) { typedef int arr[f(T())]; return t; } template<typename T> constexpr T f(T t) { typedef int arr[g(T())]; return t; } // This should be ill-formed. int n = f(0); } namespace test7 { template<typename T> constexpr T g(T t) { return t; } template<typename T> constexpr T f(T t) { typedef int arr[g(T())]; return t; } // This should be accepted. int n = f(0); } #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ms-class-specialization-duplicate.cpp
// RUN: %clang_cc1 -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify %s template <typename T> class A { }; typedef int TInt; template class A<int>; // expected-note {{previous explicit instantiation is here}} template class A<TInt>; // expected-warning {{duplicate explicit instantiation of 'A<int>' ignored as a Microsoft extension}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ext-vector-type.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T, unsigned Length> struct make1 { typedef T __attribute__((ext_vector_type(Length))) type; }; void test_make1() { make1<int, 5>::type x; x.x = 4; } template<typename T, unsigned Length> struct make2 { typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{zero vector size}} }; int test_make2() { make2<int, 0> x; // expected-note{{in instantiation of}} } template<typename T, unsigned Length> struct make3 { typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type 's'}} }; struct s {}; int test_make3() { make3<s, 3>x; // expected-note{{in instantiation of}} } template<typename T, T Length> struct make4 { typedef T __attribute__((ext_vector_type(Length))) type; }; int test_make4() { make4<int, 4>::type x; x.w = 7; } typedef int* int_ptr; template<unsigned Length> struct make5 { typedef int_ptr __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type}} }; template<int Length> struct make6 { typedef int __attribute__((ext_vector_type(Length))) type; }; int test_make6() { make6<4>::type x; x.w = 7; make6<2>::type y; y.x = -1; y.w = -1; // expected-error{{vector component access exceeds type}} } namespace Deduction { template<typename T> struct X0; template<typename T, unsigned N> struct X0<T __attribute__((ext_vector_type(N)))> { static const unsigned value = 0; }; template<typename T> struct X0<T __attribute__((ext_vector_type(4)))> { static const unsigned value = 1; }; template<unsigned N> struct X0<float __attribute__((ext_vector_type(N)))> { static const unsigned value = 2; }; template<> struct X0<float __attribute__((ext_vector_type(4)))> { static const unsigned value = 3; }; typedef int __attribute__((ext_vector_type(2))) int2; typedef int __attribute__((ext_vector_type(4))) int4; typedef float __attribute__((ext_vector_type(2))) float2; typedef float __attribute__((ext_vector_type(4))) float4; int array0[X0<int2>::value == 0? 1 : -1]; int array1[X0<int4>::value == 1? 1 : -1]; int array2[X0<float2>::value == 2? 1 : -1]; int array3[X0<float4>::value == 3? 1 : -1]; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-base-member-init.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // PR4381 template<class T> struct X {}; template<typename T> struct Y : public X<T>::X { }; // PR4621 class A1 { A1(int x) {} }; template<class C> class B1 : public A1 { B1(C x) : A1(x.x) {} }; class A2 { A2(int x, int y); }; template <class C> class B2 { A2 x; B2(C x) : x(x.x, x.y) {} }; template <class C> class B3 { C x; B3() : x(1,2) {} }; // PR4627 template<typename _Container> class insert_iterator { _Container* container; insert_iterator(_Container& __x) : container(&__x) {} }; // PR4763 template<typename T> struct s0 {}; template<typename T> struct s0_traits {}; template<typename T> struct s1 : s0<typename s0_traits<T>::t0> { s1() {} }; // PR6062 namespace PR6062 { template <typename T> class A : public T::type { A() : T::type() { } template <typename U> A(U const& init) : T::type(init) { } template<typename U> A(U& init) : U::other_type(init) { } }; } template<typename T, typename U> struct X0 : T::template apply<U> { X0(int i) : T::template apply<U>(i) { } }; // PR7698 namespace PR7698 { template<typename Type> class A { char mA[sizeof(Type *)]; A(): mA() {} }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_arg_nontype.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wconversion -verify %s template<int N> struct A; // expected-note 5{{template parameter is declared here}} A<0> *a0; A<int()> *a1; // expected-error{{template argument for non-type template parameter is treated as function type 'int ()'}} A<int> *a2; // expected-error{{template argument for non-type template parameter must be an expression}} A<1 >> 2> *a3; // expected-warning{{use of right-shift operator ('>>') in template argument will require parentheses in C++11}} // C++ [temp.arg.nontype]p5: A<A> *a4; // expected-error{{must be an expression}} enum E { Enumerator = 17 }; A<E> *a5; // expected-error{{template argument for non-type template parameter must be an expression}} template<E Value> struct A1; // expected-note{{template parameter is declared here}} A1<Enumerator> *a6; // okay A1<17> *a7; // expected-error{{non-type template argument of type 'int' cannot be converted to a value of type 'E'}} const long LongValue = 12345678; A<LongValue> *a8; const short ShortValue = 17; A<ShortValue> *a9; int f(int); A<f(17)> *a10; // expected-error{{non-type template argument of type 'int' is not an integral constant expression}} class X { public: X(); X(int, int); operator int() const; }; A<X(17, 42)> *a11; // expected-error{{non-type template argument of type 'X' must have an integral or enumeration type}} float f(float); float g(float); // expected-note 2{{candidate function}} double g(double); // expected-note 2{{candidate function}} int h(int); float h2(float); template<int fp(int)> struct A3; // expected-note 1{{template parameter is declared here}} A3<h> *a14_1; A3<&h> *a14_2; A3<f> *a14_3; A3<&f> *a14_4; A3<h2> *a14_6; // expected-error{{non-type template argument of type 'float (float)' cannot be converted to a value of type 'int (*)(int)'}} A3<g> *a14_7; // expected-error{{address of overloaded function 'g' does not match required type 'int (int)'}} struct Y { } y; volatile X * X_volatile_ptr; template<X const &AnX> struct A4; // expected-note 2{{template parameter is declared here}} X an_X; A4<an_X> *a15_1; // okay A4<*X_volatile_ptr> *a15_2; // expected-error{{non-type template argument does not refer to any declaration}} A4<y> *15_3; // expected-error{{non-type template parameter of reference type 'const X &' cannot bind to template argument of type 'struct Y'}} \ // FIXME: expected-error{{expected unqualified-id}} template<int (&fr)(int)> struct A5; // expected-note{{template parameter is declared here}} A5<h> *a16_1; A5<f> *a16_3; A5<h2> *a16_6; // expected-error{{non-type template parameter of reference type 'int (&)(int)' cannot bind to template argument of type 'float (float)'}} A5<g> *a14_7; // expected-error{{address of overloaded function 'g' does not match required type 'int (int)'}} struct Z { int foo(int); float bar(float); int bar(int); double baz(double); int int_member; float float_member; union { int union_member; }; }; template<int (Z::*pmf)(int)> struct A6; // expected-note{{template parameter is declared here}} A6<&Z::foo> *a17_1; A6<&Z::bar> *a17_2; A6<&Z::baz> *a17_3; // expected-error-re{{non-type template argument of type 'double (Z::*)(double){{( __attribute__\(\(thiscall\)\))?}}' cannot be converted to a value of type 'int (Z::*)(int){{( __attribute__\(\(thiscall\)\))?}}'}} template<int Z::*pm> struct A7; // expected-note{{template parameter is declared here}} template<int Z::*pm> struct A7c; A7<&Z::int_member> *a18_1; A7c<&Z::int_member> *a18_2; A7<&Z::float_member> *a18_3; // expected-error{{non-type template argument of type 'float Z::*' cannot be converted to a value of type 'int Z::*'}} A7c<(&Z::int_member)> *a18_4; // expected-warning{{address non-type template argument cannot be surrounded by parentheses}} A7c<&Z::union_member> *a18_5; template<unsigned char C> struct Overflow; // expected-note{{template parameter is declared here}} Overflow<5> *overflow1; // okay Overflow<255> *overflow2; // okay Overflow<256> *overflow3; // expected-warning{{non-type template argument value '256' truncated to '0' for template parameter of type 'unsigned char'}} template<unsigned> struct Signedness; // expected-note{{template parameter is declared here}} Signedness<10> *signedness1; // okay Signedness<-10> *signedness2; // expected-warning{{non-type template argument with value '-10' converted to '4294967286' for unsigned template parameter of type 'unsigned int'}} template<signed char C> struct SignedOverflow; // expected-note 3 {{template parameter is declared here}} SignedOverflow<1> *signedoverflow1; SignedOverflow<-1> *signedoverflow2; SignedOverflow<-128> *signedoverflow3; SignedOverflow<-129> *signedoverflow4; // expected-warning{{non-type template argument value '-129' truncated to '127' for template parameter of type 'signed char'}} SignedOverflow<127> *signedoverflow5; SignedOverflow<128> *signedoverflow6; // expected-warning{{non-type template argument value '128' truncated to '-128' for template parameter of type 'signed char'}} SignedOverflow<(unsigned char)128> *signedoverflow7; // expected-warning{{non-type template argument value '128' truncated to '-128' for template parameter of type 'signed char'}} // Check canonicalization of template arguments. template<int (*)(int, int)> struct FuncPtr0; int func0(int, int); extern FuncPtr0<&func0> *fp0; template<int (*)(int, int)> struct FuncPtr0; extern FuncPtr0<&func0> *fp0; int func0(int, int); extern FuncPtr0<&func0> *fp0; // PR5350 namespace ns { template <typename T> struct Foo { static const bool value = true; }; template <bool b> struct Bar {}; const bool value = false; Bar<bool(ns::Foo<int>::value)> x; } // PR5349 namespace ns { enum E { k }; template <E e> struct Baz {}; Baz<k> f1; // This works. Baz<E(0)> f2; // This too. Baz<static_cast<E>(0)> f3; // And this. Baz<ns::E(0)> b1; // This doesn't work. Baz<static_cast<ns::E>(0)> b2; // This neither. } // PR5597 template<int (*)(float)> struct X0 { }; struct X1 { static int pfunc(float); }; void test_X0_X1() { X0<X1::pfunc> x01; } // PR6249 namespace pr6249 { template<typename T, T (*func)()> T f() { return func(); } int h(); template int f<int, h>(); } namespace PR6723 { template<unsigned char C> void f(int (&a)[C]); // expected-note {{candidate template ignored}} \ // expected-note{{substitution failure [with C = '\x00']}} void g() { int arr512[512]; f(arr512); // expected-error{{no matching function for call}} f<512>(arr512); // expected-error{{no matching function for call}} } } // Check that we instantiate declarations whose addresses are taken // for non-type template arguments. namespace EntityReferenced { template<typename T, void (*)(T)> struct X { }; template<typename T> struct Y { static void f(T x) { x = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}} } }; void g() { typedef X<int*, Y<int*>::f> x; // expected-note{{in instantiation of}} } } namespace PR6964 { template <typename ,int, int = 9223372036854775807L > // expected-warning 2{{non-type template argument value '9223372036854775807' truncated to '-1' for template parameter of type 'int'}} \ // expected-note 2{{template parameter is declared here}} struct as_nview { }; template <typename Sequence, int I0> struct as_nview<Sequence, I0> // expected-note{{while checking a default template argument used here}} { }; } // rdar://problem/8302138 namespace test8 { template <int* ip> struct A { int* p; A() : p(ip) {} }; void test0() { extern int i00; A<&i00> a00; } extern int i01; void test1() { A<&i01> a01; } struct C { int x; char y; double z; }; template <C* cp> struct B { C* p; B() : p(cp) {} }; void test2() { extern C c02; B<&c02> b02; } extern C c03; void test3() { B<&c03> b03; } } namespace PR8372 { template <int I> void foo() { } // expected-note{{template parameter is declared here}} void bar() { foo <0x80000000> (); } // expected-warning{{non-type template argument value '2147483648' truncated to '-2147483648' for template parameter of type 'int'}} } namespace PR9227 { template <bool B> struct enable_if_bool { }; template <> struct enable_if_bool<true> { typedef int type; }; // expected-note{{'enable_if_bool<true>::type' declared here}} void test_bool() { enable_if_bool<false>::type i; } // expected-error{{enable_if_bool<false>'; did you mean 'enable_if_bool<true>::type'?}} template <char C> struct enable_if_char { }; template <> struct enable_if_char<'a'> { typedef int type; }; // expected-note 5{{'enable_if_char<'a'>::type' declared here}} void test_char_0() { enable_if_char<0>::type i; } // expected-error{{enable_if_char<'\x00'>'; did you mean 'enable_if_char<'a'>::type'?}} void test_char_b() { enable_if_char<'b'>::type i; } // expected-error{{enable_if_char<'b'>'; did you mean 'enable_if_char<'a'>::type'?}} void test_char_possibly_negative() { enable_if_char<'\x02'>::type i; } // expected-error{{enable_if_char<'\x02'>'; did you mean 'enable_if_char<'a'>::type'?}} void test_char_single_quote() { enable_if_char<'\''>::type i; } // expected-error{{enable_if_char<'\''>'; did you mean 'enable_if_char<'a'>::type'?}} void test_char_backslash() { enable_if_char<'\\'>::type i; } // expected-error{{enable_if_char<'\\'>'; did you mean 'enable_if_char<'a'>::type'?}} } namespace PR10579 { namespace fcppt { namespace container { namespace bitfield { template< typename Enum, Enum Size > class basic; template< typename Enum, Enum Size > class basic { public: basic() { } }; } } } namespace { namespace testenum { enum type { foo, bar, size }; } } int main() { typedef fcppt::container::bitfield::basic< testenum::type, testenum::size > bitfield_foo; bitfield_foo obj; } } template <int& I> struct PR10766 { static int *ip; }; template <int& I> int* PR10766<I>::ip = &I; namespace rdar13000548 { template<typename R, typename U, R F> U f() { return &F; } // expected-error{{cannot take the address of an rvalue of type 'int (*)(int)'}} expected-error{{cannot take the address of an rvalue of type 'int *'}} int g(int); int y[3]; void test() { f<int(int), int (*)(int), g>(); // expected-note{{in instantiation of}} f<int[3], int*, y>(); // expected-note{{in instantiation of}} } } namespace rdar13806270 { template <unsigned N> class X { }; const unsigned value = 32; struct Y { X<value + 1> x; }; void foo() {} } namespace PR17696 { struct a { union { int i; }; }; template <int (a::*p)> struct b : a { b() { this->*p = 0; } }; b<&a::i> c; // okay }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/member-inclass-init-value-dependent.cpp
// RUN: %clang_cc1 -emit-llvm-only %s // PR10290 template<int Flags> struct foo { int value = Flags && 0; }; void test() { foo<4> bar; } struct S { S(int n); }; template<typename> struct T { S s = 0; }; T<int> t;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/alignas.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s // expected-no-diagnostics using size_t = decltype(sizeof(0)); template<typename T, typename U> constexpr T max(T t, U u) { return t > u ? t : u; } template<typename T, typename ...Ts> constexpr auto max(T t, Ts ...ts) -> decltype(max(t, max(ts...))) { return max(t, max(ts...)); } template<typename...T> struct my_union { alignas(T...) char buffer[max(sizeof(T)...)]; }; struct alignas(8) A { char c; }; struct alignas(4) B { short s; }; struct C { char a[16]; }; static_assert(sizeof(my_union<A, B, C>) == 16, ""); static_assert(alignof(my_union<A, B, C>) == 8, "");
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-partial-spec.cpp
// RUN: %clang_cc1 -std=c++1y -verify %s // expected-no-diagnostics template<typename T> struct A { template<typename U> struct B; template<typename U> struct B<U*>; }; template<typename T> template<typename U> struct A<T>::B<U*> {}; template struct A<int>; A<int>::B<int*> b; template<typename T> struct B { template<typename U> static const int var1; template<typename U> static const int var1<U*>; template<typename U> static const int var2; }; template<typename T> template<typename U> const int B<T>::var1<U*> = 1; template<typename T> template<typename U> const int B<T>::var2<U*> = 1; template struct B<int>; int b_test1[B<int>::var1<int*>]; int b_test2[B<int>::var2<int*>];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/member-template-access-expr.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename U, typename T> U f0(T t) { return t.template get<U>(); } template<typename U, typename T> int &f1(T t) { // FIXME: When we pretty-print this, we lose the "template" keyword. return t.U::template get<int&>(); } struct X { template<typename T> T get(); }; void test_f0(X x) { int i = f0<int>(x); int &ir = f0<int&>(x); } struct XDerived : public X { }; void test_f1(XDerived xd) { int &ir = f1<X>(xd); } // PR5213 template <class T> struct A {}; template<class T> class B { A<T> a_; public: void destroy(); }; template<class T> void B<T>::destroy() { a_.~A<T>(); } void do_destroy_B(B<int> b) { b.destroy(); } struct X1 { int* f1(int); template<typename T> float* f1(T); static int* f2(int); template<typename T> static float* f2(T); }; void test_X1(X1 x1) { float *fp1 = x1.f1<>(17); float *fp2 = x1.f1<int>(3.14); // expected-warning {{implicit conversion from 'double' to 'int' changes value from 3.14 to 3}} int *ip1 = x1.f1(17); float *ip2 = x1.f1(3.14); float* (X1::*mf1)(int) = &X1::f1; float* (X1::*mf2)(int) = &X1::f1<>; float* (X1::*mf3)(float) = &X1::f1<float>; float* (*fp3)(int) = &X1::f2; float* (*fp4)(int) = &X1::f2<>; float* (*fp5)(float) = &X1::f2<float>; float* (*fp6)(int) = X1::f2; float* (*fp7)(int) = X1::f2<>; float* (*fp8)(float) = X1::f2<float>; } template<int A> struct X2 { int m; }; template<typename T> struct X3 : T { }; template<typename T> struct X4 { template<typename U> void f(X2<sizeof(X3<U>().U::m)>); }; void f(X4<X3<int> > x4i) { X2<sizeof(int)> x2; x4i.f<X2<sizeof(int)> >(x2); } template<typename T> struct X5 { template<typename U> void f(); void g() { this->f<T*>(); } }; namespace PR6021 { template< class T1, class T2 > class Outer { public: // Range operations template< class X > X tmpl( const X* = 0 ) const; struct Inner { const Outer& o; template< class X > operator X() const { return o.tmpl<X>(); } }; }; } namespace rdar8198511 { template<int, typename U> struct Base { void f(); }; template<typename T> struct X0 : Base<1, T> { }; template<typename T> struct X1 { X0<int> x0; void f() { this->x0.Base<1, int>::f(); } }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-method.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> class X { public: void f(T x); // expected-error{{argument may not have 'void' type}} void g(T*); static int h(T, T); // expected-error {{argument may not have 'void' type}} }; int identity(int x) { return x; } void test(X<int> *xi, int *ip, X<int(int)> *xf) { xi->f(17); xi->g(ip); xf->f(&identity); xf->g(identity); X<int>::h(17, 25); X<int(int)>::h(identity, &identity); } void test_bad() { X<void> xv; // expected-note{{in instantiation of template class 'X<void>' requested here}} } template<typename T, typename U> class Overloading { public: int& f(T, T); // expected-note{{previous declaration is here}} float& f(T, U); // expected-error{{functions that differ only in their return type cannot be overloaded}} }; void test_ovl(Overloading<int, long> *oil, int i, long l) { int &ir = oil->f(i, i); float &fr = oil->f(i, l); } void test_ovl_bad() { Overloading<float, float> off; // expected-note{{in instantiation of template class 'Overloading<float, float>' requested here}} } template<typename T> class HasDestructor { public: virtual ~HasDestructor() = 0; }; int i = sizeof(HasDestructor<int>); // FIXME: forces instantiation, but // the code below should probably instantiate by itself. int abstract_destructor[__is_abstract(HasDestructor<int>)? 1 : -1]; template<typename T> class Constructors { public: Constructors(const T&); Constructors(const Constructors &other); }; void test_constructors() { Constructors<int> ci1(17); Constructors<int> ci2 = ci1; } template<typename T> struct ConvertsTo { operator T(); }; void test_converts_to(ConvertsTo<int> ci, ConvertsTo<int *> cip) { int i = ci; int *ip = cip; } // PR4660 template<class T> struct A0 { operator T*(); }; template<class T> struct A1; int *a(A0<int> &x0, A1<int> &x1) { int *y0 = x0; int *y1 = x1; // expected-error{{no viable conversion}} } struct X0Base { int &f(); int& g(int); static double &g(double); }; template<typename T> struct X0 : X0Base { }; template<typename U> struct X1 : X0<U> { int &f2() { return X0Base::f(); } }; void test_X1(X1<int> x1i) { int &ir = x1i.f2(); } template<typename U> struct X2 : X0Base, U { int &f2() { return X0Base::f(); } }; template<typename T> struct X3 { void test(T x) { double& d1 = X0Base::g(x); } }; template struct X3<double>; // Don't try to instantiate this, it's invalid. namespace test1 { template <class T> class A {}; template <class T> class B { void foo(A<test1::Undeclared> &a) // expected-error {{no member named 'Undeclared' in namespace 'test1'}} {} }; template class B<int>; } namespace PR6947 { template< class T > struct X { int f0( ) { typedef void ( X::*impl_fun_ptr )( ); impl_fun_ptr pImpl = &X::template f0_impl1<int>; } private: int f1() { } template< class Processor> void f0_impl1( ) { } }; char g0() { X<int> pc; pc.f0(); } } namespace PR7022 { template <typename > struct X1 { typedef int state_t( ); state_t g ; }; template < typename U = X1<int> > struct X2 { X2( U = U()) { } }; void m(void) { typedef X2<> X2_type; X2_type c; } } namespace SameSignatureAfterInstantiation { template<typename T> struct S { void f(T *); // expected-note {{previous}} void f(const T*); // expected-error-re {{multiple overloads of 'f' instantiate to the same signature 'void (const int *){{( __attribute__\(\(thiscall\)\))?}}'}} }; S<const int> s; // expected-note {{instantiation}} } namespace PR22040 { template <typename T> struct Foobar { template <> void bazqux(typename T::type) {} // expected-error {{cannot specialize a function 'bazqux' within class scope}} expected-error 2{{cannot be used prior to '::' because it has no members}} }; void test() { // FIXME: we should suppress the "no member" errors Foobar<void>::bazqux(); // expected-error{{no member named 'bazqux' in }} expected-note{{in instantiation of template class }} Foobar<int>::bazqux(); // expected-error{{no member named 'bazqux' in }} expected-note{{in instantiation of template class }} Foobar<int>::bazqux(3); // expected-error{{no member named 'bazqux' in }} } } template <typename> struct SpecializationOfGlobalFnInClassScope { template <> void ::Fn(); // expected-error{{cannot have a qualified name}} }; class AbstractClassWithGlobalFn { template <typename> void ::f(); // expected-error{{cannot have a qualified name}} virtual void f1() = 0; };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/alias-template-template-param.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s // expected-no-diagnostics template<template<typename> class D> using C = D<int>; // Substitution of the alias template transforms the TemplateSpecializationType // 'D<int>' into the DependentTemplateSpecializationType 'T::template U<int>'. template<typename T> void f(C<T::template U>);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/alias-nested-nontag.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s template<typename T> using Id = T; // expected-note {{type alias template 'Id' declared here}} struct U { static Id<int> V; }; Id<int> ::U::V; // expected-error {{type 'Id<int>' (aka 'int') cannot be used prior to '::' because it has no members}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/template-id-expr.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // PR5336 template<typename FromCl> struct isa_impl_cl { template<class ToCl> static void isa(const FromCl &Val) { } }; template<class X, class Y> void isa(const Y &Val) { return isa_impl_cl<Y>::template isa<X>(Val); } class Value; void f0(const Value &Val) { isa<Value>(Val); } // Implicit template-ids. template<typename T> struct X0 { template<typename U> void f1(); template<typename U> void f2(U) { f1<U>(); } }; void test_X0_int(X0<int> xi, float f) { xi.f2(f); } // Not template-id expressions, but they almost look like it. template<typename F> struct Y { Y(const F&); }; template<int I> struct X { X(int, int); void f() { Y<X<I> >(X<I>(0, 0)); Y<X<I> >(::X<I>(0, 0)); } }; template struct X<3>; // 'template' as a disambiguator. // PR7030 struct Y0 { template<typename U> void f1(U); template<typename U> static void f2(U); void f3(int); static int f4(int); template<typename U> static void f4(U); template<typename U> void f() { Y0::template f1<U>(0); Y0::template f1(0); this->template f1(0); Y0::template f2<U>(0); Y0::template f2(0); Y0::template f3(0); // expected-error {{'f3' following the 'template' keyword does not refer to a template}} Y0::template f3(); // expected-error {{'f3' following the 'template' keyword does not refer to a template}} int x; x = Y0::f4(0); x = Y0::f4<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} x = Y0::template f4(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} x = this->f4(0); x = this->f4<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} x = this->template f4(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} } }; struct A { template<int I> struct B { static void b1(); }; }; template<int I> void f5() { A::template B<I>::template b1(); // expected-error {{'b1' following the 'template' keyword does not refer to a template}} } template void f5<0>(); // expected-note {{in instantiation of function template specialization 'f5<0>' requested here}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_class_order.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T, typename U> struct X1 { static const int value = 0; }; template<typename T, typename U> struct X1<T*, U*> { static const int value = 1; }; template<typename T> struct X1<T*, T*> { static const int value = 2; }; template<typename T> struct X1<const T*, const T*> { static const int value = 3; }; int array0[X1<int, int>::value == 0? 1 : -1]; int array1[X1<int*, float*>::value == 1? 1 : -1]; int array2[X1<int*, int*>::value == 2? 1 : -1]; typedef const int* CIP; int array3[X1<const int*, CIP>::value == 3? 1 : -1]; template<typename T, typename U> struct X2 { }; template<typename T, typename U> struct X2<T*, U> { }; // expected-note{{matches}} template<typename T, typename U> struct X2<T, U*> { }; // expected-note{{matches}} template<typename T, typename U> struct X2<const T*, const U*> { }; X2<int*, int*> x2a; // expected-error{{ambiguous}} X2<const int*, const int*> x2b;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/template-decl-fail.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> typedef T X; // expected-error{{typedef cannot be a template}} template<typename T> enum t0 { A = T::x }; // expected-error{{enumeration cannot be a template}} \ // expected-warning{{declaration does not declare anything}} enum e0 {}; template<int x> enum e0 f0(int a=x) {}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-typeof.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s // expected-no-diagnostics // Make sure we correctly treat __typeof as potentially-evaluated when appropriate template<typename T> void f(T n) { int buffer[n]; [&buffer] { __typeof(buffer) x; }(); } int main() { f<int>(1); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-decl-dtor.cpp
// RUN: %clang_cc1 %s -fsyntax-only -verify template <typename T> struct A { T x; A(int y) { x = y; } ~A() { *x = 10; } // expected-error {{indirection requires pointer operand}} }; void a() { A<int> b = 10; // expected-note {{requested here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/typename-specifier-3.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // PR4364 template<class T> struct a { T b() { return typename T::x(); } }; struct B { typedef B x; }; B c() { a<B> x; return x.b(); } // Some extra tests for invalid cases template<class T> struct test2 { T b() { return typename T::a; } }; // expected-error{{expected '(' for function-style cast or type construction}} template<class T> struct test3 { T b() { return typename a; } }; // expected-error{{expected a qualified name after 'typename'}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/rdar9173693.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // <rdar://problem/9173693> template< bool C > struct assert { }; template< bool > struct assert_arg_pred_impl { }; // expected-note 3 {{declared here}} template< typename Pred > assert<false> assert_not_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type ); // expected-error 5 {{}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/example-typelist.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // A simple cons-style typelist struct nil { }; template<typename Head, typename Tail = nil> struct cons { typedef Head head; typedef Tail tail; }; // is_same trait, for testing template<typename T, typename U> struct is_same { static const bool value = false; }; template<typename T> struct is_same<T, T> { static const bool value = true; }; // metaprogram that computes the length of a list template<typename T> struct length; template<typename Head, typename Tail> struct length<cons<Head, Tail> > { static const unsigned value = length<Tail>::value + 1; }; template<> struct length<nil> { static const unsigned value = 0; }; typedef cons<unsigned char, cons<unsigned short, cons<unsigned int, cons<unsigned long> > > > unsigned_inttypes; int length0[length<unsigned_inttypes>::value == 4? 1 : -1]; // metaprogram that reverses a list // FIXME: I would prefer that this be a partial specialization, but // that requires partial ordering of class template partial // specializations. template<typename T> class reverse { typedef typename reverse<typename T::tail>::type reversed_tail; typedef typename reverse<typename reversed_tail::tail>::type most_of_tail; public: typedef cons<typename reversed_tail::head, typename reverse<cons<typename T::head, most_of_tail> >::type> type; }; template<typename Head> class reverse<cons<Head> > { public: typedef cons<Head> type; }; template<> class reverse<nil> { public: typedef nil type; }; int reverse0[is_same<reverse<unsigned_inttypes>::type, cons<unsigned long, cons<unsigned int, cons<unsigned short, cons<unsigned char> > > > >::value? 1 : -1]; // metaprogram that finds a type within a list // FIXME: I would prefer that this be a partial specialization, but // that requires partial ordering of class template partial // specializations. template<typename List, typename T> struct find : find<typename List::tail, T> { }; template<typename Tail, typename T> struct find<cons<T, Tail>, T> { typedef cons<T, Tail> type; }; template<typename T> struct find<nil, T> { typedef nil type; }; int find0[is_same<find<unsigned_inttypes, unsigned int>::type, cons<unsigned int, cons<unsigned long> > >::value? 1 : -1]; int find1[is_same<find<unsigned_inttypes, int>::type, nil>::value? 1 : -1];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-template-template-parm.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<template<typename T> class MetaFun, typename Value> struct apply { typedef typename MetaFun<Value>::type type; }; template<class T> struct add_pointer { typedef T* type; }; template<class T> struct add_reference { typedef T& type; }; int i; apply<add_pointer, int>::type ip = &i; apply<add_reference, int>::type ir = i; apply<add_reference, float>::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}} // Template template parameters template<int> struct B; // expected-note{{has a different type 'int'}} template<typename T, template<T Value> class X> // expected-error{{cannot have type 'float'}} \ // expected-note{{with type 'long'}} struct X0 { }; X0<int, B> x0b1; X0<float, B> x0b2; // expected-note{{while substituting}} X0<long, B> x0b3; // expected-error{{template template argument has different template parameters}} template<template<int V> class TT> // expected-note{{parameter with type 'int'}} struct X1 { }; template<typename T, template<T V> class TT> struct X2 { X1<TT> x1; // expected-error{{has different template parameters}} }; template<int V> struct X3i { }; template<long V> struct X3l { }; // expected-note{{different type 'long'}} X2<int, X3i> x2okay; X2<long, X3l> x2bad; // expected-note{{instantiation}} template <typename T, template <T, T> class TT, class R = TT<1, 2> > struct Comp { typedef R r1; template <T x, T y> struct gt { static const bool result = x > y; }; typedef gt<2, 1> r2; }; template <int x, int y> struct lt { static const bool result = x < y; }; Comp<int, lt> c0; namespace PR8629 { template<template<int> class TT> struct X0 { static void apply(); }; template<int> struct Type { }; template<class T> struct X1 { template<class U> struct Inner; template<class U> void g() { typedef Inner<U> Init; X0<Init::template VeryInner>::apply(); } template<int N> void f () { g<Type<N> >(); } }; template<class T> template<class U> struct X1<T>::Inner { template<int> struct VeryInner { }; }; struct X1Container { X1Container() { simplex_.f<0>(); } X1<double> simplex_; }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/function-template-specialization-noreturn.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // Split from function-template-specialization.cpp because the noreturn warning // requires analysis-based warnings, which the other errors in that test case // disable. template <int N> void __attribute__((noreturn)) f3() { __builtin_unreachable(); } template <> void f3<1>() { } // expected-warning {{function declared 'noreturn' should not return}} #if __cplusplus >= 201103L namespace PR21942 { template <int> struct A { void foo[[noreturn]](); }; template <> void A<0>::foo() {} // expected-warning{{function declared 'noreturn' should not return}} } #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/value-dependent-null-pointer-constant.cpp
// RUN: %clang_cc1 -fsyntax-only %s template<typename T, int N> struct X0 { const char *f0(bool Cond) { return Cond? "honk" : N; } const char *f1(bool Cond) { return Cond? N : "honk"; } bool f2(const char *str) { return str == N; } }; // PR4996 template<unsigned I> int f0() { return __builtin_choose_expr(I, 0, 1); } // PR5041 struct A { }; template <typename T> void f(T *t) { (void)static_cast<void*>(static_cast<A*>(t)); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-case.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<class T> static int alpha(T c) { return *c; // expected-error{{indirection requires pointer operand}} } template<class T> static void _shexp_match() { switch(1) { case 1: alpha(1); // expected-note{{instantiation of function template}} } } int main() { _shexp_match<char>(); // expected-note{{instantiation of function template}} return 0; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace test0 { // p3 template<typename T> int foo(T), bar(T, T); // expected-error{{single entity}} } // PR7252 namespace test1 { namespace A { template<typename T> struct Base { typedef T t; }; } // expected-note {{member found}} namespace B { template<typename T> struct Base { typedef T t; }; } // expected-note {{member found}} template<typename T> struct Derived : A::Base<char>, B::Base<int> { // FIXME: the syntax error here is unfortunate typename Derived::Base<float>::t x; // expected-error {{found in multiple base classes of different types}} \ // expected-error {{expected member name or ';'}} }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-expr-4.cpp
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s // --------------------------------------------------------------------- // C++ Functional Casts // --------------------------------------------------------------------- template<int N> struct ValueInit0 { int f() { return int(); } }; template struct ValueInit0<5>; template<int N> struct FunctionalCast0 { int f() { return int(N); } }; template struct FunctionalCast0<5>; struct X { // expected-note 3 {{candidate constructor (the implicit copy constructor)}} X(int, int); // expected-note 3 {{candidate constructor}} }; template<int N, int M> struct BuildTemporary0 { X f() { return X(N, M); } }; template struct BuildTemporary0<5, 7>; template<int N, int M> struct Temporaries0 { void f() { (void)X(N, M); } }; template struct Temporaries0<5, 7>; // Ensure that both the constructor and the destructor are instantiated by // checking for parse errors from each. template<int N> struct BadX { BadX() { int a[-N]; } // expected-error {{array with a negative size}} ~BadX() { int a[-N]; } // expected-error {{array with a negative size}} }; template<int N> struct PR6671 { void f() { (void)BadX<1>(); } // expected-note 2 {{instantiation}} }; template struct PR6671<1>; // --------------------------------------------------------------------- // new/delete expressions // --------------------------------------------------------------------- struct Y { }; template<typename T> struct New0 { T* f(bool x) { if (x) return new T; // expected-error{{no matching}} else return new T(); } }; template struct New0<int>; template struct New0<Y>; template struct New0<X>; // expected-note{{instantiation}} template<typename T, typename Arg1> struct New1 { T* f(bool x, Arg1 a1) { return new T(a1); // expected-error{{no matching}} } }; template struct New1<int, float>; template struct New1<Y, Y>; template struct New1<X, Y>; // expected-note{{instantiation}} template<typename T, typename Arg1, typename Arg2> struct New2 { T* f(bool x, Arg1 a1, Arg2 a2) { return new T(a1, a2); // expected-error{{no matching}} } }; template struct New2<X, int, float>; template struct New2<X, int, int*>; // expected-note{{instantiation}} // FIXME: template struct New2<int, int, float>; // PR5833 struct New3 { New3(); void *operator new[](__SIZE_TYPE__) __attribute__((unavailable)); // expected-note{{explicitly made unavailable}} }; template<class C> void* object_creator() { return new C(); // expected-error{{call to unavailable function 'operator new[]'}} } template void *object_creator<New3[4]>(); // expected-note{{instantiation}} template<typename T> struct Delete0 { void f(T t) { delete t; // expected-error{{cannot delete}} ::delete [] t; // expected-error{{cannot delete}} } }; template struct Delete0<int*>; template struct Delete0<X*>; template struct Delete0<int>; // expected-note{{instantiation}} namespace PR5755 { template <class T> void Foo() { char* p = 0; delete[] p; } void Test() { Foo<int>(); } } namespace PR10480 { template<typename T> struct X { X(); ~X() { T *ptr = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} } }; template<typename T> void f() { new X<int>[1]; // expected-note{{in instantiation of member function 'PR10480::X<int>::~X' requested here}} } template void f<int>(); } // --------------------------------------------------------------------- // throw expressions // --------------------------------------------------------------------- template<typename T> struct Throw1 { void f(T t) { throw; throw t; // expected-error{{incomplete type}} } }; struct Incomplete; // expected-note 2{{forward}} template struct Throw1<int>; template struct Throw1<int*>; template struct Throw1<Incomplete*>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // typeid expressions // --------------------------------------------------------------------- namespace std { class type_info; } template<typename T> struct TypeId0 { const std::type_info &f(T* ptr) { if (ptr) return typeid(ptr); else return typeid(T); // expected-error{{'typeid' of incomplete type 'Incomplete'}} } }; struct Abstract { virtual void f() = 0; }; template struct TypeId0<int>; template struct TypeId0<Incomplete>; // expected-note{{instantiation of member function}} template struct TypeId0<Abstract>; // --------------------------------------------------------------------- // type traits // --------------------------------------------------------------------- template<typename T> struct is_pod { static const bool value = __is_pod(T); }; static int is_pod0[is_pod<X>::value? -1 : 1]; static int is_pod1[is_pod<Y>::value? 1 : -1]; // --------------------------------------------------------------------- // initializer lists // --------------------------------------------------------------------- template<typename T, typename Val1> struct InitList1 { void f(Val1 val1) { T x = { val1 }; } }; struct APair { int *x; const float *y; }; template struct InitList1<int[1], float>; template struct InitList1<APair, int*>; template<typename T, typename Val1, typename Val2> struct InitList2 { void f(Val1 val1, Val2 val2) { T x = { val1, val2 }; // expected-error{{cannot initialize}} } }; template struct InitList2<APair, int*, float*>; template struct InitList2<APair, int*, double*>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // member references // --------------------------------------------------------------------- template<typename T, typename Result> struct DotMemRef0 { void f(T t) { Result result = t.m; // expected-error{{non-const lvalue reference to type}} } }; struct MemInt { int m; }; struct InheritsMemInt : MemInt { }; struct MemIntFunc { static int m(int); }; template struct DotMemRef0<MemInt, int&>; template struct DotMemRef0<InheritsMemInt, int&>; template struct DotMemRef0<MemIntFunc, int (*)(int)>; template struct DotMemRef0<MemInt, float&>; // expected-note{{instantiation}} template<typename T, typename Result> struct ArrowMemRef0 { void f(T t) { Result result = t->m; // expected-error 2{{non-const lvalue reference}} } }; template<typename T> struct ArrowWrapper { T operator->(); }; template struct ArrowMemRef0<MemInt*, int&>; template struct ArrowMemRef0<InheritsMemInt*, int&>; template struct ArrowMemRef0<MemIntFunc*, int (*)(int)>; template struct ArrowMemRef0<MemInt*, float&>; // expected-note{{instantiation}} template struct ArrowMemRef0<ArrowWrapper<MemInt*>, int&>; template struct ArrowMemRef0<ArrowWrapper<InheritsMemInt*>, int&>; template struct ArrowMemRef0<ArrowWrapper<MemIntFunc*>, int (*)(int)>; template struct ArrowMemRef0<ArrowWrapper<MemInt*>, float&>; // expected-note{{instantiation}} template struct ArrowMemRef0<ArrowWrapper<ArrowWrapper<MemInt*> >, int&>; struct UnresolvedMemRefArray { int f(int); int f(char); }; UnresolvedMemRefArray Arr[10]; template<typename U> int UnresolvedMemRefArrayT(U u) { return Arr->f(u); } template int UnresolvedMemRefArrayT<int>(int); // FIXME: we should be able to return a MemInt without the reference! MemInt &createMemInt(int); template<int N> struct NonDepMemberExpr0 { void f() { createMemInt(N).m = N; } }; template struct NonDepMemberExpr0<0>; template<typename T, typename Result> struct MemberFuncCall0 { void f(T t) { Result result = t.f(); } }; template<typename T> struct HasMemFunc0 { T f(); }; template struct MemberFuncCall0<HasMemFunc0<int&>, const int&>; template<typename Result> struct ThisMemberFuncCall0 { Result g(); void f() { Result r1 = g(); Result r2 = this->g(); } }; template struct ThisMemberFuncCall0<int&>; template<typename T> struct NonDepMemberCall0 { void foo(HasMemFunc0<int&> x) { T result = x.f(); // expected-error{{non-const lvalue reference}} } }; template struct NonDepMemberCall0<int&>; template struct NonDepMemberCall0<const int&>; template struct NonDepMemberCall0<float&>; // expected-note{{instantiation}} template<typename T> struct QualifiedDeclRef0 { T f() { return is_pod<X>::value; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'const bool'}} } }; template struct QualifiedDeclRef0<bool>; template struct QualifiedDeclRef0<int&>; // expected-note{{instantiation}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/typo-dependent-name.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics template<typename T> struct Base { T inner; }; template<typename T> struct X { template<typename U> struct Inner { }; bool f(T other) { return this->inner < other; } };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-depth-exception-spec.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ftemplate-depth 16 -fcxx-exceptions -fexceptions %s template<typename T> T go(T a) noexcept(noexcept(go(a))); // \ // expected-error 16{{call to function 'go' that is neither visible}} \ // expected-note 16{{'go' should be declared prior to the call site}} \ // expected-error {{recursive template instantiation exceeded maximum depth of 16}} void f() { int k = go(0); // \ // expected-note {{in instantiation of exception specification for 'go<int>' requested here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-cast.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct A { int x; }; // expected-note 2 {{candidate constructor}} class Base { public: virtual void f(); }; class Derived : public Base { }; struct ConvertibleToInt { operator int() const; }; struct Constructible { Constructible(int, float); }; // --------------------------------------------------------------------- // C-style casts // --------------------------------------------------------------------- template<typename T, typename U> struct CStyleCast0 { void f(T t) { (void)((U)t); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}} } }; template struct CStyleCast0<int, float>; template struct CStyleCast0<A, int>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // static_cast // --------------------------------------------------------------------- template<typename T, typename U> struct StaticCast0 { void f(T t) { (void)static_cast<U>(t); // expected-error{{no matching conversion for static_cast from 'int' to 'A'}} } }; template struct StaticCast0<ConvertibleToInt, bool>; template struct StaticCast0<int, float>; template struct StaticCast0<int, A>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // dynamic_cast // --------------------------------------------------------------------- template<typename T, typename U> struct DynamicCast0 { void f(T t) { (void)dynamic_cast<U>(t); // expected-error{{not a reference or pointer}} } }; template struct DynamicCast0<Base*, Derived*>; template struct DynamicCast0<Base*, A>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // reinterpret_cast // --------------------------------------------------------------------- template<typename T, typename U> struct ReinterpretCast0 { void f(T t) { (void)reinterpret_cast<U>(t); // expected-error{{qualifiers}} } }; template struct ReinterpretCast0<void (*)(int), void (*)(float)>; template struct ReinterpretCast0<int const *, float *>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // const_cast // --------------------------------------------------------------------- template<typename T, typename U> struct ConstCast0 { void f(T t) { (void)const_cast<U>(t); // expected-error{{not allowed}} } }; template struct ConstCast0<int const * *, int * *>; template struct ConstCast0<int const *, float *>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // C++ functional cast // --------------------------------------------------------------------- template<typename T, typename U> struct FunctionalCast1 { void f(T t) { (void)U(t); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}} } }; template struct FunctionalCast1<int, float>; template struct FunctionalCast1<A, int>; // expected-note{{instantiation}} // Generates temporaries, which we cannot handle yet. template<int N, long M> struct FunctionalCast2 { void f() { (void)Constructible(N, M); } }; template struct FunctionalCast2<1, 3>; // --------------------------------------------------------------------- // implicit casting // --------------------------------------------------------------------- template<typename T> struct Derived2 : public Base { }; void test_derived_to_base(Base *&bp, Derived2<int> *dp) { bp = dp; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-exception-spec.cpp
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -verify %s -DERRORS // RUN: %clang_cc1 -fexceptions -fcxx-exceptions -emit-llvm-only %s #ifdef ERRORS template<typename T> void f1(T*) throw(T); // expected-error{{incomplete type 'Incomplete' is not allowed in exception specification}} struct Incomplete; // expected-note{{forward}} void test_f1(Incomplete *incomplete_p, int *int_p) { f1(int_p); f1(incomplete_p); // expected-note{{instantiation of}} } #endif template<typename T> void f(void (*p)() throw(T)) { #ifdef ERRORS void (*q)() throw(char) = p; // expected-error {{target exception spec}} extern void (*p2)() throw(T); void (*q2)() throw(char) = p2; // expected-error {{target exception spec}} extern void (*p3)() throw(char); void (*q3)() throw(T) = p3; // expected-error {{target exception spec}} void (*q4)() throw(T) = p2; // ok #endif p(); } void g() { f<int>(0); } // expected-note {{instantiation of}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
// RUN: %clang_cc1 -std=c++1z -verify %s template<typename ...T> constexpr auto sum(T ...t) { return (... + t); } template<typename ...T> constexpr auto product(T ...t) { return (t * ...); } template<typename ...T> constexpr auto all(T ...t) { return (true && ... && t); } template<typename ...T> constexpr auto dumb(T ...t) { return (false && ... && t); } static_assert(sum(1, 2, 3, 4, 5) == 15); static_assert(product(1, 2, 3, 4, 5) == 120); static_assert(!all(true, true, false, true, false)); static_assert(all(true, true, true, true, true)); static_assert(!dumb(true, true, true, true, true)); struct S { int a, b, c, d, e; }; template<typename ...T> constexpr auto increment_all(T &...t) { (++t, ...); } constexpr bool check() { S s = { 1, 2, 3, 4, 5 }; increment_all(s.a, s.b, s.c, s.d, s.e); return s.a == 2 && s.b == 3 && s.c == 4 && s.d == 5 && s.e == 6; } static_assert(check()); template<int ...N> void empty() { static_assert((N + ...) == 0); static_assert((N * ...) == 1); static_assert((N | ...) == 0); static_assert((N & ...) == -1); static_assert((N || ...) == false); static_assert((N && ...) == true); (N, ...); } template void empty<>(); // An empty fold-expression isn't a null pointer just because it's an integer // with value 0. template<int ...N> void null_ptr() { void *p = (N + ...); // expected-error {{rvalue of type 'int'}} void *q = (N | ...); // expected-error {{rvalue of type 'int'}} } template void null_ptr<>(); // expected-note {{in instantiation of}} template<int ...N> void bad_empty() { (N - ...); // expected-error {{empty expansion for operator '-' with no fallback}} (N / ...); // expected-error {{empty expansion for operator '/' with no fallback}} (N % ...); // expected-error {{empty expansion for operator '%' with no fallback}} (N = ...); // expected-error {{empty expansion for operator '=' with no fallback}} } template void bad_empty<>(); // expected-note {{in instantiation of}} template<int ...N> void empty_with_base() { extern int k; (k = ... = N); // expected-warning{{unused}} void (k = ... = N); // expected-error {{expected ')'}} expected-note {{to match}} void ((k = ... = N)); (void) (k = ... = N); } template void empty_with_base<>(); // expected-note {{in instantiation of}} template void empty_with_base<1>(); struct A { struct B { struct C { struct D { int e; } d; } c; } b; } a; template<typename T, typename ...Ts> constexpr decltype(auto) apply(T &t, Ts ...ts) { return (t.*....*ts); } static_assert(&apply(a, &A::b, &A::B::c, &A::B::C::d, &A::B::C::D::e) == &a.b.c.d.e);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/self-comparison.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template <int A, int B> void foo() { (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} (void)(A == B); } template <int A, int B> struct S1 { void foo() { (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} (void)(A == B); } }; template <int A, int B> struct S2 { template <typename T> T foo() { (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} (void)(A == B); } }; struct S3 { template <int A, int B> void foo() { (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} (void)(A == B); } }; template <int A> struct S4 { template <int B> void foo() { (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} (void)(A == B); } }; const int N = 42; template <int X> void foo2() { (void)(X == N); (void)(N == X); } void test() { foo<1, 1>(); S1<1, 1> s1; s1.foo(); S2<1, 1> s2; s2.foo<void>(); S3 s3; s3.foo<1, 1>(); S4<1> s4; s4.foo<1>(); foo2<N>(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/class-template-id.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T, typename U = float> struct A { }; typedef A<int> A_int; typedef float FLOAT; A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) { if (ptr) return ptr; // okay else if (ptr2) return ptr2; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'const A<int> *'}} else { return ptr3; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'A<int, double> *'}} } } template<int I> struct B; const int value = 12; B<17 + 2> *bar(B<(19)> *ptr1, B< (::value + 7) > *ptr2, B<19 - 3> *ptr3) { if (ptr1) return ptr1; else if (ptr2) return ptr2; else return ptr3; // expected-error{{cannot initialize return object of type 'B<17 + 2> *' with an lvalue of type 'B<19 - 3>}} } typedef B<5> B5; namespace N { template<typename T> struct C {}; } N::C<int> c1; typedef N::C<float> c2; // PR5655 template<typename T> struct Foo { }; // expected-note{{template is declared here}} void f(void) { Foo bar; } // expected-error{{use of class template 'Foo' requires template arguments}} // rdar://problem/8254267 template <typename T> class Party; template <> class Party<T> { friend struct Party<>; }; // expected-error {{use of undeclared identifier 'T'}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-enum.cpp
// RUN: %clang_cc1 -fsyntax-only %s template<typename T, T I, int J> struct adder { enum { value = I + J, value2 }; }; int array1[adder<long, 3, 4>::value == 7? 1 : -1]; namespace PR6375 { template<typename T> void f() { enum Enum { enumerator1 = 0xFFFFFFF, enumerator2 = enumerator1 - 1 }; int xb1 = enumerator1; int xe1 = enumerator2; } template void f<int>(); } namespace EnumScoping { template <typename T> class C { enum { value = 42 }; }; void f(int i, C<int>::C c) { int value; } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/alias-church-numerals.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // expected-no-diagnostics template<template<template<typename> class, typename> class T, template<typename> class V> struct PartialApply { template<typename W> using R = T<V, W>; }; template<typename T> using Id = T; template<template<typename> class, typename X> using Zero = X; template<template<template<typename> class, typename> class N, template<typename> class F, typename X> using Succ = F<N<F,X>>; template<template<typename> class F, typename X> using One = Succ<Zero, F, X>; template<template<typename> class F, typename X> using Two = Succ<One, F, X>; template<template<template<typename> class, typename> class A, template<template<typename> class, typename> class B, template<typename> class F, typename X> using Add = A<F, B<F, X>>; template<template<template<typename> class, typename> class A, template<template<typename> class, typename> class B, template<typename> class F, typename X> using Mul = A<PartialApply<B,F>::template R, X>; template<template<typename> class F, typename X> using Four = Add<Two, Two, F, X>; template<template<typename> class F, typename X> using Sixteen = Mul<Four, Four, F, X>; template<template<typename> class F, typename X> using TwoHundredAndFiftySix = Mul<Sixteen, Sixteen, F, X>; template<typename T, T N> struct Const { static const T value = N; }; template<typename A> struct IncrementHelper; template<typename T, T N> struct IncrementHelper<Const<T, N>> { using Result = Const<T, N+1>; }; template<typename A> using Increment = typename IncrementHelper<A>::Result; using Arr = int[TwoHundredAndFiftySix<Increment, Const<int, 0>>::value]; using Arr = int[256];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/virtual-member-functions.cpp
// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify %s // RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -verify %s namespace PR5557 { template <class T> struct A { A(); // expected-note{{instantiation}} virtual int a(T x); }; template<class T> A<T>::A() {} template<class T> int A<T>::a(T x) { return *x; // expected-error{{requires pointer operand}} } void f() { A<int> x; // expected-note{{instantiation}} } template<typename T> struct X { virtual void f(); }; template<> void X<int>::f() { } } // Like PR5557, but with a defined destructor instead of a defined constructor. namespace PR5557_dtor { template <class T> struct A { A(); // Don't have an implicit constructor. ~A(); // expected-note{{instantiation}} virtual int a(T x); }; template<class T> A<T>::~A() {} template<class T> int A<T>::a(T x) { return *x; // expected-error{{requires pointer operand}} } void f() { A<int> x; // expected-note{{instantiation}} } } template<typename T> struct Base { virtual ~Base() { int *ptr = 0; T t = ptr; // expected-error{{cannot initialize}} } }; template<typename T> struct Derived : Base<T> { virtual void foo() { } }; template struct Derived<int>; // expected-note {{in instantiation of member function 'Base<int>::~Base' requested here}} template<typename T> struct HasOutOfLineKey { HasOutOfLineKey() { } // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}} virtual T *f(float *fp); }; template<typename T> T *HasOutOfLineKey<T>::f(float *fp) { return fp; // expected-error{{cannot initialize return object of type 'int *' with an lvalue of type 'float *'}} } HasOutOfLineKey<int> out_of_line; // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::HasOutOfLineKey' requested here}} namespace std { class type_info; } namespace PR7114 { class A { virtual ~A(); }; // expected-note{{declared private here}} template<typename T> class B { public: class Inner : public A { }; // expected-error{{base class 'PR7114::A' has private destructor}} static Inner i; static const unsigned value = sizeof(i) == 4; }; int f() { return B<int>::value; } #ifdef MSABI void test_typeid(B<float>::Inner bfi) { // expected-note{{implicit destructor}} (void)typeid(bfi); #else void test_typeid(B<float>::Inner bfi) { (void)typeid(bfi); // expected-note{{implicit destructor}} #endif } template<typename T> struct X : A { void f() { } }; void test_X(X<int> &xi, X<float> &xf) { xi.f(); } } namespace DynamicCast { struct Y {}; template<typename T> struct X : virtual Y { virtual void foo() { T x; } }; template<typename T> struct X2 : virtual Y { virtual void foo() { T x; } }; Y* f(X<void>* x) { return dynamic_cast<Y*>(x); } Y* f2(X<void>* x) { return dynamic_cast<Y*>(x); } } namespace avoid_using_vtable { // We shouldn't emit the vtable for this code, in any ABI. If we emit the // vtable, we emit an implicit virtual dtor, which calls ~RefPtr, which requires // a complete type for DeclaredOnly. // // Previously we would reference the vtable in the MS C++ ABI, even though we // don't need to emit either the ctor or the dtor. In the Itanium C++ ABI, the // 'trace' method is the key function, so even though we use the vtable, we // don't emit it. template <typename T> struct RefPtr { T *m_ptr; ~RefPtr() { m_ptr->deref(); } }; struct DeclaredOnly; struct Base { virtual ~Base(); }; struct AvoidVTable : Base { RefPtr<DeclaredOnly> m_insertionStyle; virtual void trace(); AvoidVTable(); }; // Don't call the dtor, because that will emit an implicit dtor, and require a // complete type for DeclaredOnly. void foo() { new AvoidVTable; } } namespace vtable_uses_incomplete { // Opposite of the previous test that avoids a vtable, this one tests that we // use the vtable when the ctor is defined inline. template <typename T> struct RefPtr { T *m_ptr; ~RefPtr() { m_ptr->deref(); } // expected-error {{member access into incomplete type 'vtable_uses_incomplete::DeclaredOnly'}} }; struct DeclaredOnly; // expected-note {{forward declaration of 'vtable_uses_incomplete::DeclaredOnly'}} struct Base { virtual ~Base(); }; struct UsesVTable : Base { RefPtr<DeclaredOnly> m_insertionStyle; virtual void trace(); UsesVTable() {} // expected-note {{in instantiation of member function 'vtable_uses_incomplete::RefPtr<vtable_uses_incomplete::DeclaredOnly>::~RefPtr' requested here}} }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-default-3.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics template<typename T> struct A { }; template<typename T, typename U = A<T*> > struct B : U { }; template<> struct A<int*> { void foo(); }; template<> struct A<float*> { void bar(); }; void test(B<int> *b1, B<float> *b2) { b1->foo(); b2->bar(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/recovery-crash.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // Clang used to crash trying to recover while adding 'this->' before Work(x); template <typename> struct A { static void Work(int); // expected-note{{must qualify identifier}} }; template <typename T> struct B : public A<T> { template <typename T2> B(T2 x) { Work(x); // expected-error{{use of undeclared identifier}} } }; void Test() { B<int> b(0); // expected-note{{in instantiation of function template}} } // Don't crash here. namespace PR16134 { template <class P> struct S // expected-error {{expected ';'}} template <> static S<Q>::f() // expected-error +{{}} } namespace PR16225 { template <typename T> void f(); template<typename C> void g(C*) { struct LocalStruct : UnknownBase<Mumble, C> { }; // expected-error {{unknown template name 'UnknownBase'}} \ // expected-error {{use of undeclared identifier 'Mumble'}} f<LocalStruct>(); // expected-warning {{template argument uses local type 'LocalStruct'}} } struct S; void h() { g<S>(0); // expected-note {{in instantiation of function template specialization}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-sizeof.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s // expected-no-diagnostics // Make sure we handle contexts correctly with sizeof template<typename T> void f(T n) { int buffer[n]; [] { int x = sizeof(sizeof(buffer)); }(); } int main() { f<int>(1); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s namespace PR15360 { template<typename R, typename U, R F> U f() { return &F; } // expected-error{{cannot take the address of an rvalue of type 'int (*)(int)'}} expected-error{{cannot take the address of an rvalue of type 'int *'}} void test() { f<int(int), int(*)(int), nullptr>(); // expected-note{{in instantiation of}} f<int[3], int*, nullptr>(); // expected-note{{in instantiation of}} } } namespace CanonicalNullptr { template<typename T> struct get { typedef T type; }; struct X {}; template<typename T, typename get<T *>::type P = nullptr> struct A {}; template<typename T, typename get<decltype((T(), nullptr))>::type P = nullptr> struct B {}; template<typename T, typename get<T X::*>::type P = nullptr> struct C {}; template<typename T> A<T> MakeA(); template<typename T> B<T> MakeB(); template<typename T> C<T> MakeC(); A<int> a = MakeA<int>(); B<int> b = MakeB<int>(); C<int> c = MakeC<int>(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-subscript.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct Sub0 { int &operator[](int); }; struct Sub1 { long &operator[](long); // expected-note{{candidate function}} }; struct ConvertibleToInt { operator int(); }; template<typename T, typename U, typename Result> struct Subscript0 { void test(T t, U u) { Result &result = t[u]; // expected-error{{no viable overloaded operator[] for type}} } }; template struct Subscript0<int*, int, int&>; template struct Subscript0<Sub0, int, int&>; template struct Subscript0<Sub1, ConvertibleToInt, long&>; template struct Subscript0<Sub1, Sub0, long&>; // expected-note{{instantiation}} // PR5345 template <typename T> struct S { bool operator[](int n) const { return true; } }; template <typename T> void Foo(const S<int>& s, T x) { if (s[0]) {} } void Bar() { Foo(S<int>(), 0); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-typedef.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> struct add_pointer { typedef T* type; // expected-error{{'type' declared as a pointer to a reference}} }; add_pointer<int>::type test1(int * ptr) { return ptr; } add_pointer<float>::type test2(int * ptr) { return ptr; // expected-error{{cannot initialize return object of type 'add_pointer<float>::type' (aka 'float *') with an lvalue of type 'int *'}} } add_pointer<int&>::type // expected-note{{in instantiation of template class 'add_pointer<int &>' requested here}} test3();
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/pack-deduction.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s template<typename ...T> struct X {}; template<typename T, typename U> struct P {}; namespace Nested { template<typename ...T> int f1(X<T, T...>... a); // expected-note +{{conflicting types for parameter 'T'}} template<typename ...T> int f2(P<X<T...>, T> ...a); // expected-note +{{conflicting types for parameter 'T'}} int a1 = f1(X<int, int, double>(), X<double, int, double>()); int a2 = f1(X<int, int>()); int a3 = f1(X<int>(), X<double>()); // expected-error {{no matching}} int a4 = f1(X<int, int>(), X<int>()); // expected-error {{no matching}} int a5 = f1(X<int>(), X<int, int>()); // expected-error {{no matching}} int a6 = f1(X<int, int, int>(), X<int, int, int>(), X<int, int, int, int>()); // expected-error {{no matching}} int b1 = f2(P<X<int, double>, int>(), P<X<int, double>, double>()); int b2 = f2(P<X<int, double>, int>(), P<X<int, double>, double>(), P<X<int, double>, char>()); // expected-error {{no matching}} } namespace PR14841 { template<typename T, typename U> struct A {}; template<typename ...Ts> void f(A<Ts...>); // expected-note {{substitution failure [with Ts = <char, short, int>]: too many template arg}} void g(A<char, short> a) { f(a); f<char>(a); f<char, short>(a); f<char, short, int>(a); // expected-error {{no matching function}} } } namespace RetainExprPacks { int f(int a, int b, int c); template<typename ...Ts> struct X {}; template<typename ...Ts> int g(X<Ts...>, decltype(f(Ts()...))); int n = g<int, int>(X<int, int, int>(), 0); } namespace PR14615 { namespace comment0 { template <class A, class...> struct X {}; template <class... B> struct X<int, B...> { typedef int type; struct valid {}; }; template <typename A, typename... B, typename T = X<A, B...>, typename = typename T::valid> typename T::type check(int); int i = check<int, char>(1); } namespace comment2 { template <class...> struct X; template <typename... B, typename X<B...>::type I = 0> char check(B...); // expected-note {{undefined template 'PR14615::comment2::X<char, int>'}} void f() { check<char>(1, 2); } // expected-error {{no matching function}} } namespace comment3 { template <class...> struct X; template <typename... B, typename X<B...>::type I = (typename X<B...>::type)0> char check(B...); // expected-note {{undefined template 'PR14615::comment3::X<char, int>'}} void f() { check<char>(1, 2); } // expected-error {{no matching function}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/class-template-id-2.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace N { template<typename T> class A { }; template<> class A<int> { }; template<> class A<float>; // expected-note{{forward declaration of 'N::A<float>'}} class B : public A<int> { }; } class C1 : public N::A<int> { }; class C2 : public N::A<float> { }; // expected-error{{base class has incomplete type}} struct D1 { operator N::A<int>(); }; namespace N { struct D2 { operator A<int>(); }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-c99.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // Test template instantiation for C99-specific features. // --------------------------------------------------------------------- // Designated initializers // --------------------------------------------------------------------- template<typename T, typename XType, typename YType> struct DesigInit0 { void f(XType x, YType y) { T agg = { .y = y, // expected-error{{does not refer}} .x = x // expected-error{{does not refer}} }; } }; struct Point2D { float x, y; }; template struct DesigInit0<Point2D, int, double>; struct Point3D { float x, y, z; }; template struct DesigInit0<Point3D, int, double>; struct Color { unsigned char red, green, blue; }; struct ColorPoint3D { Color color; float x, y, z; }; template struct DesigInit0<ColorPoint3D, int, double>; template struct DesigInit0<Color, int, double>; // expected-note{{instantiation}} template<typename T, int Subscript1, int Subscript2, typename Val1, typename Val2> struct DesigArrayInit0 { void f(Val1 val1, Val2 val2) { T array = { [Subscript1] = val1, [Subscript2] = val2 // expected-error{{exceeds array bounds}} }; int array2[10] = { [5] = 3 }; } }; template struct DesigArrayInit0<int[8], 5, 3, float, int>; template struct DesigArrayInit0<int[8], 5, 13, float, int>; // expected-note{{instantiation}} template<typename T, int Subscript1, int Subscript2, typename Val1> struct DesigArrayRangeInit0 { void f(Val1 val1) { T array = { [Subscript1...Subscript2] = val1 // expected-error{{exceeds}} }; } }; template struct DesigArrayRangeInit0<int[8], 3, 5, float>; template struct DesigArrayRangeInit0<int[8], 5, 13, float>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // Compound literals // --------------------------------------------------------------------- template<typename T, typename Arg1, typename Arg2> struct CompoundLiteral0 { T f(Arg1 a1, Arg2 a2) { return (T){a1, a2}; } }; template struct CompoundLiteral0<Point2D, int, float>;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-field.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> struct X { int x; T y; // expected-error{{data member instantiated with function type}} T* z; T bitfield : 12; // expected-error{{bit-field 'bitfield' has non-integral type 'float'}} \ // expected-error{{data member instantiated with function type}} mutable T x2; // expected-error{{data member instantiated with function type}} }; void test1(const X<int> *xi) { int i1 = xi->x; const int &i2 = xi->y; int* ip1 = xi->z; int i3 = xi->bitfield; xi->x2 = 17; } void test2(const X<float> *xf) { (void)xf->x; // expected-note{{in instantiation of template class 'X<float>' requested here}} } void test3(const X<int(int)> *xf) { (void)xf->x; // expected-note{{in instantiation of template class 'X<int (int)>' requested here}} } namespace PR7123 { template <class > struct requirement_; template <void(*)()> struct instantiate { }; template <class > struct requirement ; struct failed ; template <class Model> struct requirement<failed *Model::*> { static void failed() { ((Model*)0)->~Model(); // expected-note{{in instantiation of}} } }; template <class Model> struct requirement_<void(*)(Model)> : requirement<failed *Model::*> { }; template <int> struct Requires_ { typedef void type; }; template <class Model> struct usage_requirements { ~usage_requirements() {((Model*)0)->~Model(); } // expected-note{{in instantiation of}} }; template < typename TT > struct BidirectionalIterator { enum { value = 0 }; instantiate< requirement_<void(*)(usage_requirements<BidirectionalIterator>)>::failed> int534; // expected-note{{in instantiation of}} ~BidirectionalIterator() { i--; } // expected-error{{cannot decrement value of type 'PR7123::X'}} TT i; }; struct X { }; template<typename RanIter> typename Requires_< BidirectionalIterator<RanIter>::value >::type sort(RanIter,RanIter){} void f() { X x; sort(x,x); } } namespace PR7355 { template<typename T1> class A { class D; // expected-note{{declared here}} D d; //expected-error{{implicit instantiation of undefined member 'PR7355::A<int>::D'}} }; A<int> ai; // expected-note{{in instantiation of}} } namespace PR8712 { template <int dim> class B { public: B(const unsigned char i); unsigned char value : (dim > 0 ? dim : 1); }; template <int dim> inline B<dim>::B(const unsigned char i) : value(i) {} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/crash-unparsed-exception.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -fcxx-exceptions -fexceptions %s struct A { virtual ~A(); }; template <class> struct B {}; struct C { template <typename> struct D { ~D() throw(); }; struct E : A { D<int> d; //expected-error{{exception specification is not available until end of class definition}} }; B<int> b; //expected-note{{in instantiation of template class 'B<int>' requested here}} };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/partial-spec-instantiate.cpp
// RUN: %clang_cc1 -fsyntax-only %s // PR4607 template <class T> struct X {}; template <> struct X<char> { static char* g(); }; template <class T> struct X2 {}; template <class U> struct X2<U*> { static void f() { X<U>::g(); } }; void a(char *a, char *b) {X2<char*>::f();} namespace WonkyAccess { template<typename T> struct X { int m; }; template<typename U> class Y; template<typename U> struct Y<U*> : X<U> { }; template<> struct Y<float*> : X<float> { }; int f(Y<int*> y, Y<float*> y2) { return y.m + y2.m; } } // <rdar://problem/9169404> namespace rdar9169404 { template<typename T, T N> struct X { }; template<bool C> struct X<bool, C> { typedef int type; }; X<bool, -1>::type value; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-expr-basic.cpp
// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -std=c++11 %s template <typename T> struct S { void f() { __func__; // PredefinedExpr 10; // IntegerLiteral 10.5; // FloatingLiteral 'c'; // CharacterLiteral "hello"; // StringLiteral true; // CXXBooleanLiteralExpr nullptr; // CXXNullPtrLiteralExpr __null; // GNUNullExpr } }; template struct S<int>;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-function-params.cpp
// RUN: %clang_cc1 -triple i686-unknown-unknown -fsyntax-only -verify %s // PR6619 template<bool C> struct if_c { }; template<typename T1> struct if_ { typedef if_c< static_cast<bool>(T1::value)> almost_type_; // expected-note 5{{in instantiation}} }; template <class Model, void (Model::*)()> struct wrap_constraints { }; template <class Model> inline char has_constraints_(Model* , // expected-note 3{{candidate template ignored}} wrap_constraints<Model,&Model::constraints>* = 0); // expected-note 2{{in instantiation}} template <class Model> struct not_satisfied { static const bool value = sizeof( has_constraints_((Model*)0) == 1); // expected-error 3{{no matching function}} \ // expected-note 2{{while substituting deduced template arguments into function template 'has_constraints_' [with }} }; template <class ModelFn> struct requirement_; template <void(*)()> struct instantiate { }; template <class Model> struct requirement_<void(*)(Model)> : if_< not_satisfied<Model> >::type { // expected-note 5{{in instantiation}} }; template <class Model> struct usage_requirements { }; template < typename TT > struct InputIterator { typedef instantiate< & requirement_<void(*)(usage_requirements<InputIterator> x)>::failed> boost_concept_check1; // expected-note {{in instantiation}} }; template < typename TT > struct ForwardIterator : InputIterator<TT> { // expected-note {{in instantiation}} typedef instantiate< & requirement_<void(*)(usage_requirements<ForwardIterator> x)>::failed> boost_concept_check2; // expected-note {{in instantiation}} }; typedef instantiate< &requirement_<void(*)(ForwardIterator<char*> x)>::failed> boost_concept_checkX;// expected-note 3{{in instantiation}} template<typename T> struct X0 { }; template<typename R, typename A1> struct X0<R(A1 param)> { }; template<typename T, typename A1, typename A2> void instF0(X0<T(A1)> x0a, X0<T(A2)> x0b) { X0<T(A1)> x0c; X0<T(A2)> x0d; } template void instF0<int, int, float>(X0<int(int)>, X0<int(float)>); template<typename R, typename A1, R (*ptr)(A1)> struct FuncPtr { }; template<typename A1, int (*ptr)(A1)> struct FuncPtr<int, A1, ptr> { }; template<typename R, typename A1> R unary_func(A1); template<typename R, typename A1, typename A2> void use_func_ptr() { FuncPtr<R, A1, &unary_func<R, A1> > fp1; FuncPtr<R, A2, &unary_func<R, A2> > fp2; }; template void use_func_ptr<int, float, double>(); namespace PR6990 { template < typename , typename = int, typename = int > struct X1; template <typename > struct X2; template <typename = int *, typename TokenT = int, typename = int( X2<TokenT> &)> struct X3 { }; template <typename , typename P> struct X3_base : X3< X1<int, P> > { protected: typedef X1< P> type; X3<type> e; }; struct r : X3_base<int, int> { }; } namespace InstantiateFunctionTypedef { template<typename T> struct X { typedef int functype(int, int); functype func1; __attribute__((noreturn)) functype func2; typedef int stdfunctype(int, int) __attribute__((stdcall)); __attribute__((stdcall)) functype stdfunc1; stdfunctype stdfunc2; __attribute__((pcs("aapcs"))) functype pcsfunc; // expected-warning {{calling convention 'pcs' ignored for this target}} }; void f(X<int> x) { (void)x.func1(1, 2); (void)x.func2(1, 2); (void)x.stdfunc1(1, 2); (void)x.stdfunc2(1, 2); (void)x.pcsfunc(1, 2); } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/overloaded-functions.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace { template <bool, typename> void Foo() {} template <int size> void Foo() { int arr[size]; // expected-error@-1 {{'arr' declared as an array with a negative size}} } } void test_foo() { Foo<-1>(); // expected-note@-1 {{in instantiation of function template specialization '(anonymous namespace)::Foo<-1>' requested here}} } template <bool, typename> void Bar() {} template <int size> void Bar() { int arr[size]; // expected-error@-1 {{'arr' declared as an array with a negative size}} } void test_bar() { Bar<-1>(); // expected-note@-1 {{in instantiation of function template specialization 'Bar<-1>' requested here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/nested-incomplete-class.cpp
// RUN: %clang_cc1 -fsyntax-only %s template <typename T> struct foo { struct bar; bar fn() { // Should not get errors about bar being incomplete here. bar b = bar(1, 2); return b; } }; template <typename T> struct foo<T>::bar { bar(int, int); }; void fn() { foo<int>().fn(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ms-sizeof-missing-typename.cpp
// RUN: %clang_cc1 -std=c++11 -fms-compatibility -fsyntax-only -verify %s // If we were even more clever, we'd tell the user to use one set of parens to // get the size of this type, so they don't get errors after inserting typename. namespace basic { template <typename T> int type_f() { return sizeof T::type; } // expected-error {{missing 'typename' prior to dependent type name 'X::type'}} template <typename T> int type_g() { return sizeof(T::type); } // expected-warning {{missing 'typename' prior to dependent type name 'X::type'}} template <typename T> int type_h() { return sizeof((T::type)); } // expected-error {{missing 'typename' prior to dependent type name 'X::type'}} template <typename T> int value_f() { return sizeof T::not_a_type; } template <typename T> int value_g() { return sizeof(T::not_a_type); } template <typename T> int value_h() { return sizeof((T::not_a_type)); } struct X { typedef int type; static const int not_a_type; }; int bar() { return type_f<X>() + // expected-note-re {{in instantiation {{.*}} requested here}} type_g<X>() + // expected-note-re {{in instantiation {{.*}} requested here}} type_h<X>() + // expected-note-re {{in instantiation {{.*}} requested here}} value_f<X>() + value_f<X>() + value_f<X>(); } } namespace nested_sizeof { template <typename T> struct Foo { enum { // expected-warning@+2 {{use 'template' keyword to treat 'InnerTemplate' as a dependent template name}} // expected-warning@+1 {{missing 'typename' prior to dependent type name 'Bar::InnerType'}} x1 = sizeof(typename T::/*template*/ InnerTemplate<sizeof(/*typename*/ T::InnerType)>), // expected-warning@+1 {{missing 'typename' prior to dependent type name 'Bar::InnerType'}} x2 = sizeof(typename T::template InnerTemplate<sizeof(/*typename*/ T::InnerType)>), // expected-warning@+1 {{use 'template' keyword to treat 'InnerTemplate' as a dependent template name}} y1 = sizeof(typename T::/*template*/ InnerTemplate<sizeof(T::InnerVar)>), y2 = sizeof(typename T::template InnerTemplate<sizeof(T::InnerVar)>), z = sizeof(T::template InnerTemplate<sizeof(T::InnerVar)>::x), }; }; struct Bar { template <int N> struct InnerTemplate { int x[N]; }; typedef double InnerType; static const int InnerVar = 42; }; template struct Foo<Bar>; // expected-note-re {{in instantiation {{.*}} requested here}} } namespace ambiguous_missing_parens { // expected-error@+1 {{'Q::U' instantiated to a class template, not a function template}} template <typename T> void f() { int a = sizeof T::template U<0> + 4; } struct Q { // expected-error@+1 {{class template declared here}} template <int> struct U {}; }; // expected-note-re@+1 {{in instantiation {{.*}} requested here}} template void f<Q>(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/qualified-names-diag.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace std { template<typename T> class vector { }; // expected-note{{candidate}} } typedef int INT; typedef float Real; void test() { using namespace std; std::vector<INT> v1; vector<Real> v2; v1 = v2; // expected-error{{no viable overloaded '='}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-order.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s // From core issue 1227. template <class T> struct A { using X = typename T::X; }; // expected-error {{no members}} template <class T> typename T::X f(typename A<T>::X); template <class T> void f(...) {} template <class T> auto g(typename A<T>::X) -> typename T::X; // expected-note {{here}} template <class T> void g(...) {} void h() { f<int>(0); // ok, SFINAE in return type g<int>(0); // not ok, substitution inside A<int> is a hard error // expected-note {{substituting}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-elab-type-specifier.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // PR5681 template <class T> struct Base { struct foo {}; int foo; }; template <class T> struct Derived : Base<T> { typedef struct Base<T>::foo type; }; template struct Derived<int>;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/member-initializers.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics template<typename T> struct A { A() : j(10), i(10) { } int i; int j; }; template<typename T> struct B : A<T> { B() : A<T>() { } };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-member-class.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace PR8965 { template<typename T> struct X { typedef int type; T field; // expected-note{{in instantiation of member class}} }; template<typename T> struct Y { struct Inner; typedef typename X<Inner>::type // expected-note{{in instantiation of template class}} type; // expected-note{{not-yet-instantiated member is declared here}} struct Inner { typedef type field; // expected-error{{no member 'type' in 'PR8965::Y<int>'; it has not yet been instantiated}} }; }; Y<int> y; // expected-note{{in instantiation of template class}} } template<typename T> class X { public: struct C { T &foo(); }; struct D { struct E { T &bar(); }; // expected-error{{cannot form a reference to 'void'}} struct F; // expected-note{{member is declared here}} }; }; X<int>::C *c1; X<float>::C *c2; X<int>::X *xi; // expected-error{{qualified reference to 'X' is a constructor name rather than a type wherever a constructor can be declared}} X<float>::X *xf; // expected-error{{qualified reference to 'X' is a constructor name rather than a type wherever a constructor can be declared}} void test_naming() { c1 = c2; // expected-error{{assigning to 'X<int>::C *' from incompatible type 'X<float>::C *'}} xi = xf; // expected-error{{assigning to 'X<int>::X<int> *' from incompatible type 'X<float>::X<float> *'}} // FIXME: error above doesn't print the type X<int>::X cleanly! } void test_instantiation(X<double>::C *x, X<float>::D::E *e, X<float>::D::F *f) { double &dr = x->foo(); float &fr = e->bar(); f->foo(); // expected-error{{implicit instantiation of undefined member 'X<float>::D::F'}} } X<void>::C *c3; // okay X<void>::D::E *e1; // okay X<void>::D::E e2; // expected-note{{in instantiation of member class 'X<void>::D::E' requested here}} // Redeclarations. namespace test1 { template <typename T> struct Registry { struct node; static node *Head; struct node { node(int v) { Head = this; } }; }; void test() { Registry<int>::node node(0); } } // Redeclarations during explicit instantiations. namespace test2 { template <typename T> class A { class Foo; class Foo { int foo(); }; }; template class A<int>; template <typename T> class B { class Foo; class Foo { public: typedef int X; }; typename Foo::X x; }; template class B<int>; template <typename T> class C { class Foo; }; template <typename T> class C<T>::Foo { int x; }; template class C<int>; } namespace AliasTagDef { template<typename T> struct F { using S = struct U { // expected-warning {{C++11}} T g() { return T(); } }; }; int m = F<int>::S().g(); int n = F<int>::U().g(); } namespace rdar10397846 { template<int I> struct A { struct B { struct C { C() { int *ptr = I; } }; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} \ expected-warning{{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} }; }; template<int N> void foo() { class A<N>::B::C X; // expected-note 2 {{in instantiation of member function}} int A<N+1>::B::C::*member = 0; } void bar() { foo<0>(); // expected-note{{in instantiation of function template}} foo<1>(); // expected-note{{in instantiation of function template}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/exception-spec-crash.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -DCXX_EXCEPTIONS -fsyntax-only -verify %s template <class _Tp> struct is_nothrow_move_constructible { static const bool value = false; }; template <class _Tp> class allocator; template <> class allocator<char> {}; template <class _Allocator> class basic_string { typedef _Allocator allocator_type; basic_string(basic_string &&__str) noexcept(is_nothrow_move_constructible<allocator_type>::value); }; class Foo { Foo(Foo &&) noexcept = default; #ifdef CXX_EXCEPTIONS // expected-error@-2 {{does not match the calculated}} #else // expected-no-diagnostics #endif Foo &operator=(Foo &&) noexcept = default; basic_string<allocator<char> > vectorFoo_; };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/copy-ctor-assign.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // Make sure that copy constructors and assignment operators are properly // generated when there is a matching // PR5072 template<typename T> struct X { template<typename U> X(const X<U>& other) : value(other.value + 1) { } // expected-error{{binary expression}} template<typename U> X& operator=(const X<U>& other) { value = other.value + 1; // expected-error{{binary expression}} return *this; } T value; }; struct Y {}; X<int Y::*> test0(X<int Y::*> x) { return x; } X<int> test1(X<long> x) { return x; } X<int> test2(X<int Y::*> x) { return x; // expected-note{{instantiation}} } void test3(X<int> &x, X<int> xi, X<long> xl, X<int Y::*> xmptr) { x = xi; x = xl; x = xmptr; // expected-note{{instantiation}} } struct X1 { X1 &operator=(const X1&); }; template<typename T> struct X2 : X1 { template<typename U> X2 &operator=(const U&); }; struct X3 : X2<int> { }; void test_X2(X3 &to, X3 from) { to = from; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-array.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 // expected-no-diagnostics #ifndef __GXX_EXPERIMENTAL_CXX0X__ #define __CONCAT(__X, __Y) __CONCAT1(__X, __Y) #define __CONCAT1(__X, __Y) __X ## __Y #define static_assert(__b, __m) \ typedef int __CONCAT(__sa, __LINE__)[__b ? 1 : -1] #endif template <int N> class IntArray { int elems[N]; }; static_assert(sizeof(IntArray<10>) == sizeof(int) * 10, "Array size mismatch"); static_assert(sizeof(IntArray<1>) == sizeof(int) * 1, "Array size mismatch"); template <typename T> class TenElementArray { int elems[10]; }; static_assert(sizeof(TenElementArray<int>) == sizeof(int) * 10, "Array size mismatch"); template<typename T, int N> class Array { T elems[N]; }; static_assert(sizeof(Array<int, 10>) == sizeof(int) * 10, "Array size mismatch");
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-expr-3.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // --------------------------------------------------------------------- // Imaginary literals // --------------------------------------------------------------------- template<typename T> struct ImaginaryLiteral0 { void f(T &x) { x = 3.0I; // expected-error{{incompatible type}} } }; template struct ImaginaryLiteral0<_Complex float>; template struct ImaginaryLiteral0<int*>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // Compound assignment operator // --------------------------------------------------------------------- namespace N1 { struct X { }; int& operator+=(X&, int); // expected-note{{candidate}} } namespace N2 { long& operator+=(N1::X&, long); // expected-note{{candidate}} template<typename T, typename U, typename Result> struct PlusEquals0 { void f(T t, U u) { Result r = t += u; // expected-error{{ambiguous}} } }; } namespace N3 { struct Y : public N1::X { short& operator+=(long); // expected-note{{candidate}} }; } template struct N2::PlusEquals0<N1::X, int, int&>; template struct N2::PlusEquals0<N1::X, long, long&>; template struct N2::PlusEquals0<N3::Y, long, short&>; template struct N2::PlusEquals0<int, int, int&>; template struct N2::PlusEquals0<N3::Y, int, short&>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // Conditional operator // --------------------------------------------------------------------- template<typename T, typename U, typename Result> struct Conditional0 { void f(T t, U u) { Result result = t? : u; } }; template struct Conditional0<int, int, int>; // --------------------------------------------------------------------- // Statement expressions // --------------------------------------------------------------------- template<typename T> struct StatementExpr0 { void f(T t) { (void)({ if (t) // expected-error{{contextually convertible}} t = t + 17; t + 12; // expected-error{{invalid operands}} }); } }; template struct StatementExpr0<int>; template struct StatementExpr0<N1::X>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // __builtin_choose_expr // --------------------------------------------------------------------- template<bool Cond, typename T, typename U, typename Result> struct Choose0 { void f(T t, U u) { Result r = __builtin_choose_expr(Cond, t, u); // expected-error{{lvalue}} } }; template struct Choose0<true, int, float, int&>; template struct Choose0<false, int, float, float&>; template struct Choose0<true, int, float, float&>; // expected-note{{instantiation}} // --------------------------------------------------------------------- // __builtin_va_arg // --------------------------------------------------------------------- template<typename ArgType> struct VaArg0 { void f(int n, ...) { __builtin_va_list va; __builtin_va_start(va, n); for (int i = 0; i != n; ++i) (void)__builtin_va_arg(va, ArgType); __builtin_va_end(va); } }; template struct VaArg0<int>; template<typename VaList, typename ArgType> struct VaArg1 { void f(int n, ...) { VaList va; __builtin_va_start(va, n); // expected-error{{int}} for (int i = 0; i != n; ++i) (void)__builtin_va_arg(va, ArgType); // expected-error{{int}} __builtin_va_end(va); // expected-error{{int}} } }; template struct VaArg1<__builtin_va_list, int>; template struct VaArg1<int, int>; // expected-note{{instantiation}}