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/instantiate-function-1.cpp
|
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
template<typename T, typename U>
struct X0 {
void f(T x, U y) {
(void)(x + y); // expected-error{{invalid operands}}
}
};
struct X1 { };
template struct X0<int, float>;
template struct X0<int*, int>;
template struct X0<int X1::*, int>; // expected-note{{instantiation of}}
template<typename T>
struct X2 {
void f(T);
T g(T x, T y) {
/* DeclStmt */;
T *xp = &x, &yr = y; // expected-error{{pointer to a reference}}
/* NullStmt */;
}
};
template struct X2<int>;
template struct X2<int&>; // expected-note{{instantiation of}}
template<typename T>
struct X3 {
void f(T) {
Label:
T x;
goto Label;
}
};
template struct X3<int>;
template <typename T> struct X4 {
T f() const {
return; // expected-error{{non-void function 'f' should return a value}}
}
T g() const {
return 1; // expected-error{{void function 'g' should not return a value}}
}
};
template struct X4<void>; // expected-note{{in instantiation of}}
template struct X4<int>; // expected-note{{in instantiation of}}
struct Incomplete; // expected-note 2{{forward declaration}}
template<typename T> struct X5 {
T f() { } // expected-error{{incomplete result type}}
};
void test_X5(X5<Incomplete> x5); // okay!
template struct X5<Incomplete>; // expected-note{{instantiation}}
template<typename T, typename U, typename V> struct X6 {
U f(T t, U u, V v) {
// IfStmt
if (t > 0)
return u;
else {
if (t < 0)
return v; // expected-error{{cannot initialize return object of type}}
}
if (T x = t) {
t = x;
}
return v; // expected-error{{cannot initialize return object of type}}
}
};
struct ConvertibleToInt {
operator int() const;
};
template struct X6<ConvertibleToInt, float, char>;
template struct X6<bool, int, int*>; // expected-note{{instantiation}}
template <typename T> struct X7 {
void f() {
void *v = this;
}
};
template struct X7<int>;
template<typename T> struct While0 {
void f(T t) {
while (t) {
}
while (T t2 = T()) ;
}
};
template struct While0<float>;
template<typename T> struct Do0 {
void f(T t) {
do {
} while (t); // expected-error{{not contextually}}
}
};
struct NotConvertibleToBool { };
template struct Do0<ConvertibleToInt>;
template struct Do0<NotConvertibleToBool>; // expected-note{{instantiation}}
template<typename T> struct For0 {
void f(T f, T l) {
for (; f != l; ++f) {
if (*f)
continue;
else if (*f == 17)
break;
}
}
};
template struct For0<int*>;
template<typename T> struct Member0 {
void f(T t) {
t;
t.f;
t->f;
T* tp;
tp.f; // expected-error{{member reference base type 'T *' is not a structure or union}}
tp->f;
this->f;
this.f; // expected-error{{member reference base type 'Member0<T> *' is not a structure or union}}
}
};
template<typename T, typename U> struct Switch0 {
U f(T value, U v0, U v1, U v2) {
switch (value) {
case 0: return v0;
case 1: return v1;
case 2: // fall through
default:
return v2;
}
}
};
template struct Switch0<int, float>;
template<typename T, int I1, int I2> struct Switch1 {
T f(T x, T y, T z) {
switch (x) {
case I1: return y; // expected-note{{previous}}
case I2: return z; // expected-error{{duplicate}}
default: return x;
}
}
};
template struct Switch1<int, 1, 2>;
template struct Switch1<int, 2, 2>; // expected-note{{instantiation}}
template<typename T> struct IndirectGoto0 {
void f(T x) {
// FIXME: crummy error message below
goto *x; // expected-error{{incompatible}}
prior:
T prior_label;
prior_label = &&prior; // expected-error{{assigning to 'int'}}
T later_label;
later_label = &&later; // expected-error{{assigning to 'int'}}
later:
(void)(1+1);
}
};
template struct IndirectGoto0<void*>;
template struct IndirectGoto0<int>; // expected-note{{instantiation}}
template<typename T> struct TryCatch0 {
void f() {
try {
} catch (T t) { // expected-error{{incomplete type}} \
// expected-error{{abstract class}}
} catch (...) {
}
}
};
struct Abstract {
virtual void foo() = 0; // expected-note{{pure virtual}}
};
template struct TryCatch0<int>; // okay
template struct TryCatch0<Incomplete*>; // expected-note{{instantiation}}
template struct TryCatch0<Abstract>; // expected-note{{instantiation}}
// PR4383
template<typename T> struct X;
template<typename T> struct Y : public X<T> {
Y& x() { return *this; }
};
// Make sure our assertions don't get too uppity.
namespace test0 {
template <class T> class A { void foo(T array[10]); };
template class A<int>;
}
namespace PR7016 {
template<typename T> void f() { T x = x; }
template void f<int>();
}
namespace PR9880 {
struct lua_State;
struct no_tag { char a; }; // (A)
struct yes_tag { long a; long b; }; // (A)
template <typename T>
struct HasIndexMetamethod {
template <typename U>
static no_tag check(...);
template <typename U>
static yes_tag check(char[sizeof(&U::luaIndex)]);
enum { value = sizeof(check<T>(0)) == sizeof(yes_tag) };
};
class SomeClass {
public:
int luaIndex(lua_State* L);
};
int i = HasIndexMetamethod<SomeClass>::value;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/enum-forward.cpp
|
// RUN: %clang_cc1 -fsyntax-only -fms-compatibility %s
template<typename T>
struct X {
enum E *e;
};
X<int> xi;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_func_order.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
int &f0(T);
template<typename T>
float &f0(T*);
void test_f0(int i, int *ip) {
int &ir = f0(i);
float &fr = f0(ip);
}
template<typename T, typename U>
int &f1(T, U);
template<typename T>
float &f1(T, T);
void test_f1(int i, float f) {
int &ir = f1(i, f);
float &fr1 = f1(i, i);
float &fr2 = f1(f, f);
}
template<typename T, typename U>
struct A { };
template<typename T>
int &f2(T);
template<typename T, typename U>
float &f2(A<T, U>);
template<typename T>
double &f2(A<T, T>);
void test_f2(int i, A<int, float> aif, A<int, int> aii) {
int &ir = f2(i);
float &fr = f2(aif);
double &dr = f2(aii);
}
template<typename T, typename U>
int &f3(T*, U); // expected-note{{candidate}}
template<typename T, typename U>
float &f3(T, U*); // expected-note{{candidate}}
void test_f3(int i, int *ip, float *fp) {
int &ir = f3(ip, i);
float &fr = f3(i, fp);
f3(ip, ip); // expected-error{{ambiguous}}
}
template<typename T>
int &f4(T&);
template<typename T>
float &f4(const T&);
void test_f4(int i, const int ic) {
int &ir1 = f4(i);
float &fr1 = f4(ic);
}
template<typename T, typename U>
int &f5(T&, const U&); // expected-note{{candidate}}
template<typename T, typename U>
float &f5(const T&, U&); // expected-note{{candidate}}
void test_f5(int i, const int ic) {
f5(i, i); // expected-error{{ambiguous}}
}
template<typename T, typename U>
int &f6(T&, U&);
template<typename T, typename U>
float &f6(const T&, U&);
void test_f6(int i, const int ic) {
int &ir = f6(i, i);
float &fr = f6(ic, ic);
}
struct CrazyFun {
template<typename T, typename U> operator A<T, U>();
template<typename T> operator A<T, T>();
};
void fun(CrazyFun cf) {
A<int, float> aif = cf;
A<int, int> aii = cf;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp
|
// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
// RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify %s
class A {
public:
template<class U> A(U p) {}
template<> A(int p) {
// expected-warning@-1 {{explicit specialization of 'A' within class scope is a Microsoft extension}}
}
template<class U> void f(U p) {}
template<> void f(int p) {
// expected-warning@-1 {{explicit specialization of 'f' within class scope is a Microsoft extension}}
}
void f(int p) {}
};
void test1() {
A a(3);
char *b;
a.f(b);
a.f<int>(99);
a.f(100);
}
template<class T> class B {
public:
template<class U> B(U p) {}
template<> B(int p) {
// expected-warning@-1 {{explicit specialization of 'B<T>' within class scope is a Microsoft extension}}
}
template<class U> void f(U p) { T y = 9; }
template<> void f(int p) {
// expected-warning@-1 {{explicit specialization of 'f' within class scope is a Microsoft extension}}
T a = 3;
}
void f(int p) { T a = 3; }
};
void test2() {
B<char> b(3);
char *ptr;
b.f(ptr);
b.f<int>(99);
b.f(100);
}
namespace PR12709 {
template<class T> class TemplateClass {
void member_function() { specialized_member_template<false>(); }
template<bool b> void specialized_member_template() {}
template<> void specialized_member_template<false>() {
// expected-warning@-1 {{explicit specialization of 'specialized_member_template' within class scope is a Microsoft extension}}
}
};
void f() { TemplateClass<int> t; }
}
namespace Duplicates {
template<typename T> struct A {
template<typename U> void f();
template<> void f<int>() {} // expected-warning {{Microsoft extension}}
template<> void f<T>() {} // expected-warning {{Microsoft extension}}
};
// FIXME: We should diagnose the duplicate explicit specialization definitions
// here.
template struct A<int>;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/operator-template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// Make sure we accept this
template<class X>struct A{typedef X Y;};
template<class X>bool operator==(A<X>,typename A<X>::Y); // expected-note{{candidate template ignored: could not match 'A<type-parameter-0-0>' against 'B<int> *'}}
int a(A<int> x) { return operator==(x,1); }
int a0(A<int> x) { return x == 1; }
// FIXME: the location information for the note isn't very good
template<class X>struct B{typedef X Y;};
template<class X>bool operator==(B<X>*,typename B<X>::Y); // \
// expected-error{{overloaded 'operator==' must have at least one parameter of class or enumeration type}} \
// expected-note{{candidate template ignored: substitution failure [with X = int]}}
int a(B<int> x) { return operator==(&x,1); } // expected-error{{no matching function for call to 'operator=='}} \
// expected-note{{in instantiation of function template specialization}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-init.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
struct X0 { // expected-note 8{{candidate}}
X0(int*, float*); // expected-note 4{{candidate}}
};
template<typename T, typename U>
X0 f0(T t, U u) {
X0 x0(t, u); // expected-error{{no matching}}
return X0(t, u); // expected-error{{no matching}}
}
void test_f0(int *ip, float *fp, double *dp) {
f0(ip, fp);
f0(ip, dp); // expected-note{{instantiation}}
}
template<typename Ret, typename T, typename U>
Ret f1(Ret *retty, T t, U u) {
Ret r0(t, u); // expected-error{{no matching}}
return Ret(t, u); // expected-error{{no matching}}
}
void test_f1(X0 *x0, int *ip, float *fp, double *dp) {
f1(x0, ip, fp);
f1(x0, ip, dp); // expected-note{{instantiation}}
}
namespace PR6457 {
template <typename T> struct X { explicit X(T* p = 0) { }; };
template <typename T> struct Y { Y(int, const T& x); };
struct A { };
template <typename T>
struct B {
B() : y(0, X<A>()) { }
Y<X<A> > y;
};
B<int> b;
}
namespace PR6657 {
struct X
{
X (int, int) { }
};
template <typename>
void f0()
{
X x = X(0, 0);
}
void f1()
{
f0<int>();
}
}
// Instantiate out-of-line definitions of static data members which complete
// types through an initializer even when the only use of the member that would
// cause instantiation is in an unevaluated context, but one requiring its
// complete type.
namespace PR10001 {
template <typename T> struct S {
static const int arr[];
static const int x;
static int f();
};
template <typename T> const int S<T>::arr[] = { 1, 2, 3 };
template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]);
template <typename T> int S<T>::f() { return x; }
int x = S<int>::f();
}
namespace PR7985 {
template<int N> struct integral_c { };
template <typename T, int N>
integral_c<N> array_lengthof(T (&x)[N]) { return integral_c<N>(); } // expected-note 2{{candidate template ignored: could not match 'T [N]' against 'const Data<}}
template<typename T>
struct Data {
T x;
};
template<typename T>
struct Description {
static const Data<T> data[];
};
template<typename T>
const Data<T> Description<T>::data[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}}
template<>
const Data<float*> Description<float*>::data[];
void test() {
integral_c<1> ic1 = array_lengthof(Description<int>::data);
(void)sizeof(array_lengthof(Description<float>::data));
sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
Description<int*>::data // expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}}
));
array_lengthof(Description<float*>::data); // expected-error{{no matching function for call to 'array_lengthof'}}
}
}
namespace PR13064 {
// Ensure that in-class direct-initialization is instantiated as
// direct-initialization and likewise copy-initialization is instantiated as
// copy-initialization.
struct A { explicit A(int); }; // expected-note{{here}}
template<typename T> struct B { T a { 0 }; };
B<A> b;
// expected-note@+1 {{in instantiation of default member initializer}}
template<typename T> struct C { T a = { 0 }; }; // expected-error{{explicit}}
C<A> c; // expected-note{{here}}
}
namespace PR16903 {
// Make sure we properly instantiate list-initialization.
template<typename T>
void fun (T it) {
int m = 0;
for (int i = 0; i < 4; ++i, ++it){
m |= long{char{*it}};
}
}
int test() {
char in[4] = {0,0,0,0};
fun(in);
}
}
namespace ReturnStmtIsInitialization {
struct X {
X() {}
X(const X &) = delete;
};
template<typename T> X f() { return {}; }
auto &&x = f<void>();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/extension-sfinae.cpp
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -verify %s -pedantic-errors -DPEDANTIC
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -verify %s -Wno-c++11-narrowing
namespace cce_narrowing {
decltype(short{123456}) a;
#if PEDANTIC
// expected-error@-2 {{cannot be narrowed}} expected-note@-2 {{cast}}
#endif
template<typename T> int f(decltype(T{123456})); // expected-note {{cannot be narrowed}}
int b = f<short>(0); // expected-error {{no match}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/function-template-specialization.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template <int N>
void f0(int (&array)[N]); // expected-note {{candidate template ignored: could not match 'int' against 'char'}}
// Simple function template specialization (using overloading)
template<> void f0(int (&array)[1]);
void test_f0() {
int iarr1[1];
f0(iarr1);
}
// Function template specialization where there are no matches
template<> void f0(char (&array)[1]); // expected-error{{no function template matches}}
template<> void f0<2>(int (&array)[2]) { }
// Function template specialization that requires partial ordering
template<typename T, int N> void f1(T (&array)[N]); // expected-note{{matches}}
template<int N> void f1(int (&array)[N]); // expected-note{{matches}}
template<> void f1(float (&array)[1]);
template<> void f1(int (&array)[1]);
// Function template specialization that results in an ambiguity
template<typename T> void f1(T (&array)[17]); // expected-note{{matches}}
template<> void f1(int (&array)[17]); // expected-error{{ambiguous}}
// Resolving that ambiguity with explicitly-specified template arguments.
template<int N> void f2(double (&array)[N]);
template<typename T> void f2(T (&array)[42]);
template<> void f2<double>(double (&array)[42]);
template<> void f2<42>(double (&array)[42]);
void f2<25>(double (&array)[25]); // expected-error{{specialization}}
// PR5833
namespace PR5833 {
template <typename T> bool f0(T &t1);
template <> bool f0<float>(float &t1);
}
template <> bool PR5833::f0<float>(float &t1) {}
// PR8295
namespace PR8295 {
template <typename T> void f(T t) {}
template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}}
}
class Foo {
template<class T>
static void Bar(const T& input);
// Don't crash here.
template<>
static void Bar(const long& input) {} // expected-error{{explicit specialization of 'Bar' in class scope}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ext_ms_template_spec.cpp
|
// RUN: %clang_cc1 -fsyntax-only -fms-extensions -std=c++11 -verify %s
namespace A {
template <class T>
class ClassTemplate; // expected-note {{explicitly specialized declaration is here}}
template <class T1, class T2>
class ClassTemplatePartial; // expected-note {{explicitly specialized declaration is here}}
template <typename T> struct X {
struct MemberClass; // expected-note {{explicitly specialized declaration is here}}
enum MemberEnumeration; // expected-note {{explicitly specialized declaration is here}} // expected-error {{ISO C++ forbids forward references to 'enum' types}}
};
}
namespace B {
template <>
class A::ClassTemplate<int>; // expected-warning {{class template specialization of 'ClassTemplate' outside namespace enclosing 'A' is a Microsoft extension}}
template <class T1>
class A::ClassTemplatePartial<T1, T1 *> {}; // expected-warning {{class template partial specialization of 'ClassTemplatePartial' outside namespace enclosing 'A' is a Microsoft extension}}
template <>
struct A::X<int>::MemberClass; // expected-warning {{member class specialization of 'MemberClass' outside namespace enclosing 'A' is a Microsoft extension}}
template <>
enum A::X<int>::MemberEnumeration; // expected-warning {{member enumeration specialization of 'MemberEnumeration' outside namespace enclosing 'A' is a Microsoft extension}} // expected-error {{ISO C++ forbids forward references to 'enum' types}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-names-no-std.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
//
// The whole point of this test is to verify certain diagnostics work in the
// absence of namespace 'std'.
namespace PR10053 {
namespace ns {
struct Data {};
}
template<typename T> struct A {
T t;
A() {
f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
}
};
void f(ns::Data); // expected-note {{in namespace 'PR10053::ns'}}
A<ns::Data> a; // expected-note {{in instantiation of member function}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/nested-name-spec-template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace N {
namespace M {
template<typename T> struct Promote;
template<> struct Promote<short> {
typedef int type;
};
template<> struct Promote<int> {
typedef int type;
};
template<> struct Promote<float> {
typedef double type;
};
Promote<short>::type *ret_intptr(int* ip) { return ip; }
Promote<int>::type *ret_intptr2(int* ip) { return ip; }
}
M::Promote<int>::type *ret_intptr3(int* ip) { return ip; }
M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } // expected-warning{{'template' keyword outside of a template}}
M::template Promote<int> pi; // expected-warning{{'template' keyword outside of a template}}
}
N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; }
::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; }
N::M::template; // expected-error{{expected unqualified-id}}
N::M::template Promote; // expected-error{{expected unqualified-id}}
namespace N {
template<typename T> struct A;
template<>
struct A<int> {
struct X;
};
struct B;
}
struct ::N::A<int>::X {
int foo;
};
template<typename T>
struct TestA {
typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}} \
// expected-error{{expected member name}}
};
// Reduced from a Boost failure.
namespace test1 {
template <class T> struct pair {
T x;
T y;
static T pair<T>::* const mem_array[2];
};
template <class T>
T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y };
}
typedef int T;
namespace N1 {
template<typename T> T f0();
}
template<typename T> T N1::f0() { }
namespace PR7385 {
template< typename > struct has_xxx0
{
template< typename > struct has_xxx0_introspect
{
template< typename > struct has_xxx0_substitute ;
template< typename V >
int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 );
};
static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}}
typedef int type;
};
has_xxx0<int>::type t; // expected-note{{instantiation of}}
}
namespace PR7725 {
template<class ignored> struct TypedefProvider;
template<typename T>
struct TemplateClass : public TypedefProvider<T>
{
void PrintSelf() {
TemplateClass::Test::PrintSelf();
}
};
}
namespace PR9226 {
template<typename a>
void nt() // expected-note{{function template 'nt' declared here}}
{ nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \
// expected-error{{expected unqualified-id}}
template<typename T>
void f(T*); // expected-note{{function template 'f' declared here}}
template<typename T>
void f(T*, T*); // expected-note{{function template 'f' declared here}}
void g() {
f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}}
} // expected-error{{expected unqualified-id}}
struct X {
template<typename T> void f(); // expected-note{{function template 'f' declared here}}
};
template<typename T, typename U>
struct Y {
typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'X::f'}}
};
Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}}
}
namespace PR9449 {
template <typename T>
struct s; // expected-note{{template is declared here}}
template <typename T>
void f() {
int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}} \
// expected-error{{following the 'template' keyword}}
}
template void f<int>(); // expected-note{{in instantiation of}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ambiguous-ovl-print.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
void f(void*, int); // expected-note{{candidate function}}
template<typename T>
void f(T*, long); // expected-note{{candidate function}}
void test_f(int *ip, int i) {
f(ip, i); // expected-error{{ambiguous}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/template-class-traits.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
#define T(b) (b) ? 1 : -1
#define F(b) (b) ? -1 : 1
struct HasVirt { virtual void a(); };
template<class T> struct InheritPolymorph : HasVirt {};
int t01[T(__is_polymorphic(InheritPolymorph<int>))];
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/constructor-template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct X0 { // expected-note{{candidate}}
X0(int); // expected-note{{candidate}}
template<typename T> X0(T); // expected-note {{candidate}}
template<typename T, typename U> X0(T*, U*); // expected-note {{candidate}}
// PR4761
template<typename T> X0() : f0(T::foo) {} // expected-note {{candidate}}
int f0;
};
void accept_X0(X0);
void test_X0(int i, float f) {
X0 x0a(i);
X0 x0b(f);
X0 x0c = i;
X0 x0d = f;
accept_X0(i);
accept_X0(&i);
accept_X0(f);
accept_X0(&f);
X0 x0e(&i, &f);
X0 x0f(&f, &i);
X0 x0g(f, &i); // expected-error{{no matching constructor}}
}
template<typename T>
struct X1 {
X1(const X1&);
template<typename U> X1(const X1<U>&);
};
template<typename T>
struct Outer {
typedef X1<T> A;
A alloc;
explicit Outer(const A& a) : alloc(a) { }
};
void test_X1(X1<int> xi) {
Outer<int> oi(xi);
Outer<float> of(xi);
}
// PR4655
template<class C> struct A {};
template <> struct A<int>{A(const A<int>&);};
struct B { A<int> x; B(B& a) : x(a.x) {} };
struct X2 {
X2(); // expected-note{{candidate constructor}}
X2(X2&); // expected-note {{candidate constructor}}
template<typename T> X2(T); // expected-note {{candidate template ignored: instantiation would take its own class type by value}}
};
X2 test(bool Cond, X2 x2) {
if (Cond)
return x2; // okay, uses copy constructor
return X2(); // expected-error{{no matching constructor}}
}
struct X3 {
template<typename T> X3(T);
};
template<> X3::X3(X3); // expected-error{{must pass its first argument by reference}}
struct X4 {
X4();
~X4();
X4(X4&);
template<typename T> X4(const T&, int = 17);
};
X4 test_X4(bool Cond, X4 x4) {
X4 a(x4, 17); // okay, constructor template
X4 b(x4); // okay, copy constructor
return X4();
}
// Instantiation of a non-dependent use of a constructor
struct DefaultCtorHasDefaultArg {
explicit DefaultCtorHasDefaultArg(int i = 17);
};
template<typename T>
void default_ctor_inst() {
DefaultCtorHasDefaultArg def;
}
template void default_ctor_inst<int>();
template<typename T>
struct X5 {
X5();
X5(const T &);
};
struct X6 {
template<typename T> X6(T);
};
void test_X5_X6() {
X5<X6> tf;
X5<X6> tf2(tf);
}
namespace PR8182 {
struct foo {
foo();
template<class T> foo(T&);
private:
foo(const foo&);
};
void test_foo() {
foo f1;
foo f2(f1);
foo f3 = f1;
}
}
// Don't blow out the stack trying to call an illegal constructor
// instantiation. We intentionally allow implicit instantiations to
// exist, so make sure they're unusable.
//
// rdar://19199836
namespace self_by_value {
template <class T, class U> struct A {
A() {}
A(const A<T,U> &o) {}
A(A<T,T> o) {}
};
void helper(A<int,float>);
void test1(A<int,int> a) {
helper(a);
}
void test2() {
helper(A<int,int>());
}
}
namespace self_by_value_2 {
template <class T, class U> struct A {
A() {} // expected-note {{not viable: requires 0 arguments}}
A(A<T,U> &o) {} // expected-note {{not viable: expects an l-value}}
A(A<T,T> o) {} // expected-note {{ignored: instantiation takes its own class type by value}}
};
void helper_A(A<int,int>); // expected-note {{passing argument to parameter here}}
void test_A() {
helper_A(A<int,int>()); // expected-error {{no matching constructor}}
}
}
namespace self_by_value_3 {
template <class T, class U> struct A {
A() {}
A(A<T,U> &o) {}
A(A<T,T> o) {}
};
void helper_A(A<int,int>);
void test_A(A<int,int> b) {
helper_A(b);
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/inject-templated-friend-post.cpp
|
// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DPROTOTYPE | FileCheck --check-prefix=CHECK-PROTOTYPE %s
// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DINSTANTIATE | FileCheck --check-prefix=CHECK-INSTANTIATE %s
// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DPROTOTYPE -DINSTANTIATE | FileCheck --check-prefix=CHECK-PROTOTYPE-INSTANTIATE %s
// RUN: %clang_cc1 %s -DREDEFINE -verify
// RUN: %clang_cc1 %s -DPROTOTYPE -DREDEFINE -verify
// PR8007: friend function not instantiated, reordered version.
// Corresponds to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38392
// CHECK: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE
// CHECK-PROTOTYPE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE
// CHECK-INSTANTIATE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE
// CHECK-PROTOTYPE-INSTANTIATE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE
struct std_ostream
{
int dummy;
};
std_ostream cout;
template <typename STRUCT_TYPE>
struct Streamer;
typedef struct Foo {} Foo;
inline std_ostream& operator << (std_ostream&, const Streamer<Foo>&);
void test(const Streamer<Foo>& foo)
{
cout << foo;
}
template <typename STRUCT_TYPE>
struct Streamer
{
friend std_ostream& operator << (std_ostream& o, const Streamer& f) // expected-error{{redefinition of 'operator<<'}}
{
Streamer s(f);
s(o);
return o;
}
Streamer(const STRUCT_TYPE& s) : s(s) {}
const STRUCT_TYPE& s;
void operator () (std_ostream&) const;
};
#ifdef PROTOTYPE
std_ostream& operator << (std_ostream&, const Streamer<Foo>&);
#endif
#ifdef INSTANTIATE
template struct Streamer<Foo>;
#endif
#ifdef REDEFINE
std_ostream& operator << (std_ostream& o, const Streamer<Foo>&) // expected-note{{is here}}
{
return o;
}
#endif
#ifndef INSTANTIATE
template <>
void Streamer<Foo>::operator () (std_ostream& o) const // expected-note{{requested here}}
{
}
#endif
int main(void)
{
Foo foo;
test(foo);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/enum-argument.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
enum Enum { val = 1 };
template <Enum v> struct C {
typedef C<v> Self;
};
template struct C<val>;
template<typename T>
struct get_size {
static const unsigned value = sizeof(T);
};
template<typename T>
struct X0 {
enum {
Val1 = get_size<T>::value,
Val2,
SumOfValues = Val1 + Val2
};
};
X0<int> x0i;
namespace rdar8020920 {
template<typename T>
struct X {
enum { e0 = 32 };
unsigned long long bitfield : e0;
void f(int j) {
bitfield + j;
}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_arg_template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<template<typename T> class X> struct A; // expected-note 2{{previous template template parameter is here}}
template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}}
template<template<int I> class X> struct C; // expected-note{{previous non-type template parameter with type 'int' is here}}
template<class> struct X; // expected-note{{too few template parameters in template template argument}}
template<int N> struct Y; // expected-note{{template parameter has a different kind in template argument}}
template<long N> struct Ylong; // expected-note{{template non-type parameter has a different type 'long' in template argument}}
namespace N {
template<class> struct Z;
}
template<class, class> struct TooMany; // expected-note{{too many template parameters in template template argument}}
A<X> *a1;
A<N::Z> *a2;
A< ::N::Z> *a3;
A<Y> *a4; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
A<TooMany> *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
B<X> *a6; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
C<Y> *a7;
C<Ylong> *a8; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
template<typename T> void f(int);
A<f> *a9; // expected-error{{must be a class template}}
// Evil digraph '<:' is parsed as '[', expect error.
A<::N::Z> *a10; // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
// Do not do a digraph correction here.
A<: :N::Z> *a11; // expected-error{{expected expression}} \
expected-error{{C++ requires a type specifier for all declarations}}
// PR7807
namespace N {
template <typename, typename = int>
struct X
{ };
template <typename ,int>
struct Y
{ X<int> const_ref(); };
template <template<typename,int> class TT, typename T, int N>
int operator<<(int, TT<T, N> a) { // expected-note{{candidate template ignored}}
0 << a.const_ref(); // expected-error{{invalid operands to binary expression ('int' and 'X<int>')}}
}
void f0( Y<int,1> y){ 1 << y; } // expected-note{{in instantiation of function template specialization 'N::operator<<<Y, int, 1>' requested here}}
}
// PR12179
template <typename Primitive, template <Primitive...> class F> // expected-warning {{variadic templates are a C++11 extension}}
struct unbox_args {
typedef typename Primitive::template call<F> x;
};
template <template <typename> class... Templates> // expected-warning {{variadic templates are a C++11 extension}}
struct template_tuple {};
template <typename T>
struct identity {};
template <template <typename> class... Templates> // expected-warning {{variadic templates are a C++11 extension}}
template_tuple<Templates...> f7() {}
void foo() {
f7<identity>();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/inject-templated-friend.cpp
|
// RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -o - | FileCheck %s
// RUN: %clang_cc1 %s -DREDEFINE -verify
// PR8007: friend function not instantiated.
// CHECK: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE
struct std_ostream
{
int dummy;
};
std_ostream cout;
template <typename STRUCT_TYPE>
struct Streamer
{
friend std_ostream& operator << (std_ostream& o, const Streamer& f) // expected-error{{redefinition of 'operator<<'}}
{
Streamer s(f);
s(o);
return o;
}
Streamer(const STRUCT_TYPE& s) : s(s) {}
const STRUCT_TYPE& s;
void operator () (std_ostream&) const;
};
typedef struct Foo {} Foo;
inline std_ostream& operator << (std_ostream&, const Streamer<Foo>&);
#ifdef REDEFINE
std_ostream& operator << (std_ostream& o, const Streamer<Foo>&) // expected-note{{is here}}
{
// Sema should flag this as a redefinition
return o;
}
#endif
template <>
void Streamer<Foo>::operator () (std_ostream& o) const // expected-note{{requested here}}
{
}
int main(void)
{
Foo foo;
cout << foo;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_arg_enum_printing.cpp
|
// RUN: %clang_cc1 -fsyntax-only -ast-print %s | FileCheck %s
namespace NamedEnumNS
{
enum NamedEnum
{
Val0,
Val1
};
template <NamedEnum E>
void foo();
void test() {
// CHECK: template <NamedEnumNS::NamedEnum E = NamedEnumNS::NamedEnum::Val0>
NamedEnumNS::foo<Val0>();
// CHECK: template <NamedEnumNS::NamedEnum E = NamedEnumNS::NamedEnum::Val1>
NamedEnumNS::foo<(NamedEnum)1>();
// CHECK: template <NamedEnumNS::NamedEnum E = 2>
NamedEnumNS::foo<(NamedEnum)2>();
}
} // NamedEnumNS
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-expr.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// PR5908
template <typename Iterator>
void Test(Iterator it) {
*(it += 1);
}
namespace PR6045 {
template<unsigned int r>
class A
{
static const unsigned int member = r;
void f();
};
template<unsigned int r>
const unsigned int A<r>::member;
template<unsigned int r>
void A<r>::f()
{
unsigned k;
(void)(k % member);
}
}
namespace PR7198 {
struct A
{
~A() { }
};
template<typename T>
struct B {
struct C : A {};
void f()
{
C c = C();
}
};
}
namespace PR7724 {
template<typename OT> int myMethod()
{ return 2 && sizeof(OT); }
}
namespace test4 {
template <typename T> T *addressof(T &v) {
return reinterpret_cast<T*>(
&const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
}
}
namespace test5 {
template <typename T> class chained_map {
int k;
void lookup() const {
int &v = (int &)k;
}
};
}
namespace PR8795 {
template <class _CharT> int test(_CharT t)
{
int data [] = {
sizeof(_CharT) > sizeof(char)
};
return data[0];
}
}
template<typename T> struct CastDependentIntToPointer {
static void* f() {
T *x;
return ((void*)(((unsigned long)(x)|0x1ul)));
}
};
// Regression test for crasher in r194540.
namespace PR10837 {
typedef void t(int);
template<typename> struct A {
void f();
static t g;
};
t *p;
template<typename T> void A<T>::f() {
p = g;
}
template struct A<int>;
}
namespace PR18152 {
template<int N> struct A {
static const int n = {N};
};
template struct A<0>;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/member-access-expr.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
void call_f0(T x) {
x.Base::f0();
}
struct Base {
void f0();
};
struct X0 : Base {
typedef Base CrazyBase;
};
void test_f0(X0 x0) {
call_f0(x0);
}
template<typename TheBase, typename T>
void call_f0_through_typedef(T x) {
typedef TheBase Base2;
x.Base2::f0();
}
void test_f0_through_typedef(X0 x0) {
call_f0_through_typedef<Base>(x0);
}
template<typename TheBase, typename T>
void call_f0_through_typedef2(T x) {
typedef TheBase CrazyBase; // expected-note{{current scope}}
x.CrazyBase::f0(); // expected-error{{ambiguous}} \
// expected-error 2{{no member named}}
}
struct OtherBase { };
struct X1 : Base, OtherBase {
typedef OtherBase CrazyBase; // expected-note{{object type}}
};
void test_f0_through_typedef2(X0 x0, X1 x1) {
call_f0_through_typedef2<Base>(x0);
call_f0_through_typedef2<OtherBase>(x1); // expected-note{{instantiation}}
call_f0_through_typedef2<Base>(x1); // expected-note{{instantiation}}
}
struct X2 {
operator int() const;
};
template<typename T, typename U>
T convert(const U& value) {
return value.operator T(); // expected-error{{operator long}}
}
void test_convert(X2 x2) {
convert<int>(x2);
convert<long>(x2); // expected-note{{instantiation}}
}
template<typename T>
void destruct(T* ptr) {
ptr->~T();
ptr->T::~T();
}
template<typename T>
void destruct_intptr(int *ip) {
ip->~T();
ip->T::~T();
}
void test_destruct(X2 *x2p, int *ip) {
destruct(x2p);
destruct(ip);
destruct_intptr<int>(ip);
}
// PR5220
class X3 {
protected:
template <int> float* &f0();
template <int> const float* &f0() const;
void f1() {
(void)static_cast<float*>(f0<0>());
}
void f1() const{
(void)f0<0>();
}
};
// Fun with template instantiation and conversions
struct X4 {
int& member();
float& member() const;
};
template<typename T>
struct X5 {
void f(T* ptr) { int& ir = ptr->member(); }
void g(T* ptr) { float& fr = ptr->member(); }
};
void test_X5(X5<X4> x5, X5<const X4> x5c, X4 *xp, const X4 *cxp) {
x5.f(xp);
x5c.g(cxp);
}
// In theory we can do overload resolution at template-definition time on this.
// We should at least not assert.
namespace test4 {
struct Base {
template <class T> void foo() {}
};
template <class T> struct Foo : Base {
void test() {
foo<int>();
}
};
}
namespace test5 {
template<typename T>
struct X {
using T::value;
T &getValue() {
return &value;
}
};
}
// PR8739
namespace test6 {
struct A {};
struct B {};
template <class T> class Base;
template <class T> class Derived : public Base<T> {
A *field;
void get(B **ptr) {
// It's okay if at some point we figure out how to diagnose this
// at instantiation time.
*ptr = field;
}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-friend-class.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// PR4794
template <class T> class X
{
friend class Y;
};
X<int> y;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-anonymous-union.cpp
|
// RUN: %clang_cc1 -fsyntax-only %s -Wall
template <typename T> class A { struct { }; };
A<int> a0;
template <typename T> struct B {
union {
int a;
void* b;
};
void f() {
a = 10;
b = 0;
}
};
B<int> b0;
template <typename T> struct C {
union {
int a;
void* b;
};
C(int a) : a(a) { }
C(void* b) : b(b) { }
};
C<int> c0(0);
namespace PR7088 {
template<typename T>
void f() {
union {
int a;
union {
float real;
T d;
};
};
a = 17;
d = 3.14;
}
template void f<double>();
}
// Check for problems related to PR7402 that occur when template instantiation
// instantiates implicit initializers.
namespace PR7402 {
struct X {
union {
struct {
int x;
int y;
};
int v[2];
};
// Check that this requirement survives instantiation.
template <typename T> X(const T& t) : x(t), y(t) {}
};
X x(42.0);
}
namespace PR9188 {
struct X0 {
union {
int member;
};
};
static union {
int global;
};
struct X1 : X0 {
template<typename T>
int f() {
return this->X0::member + PR9188::global;
}
};
template int X1::f<int>();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/typename-specifier-4.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
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;
};
template<typename MetaFun, typename T1, typename T2>
struct metafun_apply2 {
typedef typename MetaFun::template apply<T1, T2> inner;
typedef typename inner::type type;
};
template<typename T, typename U> struct pair;
struct make_pair {
template<typename T1, typename T2>
struct apply {
typedef pair<T1, T2> type;
};
};
int a0[is_same<metafun_apply2<make_pair, int, float>::type,
pair<int, float> >::value? 1 : -1];
int a1[is_same<
typename make_pair::template apply<int, float>, // expected-warning{{'template' keyword outside of a template}} \
// expected-warning{{'typename' occurs outside of a template}}
make_pair::apply<int, float>
>::value? 1 : -1];
template<typename MetaFun>
struct swap_and_apply2 {
template<typename T1, typename T2>
struct apply {
typedef typename MetaFun::template apply<T2, T1> new_metafun;
typedef typename new_metafun::type type;
};
};
int a2[is_same<swap_and_apply2<make_pair>::apply<int, float>::type,
pair<float, int> >::value? 1 : -1];
template<typename MetaFun>
struct swap_and_apply2b {
template<typename T1, typename T2>
struct apply {
typedef typename MetaFun::template apply<T2, T1>::type type;
};
};
int a3[is_same<swap_and_apply2b<make_pair>::apply<int, float>::type,
pair<float, int> >::value? 1 : -1];
template<typename T>
struct X0 {
template<typename U, typename V>
struct Inner;
void f0(X0<T>::Inner<T*, T&>); // expected-note{{here}}
void f0(typename X0<T>::Inner<T*, T&>); // expected-error{{redecl}}
void f1(X0<T>::Inner<T*, T&>); // expected-note{{here}}
void f1(typename X0<T>::template Inner<T*, T&>); // expected-error{{redecl}}
void f2(typename X0<T>::Inner<T*, T&>::type); // expected-note{{here}}
void f2(typename X0<T>::template Inner<T*, T&>::type); // expected-error{{redecl}}
};
namespace PR6236 {
template<typename T, typename U> struct S { };
template<typename T> struct S<T, T> {
template<typename U> struct K { };
void f() {
typedef typename S<T, T>::template K<T> Foo;
}
};
}
namespace PR6268 {
template <typename T>
struct Outer {
template <typename U>
struct Inner {};
template <typename U>
typename Outer<T>::template Inner<U>
foo(typename Outer<T>::template Inner<U>);
};
template <typename T>
template <typename U>
typename Outer<T>::template Inner<U>
Outer<T>::foo(typename Outer<T>::template Inner<U>) {
return Inner<U>();
}
}
namespace PR6463 {
struct B { typedef int type; }; // expected-note 2{{member found by ambiguous name lookup}}
struct C { typedef int type; }; // expected-note 2{{member found by ambiguous name lookup}}
template<typename T>
struct A : B, C {
type& a(); // expected-error{{found in multiple base classes}}
int x;
};
// FIXME: Improve source location info here.
template<typename T>
typename A<T>::type& A<T>::a() { // expected-error{{found in multiple base classes}}
return x;
}
}
namespace PR7419 {
template <typename T> struct S {
typedef typename T::Y T2;
typedef typename T2::Z T3;
typedef typename T3::W T4;
T4 *f();
typedef typename T::template Y<int> TT2;
typedef typename TT2::template Z<float> TT3;
typedef typename TT3::template W<double> TT4;
TT4 g();
};
template <typename T> typename T::Y::Z::W *S<T>::f() { }
template <typename T> typename T::template Y<int>::template Z<float>::template W<double> S<T>::g() { }
}
namespace rdar8740998 {
template<typename T>
struct X : public T {
using T::iterator; // expected-note{{add 'typename' to treat this using declaration as a type}} \
// expected-error{{dependent using declaration resolved to type without 'typename'}}
void f() {
typename X<T>::iterator i; // expected-error{{typename specifier refers to a dependent using declaration for a value 'iterator' in 'X<T>'}}
}
};
struct HasIterator {
typedef int *iterator; // expected-note{{target of using declaration}}
};
void test_X(X<HasIterator> xi) { // expected-note{{in instantiation of template class}}
xi.f();
}
}
namespace rdar9068589 {
// From GCC PR c++/13950
template <class T> struct Base {};
template <class T> struct Derived: public Base<T> {
typename Derived::template Base<double>* p1;
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-depth-subst-2.cpp
|
// RUN: %clang_cc1 -verify %s -ftemplate-depth 2
template<int N> struct S { };
template<typename T> S<T() + T()> operator+(T, T); // expected-error {{instantiation exceeded maximum depth}} expected-note 2{{while substituting}}
S<0> s;
int k = s + s; // expected-note {{while substituting}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-using-decl.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace test0 {
namespace N { }
template<typename T>
struct A {
void f();
};
template<typename T>
struct B : A<T> {
using A<T>::f;
void g() {
using namespace N;
f();
}
};
template struct B<int>;
}
namespace test1 {
template <class Derived> struct Visitor1 {
void Visit(struct Object1*);
};
template <class Derived> struct Visitor2 {
void Visit(struct Object2*); // expected-note {{candidate function}}
};
template <class Derived> struct JoinVisitor
: Visitor1<Derived>, Visitor2<Derived> {
typedef Visitor1<Derived> Base1;
typedef Visitor2<Derived> Base2;
void Visit(struct Object1*); // expected-note {{candidate function}}
using Base2::Visit;
};
class Knot : public JoinVisitor<Knot> {
};
void test() {
Knot().Visit((struct Object1*) 0);
Knot().Visit((struct Object2*) 0);
Knot().Visit((struct Object3*) 0); // expected-error {{no matching member function for call}}
}
}
// PR5847
namespace test2 {
namespace ns {
void foo();
}
template <class T> void bar(T* ptr) {
using ns::foo;
foo();
}
template void bar(char *);
}
namespace test3 {
template <typename T> struct t {
struct s1 {
T f1() const;
};
struct s2 : s1 {
using s1::f1;
T f1() const;
};
};
void f2()
{
t<int>::s2 a;
t<int>::s2 const & b = a;
b.f1();
}
}
namespace PR16936 {
// Make sure both using decls are properly considered for
// overload resolution.
template<class> struct A {
void access(int);
};
template<class> struct B {
void access();
};
template<class CELL> struct X : public A<CELL>, public B<CELL> {
using A<CELL>::access;
using B<CELL>::access;
void f() {
access(0);
}
};
void f() {
X<int> x;
x.f();
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/pragma-ms_struct.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-apple-osx10.7.0 %s
// expected-no-diagnostics
#pragma ms_struct on
// <rdar://problem/10791194>
template<int x> struct foo {
long long a;
int b;
};
extern int arr[sizeof(foo<0>) == 16 ? 1 : -1];
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/missing-class-keyword-crash.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class G {};
template <Foo> // expected-error{{unknown type name 'Foo'}} \
// expected-note{{template parameter is declared here}}
class Bar {};
class Bar<G> blah_test; // expected-error{{template argument for non-type template parameter must be an expression}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/default-expr-arguments-2.cpp
|
// RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s
// This is a wacky test to ensure that we're actually instantiating
// the default arguments of the constructor when the function type is
// otherwise non-dependent.
namespace PR6733 {
template <class T>
class bar {
public: enum { kSomeConst = 128 };
bar(int x = kSomeConst) {}
};
// CHECK: FunctionDecl{{.*}}f 'void (void)'
void f() {
// CHECK: VarDecl{{.*}}tmp 'bar<int>'
// CHECK: CXXDefaultArgExpr{{.*}}'int'
bar<int> tmp;
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_arg.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T,
int I,
template<typename> class TT>
class A; // expected-note 3 {{template is declared here}}
template<typename> class X;
A<int, 0, X> * a1;
A<float, 1, X, double> *a2; // expected-error{{too many template arguments for class template 'A'}}
A<float, 1> *a3; // expected-error{{too few template arguments for class template 'A'}}
A a3; // expected-error{{use of class template 'A' requires template arguments}}
namespace test0 {
template <class t> class foo {};
template <class t> class bar {
bar(::test0::foo<tee> *ptr) {} // FIXME(redundant): expected-error 2 {{use of undeclared identifier 'tee'}}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_explicit.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wc++11-compat %s
//
// Tests explicit instantiation of templates.
template<typename T, typename U = T> class X0 { };
namespace N {
template<typename T, typename U = T> class X1 { };
}
// Check the syntax of explicit instantiations.
template class X0<int, float>;
template class X0<int>; // expected-note{{previous}}
template class N::X1<int>;
template class ::N::X1<int, float>;
using namespace N;
// Check for some bogus syntax that probably means that the user
// wanted to write an explicit specialization, but forgot the '<>'
// after 'template'.
template class X0<double> { }; // expected-error{{explicit specialization}}
// Check for explicit instantiations that come after other kinds of
// instantiations or declarations.
template class X0<int, int>; // expected-error{{duplicate}}
template<> class X0<char> { }; // expected-note{{previous}}
template class X0<char>; // expected-warning{{ignored}}
void foo(X0<short>) { }
template class X0<short>;
// Check that explicit instantiations actually produce definitions. We
// determine whether this happens by placing semantic errors in the
// definition of the template we're instantiating.
template<typename T> struct X2; // expected-note{{declared here}}
template struct X2<float>; // expected-error{{undefined template}}
template<typename T>
struct X2 {
void f0(T*); // expected-error{{pointer to a reference}}
};
template struct X2<int>; // okay
template struct X2<int&>; // expected-note{{in instantiation of}}
// Check that explicit instantiations instantiate member classes.
template<typename T> struct X3 {
struct Inner {
void f(T*); // expected-error{{pointer to a reference}}
};
};
void f1(X3<int&>); // okay, Inner, not instantiated
template struct X3<int&>; // expected-note{{instantiation}}
template<typename T> struct X4 {
struct Inner {
struct VeryInner {
void f(T*); // expected-error 2{{pointer to a reference}}
};
};
};
void f2(X4<int&>); // okay, Inner, not instantiated
void f3(X4<int&>::Inner); // okay, Inner::VeryInner, not instantiated
template struct X4<int&>; // expected-note{{instantiation}}
template struct X4<float&>; // expected-note{{instantiation}}
// Check explicit instantiation of member classes
namespace N2 {
template<typename T>
struct X5 {
struct Inner1 {
void f(T&);
};
struct Inner2 { // expected-note {{here}}
struct VeryInner {
void g(T*); // expected-error 2{{pointer to a reference}}
};
};
};
}
template struct N2::X5<void>::Inner2;
using namespace N2;
template struct X5<int&>::Inner2; // expected-note{{instantiation}}
void f4(X5<float&>::Inner2);
template struct X5<float&>::Inner2; // expected-note{{instantiation}}
namespace N3 {
template struct N2::X5<int>::Inner2; // expected-warning {{explicit instantiation of 'Inner2' not in a namespace enclosing 'N2'}}
}
struct X6 {
struct Inner { // expected-note{{here}}
void f();
};
};
template struct X6::Inner; // expected-error{{non-templated}}
// PR5559
template <typename T>
struct Foo;
template <>
struct Foo<int> // expected-note{{header not required for explicitly-specialized}}
{
template <typename U>
struct Bar
{};
};
template <> // expected-warning{{extraneous template parameter list}}
template <>
struct Foo<int>::Bar<void>
{};
namespace N1 {
template<typename T> struct X7 { }; // expected-note{{here}}
namespace Inner {
template<typename T> struct X8 { };
}
template struct X7<int>;
template struct Inner::X8<int>;
}
template<typename T> struct X9 { }; // expected-note{{here}}
template struct ::N1::Inner::X8<float>;
namespace N2 {
using namespace N1;
template struct X7<double>; // expected-warning{{must occur in namespace}}
template struct X9<float>; // expected-warning{{must occur at global scope}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/default-arguments-cxx0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
// expected-no-diagnostics
// Test default template arguments for function templates.
template<typename T = int>
void f0();
template<typename T>
void f0();
void g0() {
f0(); // okay!
}
template<typename T, int N = T::value>
int &f1(T);
float &f1(...);
struct HasValue {
static const int value = 17;
};
void g1() {
float &fr = f1(15);
int &ir = f1(HasValue());
}
namespace PR16689 {
template <typename T1, typename T2> class tuple {
public:
template <typename = T2>
constexpr tuple() {}
};
template <class X, class... Y> struct a : public X {
using X::X;
};
auto x = a<tuple<int, int> >();
}
namespace PR16975 {
template <typename...> struct is {
constexpr operator bool() const { return false; }
};
template <typename... Types>
struct bar {
template <typename T,
bool = is<Types...>()>
bar(T);
};
struct baz : public bar<> {
using bar::bar;
};
baz data{0};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/typename-specifier.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused -fms-compatibility -DMSVC
namespace N {
struct A {
typedef int type;
};
struct B {
};
struct C {
struct type { };
int type; // expected-note 2{{referenced member 'type' is declared here}}
};
}
int i;
typename N::A::type *ip1 = &i; // expected-warning{{'typename' occurs outside of a template}}
typename N::B::type *ip2 = &i; // expected-error{{no type named 'type' in 'N::B'}} \
// expected-warning{{'typename' occurs outside of a template}}
typename N::C::type *ip3 = &i; // expected-error{{typename specifier refers to non-type member 'type'}} \
// expected-warning{{'typename' occurs outside of a template}}
void test(double d) {
typename N::A::type f(typename N::A::type(a)); // expected-warning{{disambiguated as a function declaration}} \
// expected-note{{add a pair of parentheses}} expected-warning 2{{'typename' occurs outside of a template}}
int five = f(5);
using namespace N;
for (typename A::type i = 0; i < 10; ++i) // expected-warning{{'typename' occurs outside of a template}}
five += 1;
const typename N::A::type f2(d); // expected-warning{{'typename' occurs outside of a template}}
}
namespace N {
template<typename T>
struct X {
typedef typename T::type type; // expected-error {{no type named 'type' in 'N::B'}} \
// expected-error {{no type named 'type' in 'B'}} \
// FIXME: location info for error above isn't very good \
// expected-error 2{{typename specifier refers to non-type member 'type'}} \
// expected-error{{type 'int' cannot be used prior to '::' because it has no members}}
};
}
N::X<N::A>::type *ip4 = &i;
N::X<N::B>::type *ip5 = &i; // expected-note{{in instantiation of template class 'N::X<N::B>' requested here}}
N::X<N::C>::type *ip6 = &i; // expected-note{{in instantiation of template class 'N::X<N::C>' requested here}}
N::X<int>::type fail1; // expected-note{{in instantiation of template class 'N::X<int>' requested here}}
template<typename T>
struct Y {
typedef typename N::X<T>::type *type; // expected-note{{in instantiation of template class 'N::X<B>' requested here}} \
// expected-note{{in instantiation of template class 'N::X<C>' requested here}}
};
struct A {
typedef int type;
};
struct B {
};
struct C {
struct type { };
int type; // expected-note{{referenced member 'type' is declared here}}
};
::Y<A>::type ip7 = &i;
::Y<B>::type ip8 = &i; // expected-note{{in instantiation of template class 'Y<B>' requested here}}
::Y<C>::type ip9 = &i; // expected-note{{in instantiation of template class 'Y<C>' requested here}}
template<typename T> struct D {
typedef typename T::foo foo; // expected-error {{type 'long' cannot be used prior to '::' because it has no members}}
typedef typename foo::bar bar;
};
D<long> struct_D; // expected-note {{in instantiation of template class 'D<long>' requested here}}
template<typename T> struct E {
typedef typename T::foo foo;
typedef typename foo::bar bar; // expected-error {{type 'foo' (aka 'double') cannot be used prior to '::' because it has no members}}
};
struct F {
typedef double foo;
};
E<F> struct_E; // expected-note {{in instantiation of template class 'E<F>' requested here}}
template<typename T> struct G {
typedef typename T::foo foo;
typedef typename foo::bar bar;
};
struct H {
struct foo {
typedef double bar;
};
};
G<H> struct_G;
namespace PR10925 {
template< int mydim, typename Traits >
class BasicGeometry
{
typedef int some_type_t;
};
template<class ctype, int mydim, int coorddim>
class MockGeometry : BasicGeometry<mydim, int>{
using typename BasicGeometry<mydim, int>::operator[]; // expected-error {{typename is allowed for identifiers only}}
};
}
namespace missing_typename {
template <class T1, class T2> struct pair {}; // expected-note 7 {{template parameter is declared here}}
template <class T1, class T2>
struct map {
typedef T1* iterator;
};
template <class T>
class ExampleClass1 {
struct ExampleItem;
struct ExampleItemSet {
typedef ExampleItem* iterator;
ExampleItem* operator[](unsigned);
};
void foo() {
#ifdef MSVC
// expected-warning@+4 {{omitted 'typename' is a Microsoft extension}}
#else
// expected-error@+2 {{template argument for template type parameter must be a type; did you forget 'typename'?}}
#endif
pair<ExampleItemSet::iterator, int> i;
pair<this->ExampleItemSet::iterator, int> i; // expected-error-re {{template argument for template type parameter must be a type{{$}}}}
pair<ExampleItemSet::operator[], int> i; // expected-error-re {{template argument for template type parameter must be a type{{$}}}}
}
#ifdef MSVC
// expected-warning@+4 {{omitted 'typename' is a Microsoft extension}}
#else
// expected-error@+2 {{template argument for template type parameter must be a type; did you forget 'typename'?}}
#endif
pair<ExampleItemSet::iterator, int> elt;
typedef map<int, ExampleItem*> ExampleItemMap;
static void bar() {
#ifdef MSVC
// expected-warning@+4 {{omitted 'typename' is a Microsoft extension}}
#else
// expected-error@+2 {{template argument for template type parameter must be a type; did you forget 'typename'?}}
#endif
pair<ExampleItemMap::iterator, int> i;
}
#ifdef MSVC
// expected-warning@+4 {{omitted 'typename' is a Microsoft extension}}
#else
// expected-error@+2 {{template argument for template type parameter must be a type; did you forget 'typename'?}}
#endif
pair<ExampleItemMap::iterator, int> entry;
pair<bar, int> foobar; // expected-error {{template argument for template type parameter must be a type}}
};
} // namespace missing_typename
namespace missing_typename_and_base {
template <class T> struct Bar {}; // expected-note 1+ {{template parameter is declared here}}
template <typename T>
struct Foo : T {
// FIXME: MSVC accepts this code.
Bar<TypeInBase> x; // expected-error {{use of undeclared identifier 'TypeInBase'}}
#ifdef MSVC
// expected-warning@+4 {{omitted 'typename' is a Microsoft extension}}
#else
// expected-error@+2 {{must be a type; did you forget 'typename'?}}
#endif
Bar<T::TypeInBase> y;
#ifdef MSVC
// expected-warning@+4 {{omitted 'typename' is a Microsoft extension}}
#else
// expected-error@+2 {{must be a type; did you forget 'typename'?}}
#endif
Bar<T::NestedRD::TypeInNestedRD> z;
};
struct Base {
typedef int TypeInBase;
struct NestedRD {
typedef int TypeInNestedRD;
};
};
Foo<Base> x;
} // namespace missing_typename_and_base
namespace func_type_vs_construct_tmp {
template <typename> struct S { typedef int type; };
template <typename T> void f();
template <int N> void f();
// expected-error@+1 {{missing 'typename' prior to dependent type name 'S<int>::type'}}
template <typename T> void g() { f</*typename*/ S<T>::type(int())>(); }
// Adding typename does fix the diagnostic.
template <typename T> void h() { f<typename S<T>::type(int())>(); }
void j() {
g<int>(); // expected-note-re {{in instantiation {{.*}} requested here}}
h<int>();
}
} // namespace func_type_vs_construct_tmp
namespace pointer_vs_multiply {
int x;
// expected-error@+1 {{missing 'typename' prior to dependent type name 'B::type_or_int'}}
template <typename T> void g() { T::type_or_int * x; }
// expected-error@+1 {{typename specifier refers to non-type member 'type_or_int' in 'pointer_vs_multiply::A'}}
template <typename T> void h() { typename T::type_or_int * x; }
struct A { static const int type_or_int = 5; }; // expected-note {{referenced member 'type_or_int' is declared here}}
struct B { typedef int type_or_int; };
void j() {
g<A>();
g<B>(); // expected-note-re {{in instantiation {{.*}} requested here}}
h<A>(); // expected-note-re {{in instantiation {{.*}} requested here}}
h<B>();
}
} // namespace pointer_vs_multiply
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-overloaded-arrow.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// PR5488
struct X {
int x;
};
struct Iter {
X* operator->();
};
template <typename T>
void Foo() {
(void)Iter()->x;
}
void Func() {
Foo<int>();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-non-dependent-types.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
template<typename T>
struct X1 {
static void member() { T* x = 1; } // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
};
template<void(*)()> struct instantiate { };
template<typename T>
struct X2 {
typedef instantiate<&X1<int>::member> i; // expected-note{{in instantiation of}}
};
X2<int> x;
template <class T, class A> class C {
public:
int i;
void f(T &t) {
T *q = new T();
t.T::~T();
q->~T();
// expected-error@+2 {{'int' is not a class, namespace, or enumeration}}
// expected-error@+1 {{no member named '~Colors' in 'Colors'}}
q->A::~A();
// expected-error@+2 {{no member named '~int' in 'Q'}}
// expected-error@+1 {{no member named '~Colors' in 'Q'}}
q->~A();
delete q;
}
};
class Q {
public:
Q() {}
~Q() {}
};
enum Colors {red, green, blue};
C<Q, int> dummy;
C<Q, Colors> dummyColors;
int main() {
Q qinst;
// expected-note@+1 {{in instantiation of member function 'C<Q, int>::f' requested here}}
dummy.f(qinst);
// expected-note@+1 {{in instantiation of member function 'C<Q, Colors>::f' requested here}}
dummyColors.f(qinst);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-scope.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify %s
template<typename ...T> struct X {
void f(int);
void f(...);
static int n;
};
template<typename T, typename U> using A = T;
// These definitions are OK, X<A<T, decltype(...)>...> is equivalent to X<T...>
// so this defines the member of the primary template.
template<typename ...T>
void X<A<T, decltype(f(T()))>...>::f(int) {} // expected-error {{undeclared}}
template<typename ...T>
int X<A<T, decltype(f(T()))>...>::n = 0; // expected-error {{undeclared}}
struct Y {}; void f(Y);
void g() {
// OK, substitution succeeds.
X<Y>().f(0);
X<Y>::n = 1;
// Error, substitution fails; this should not be treated as a SFINAE-able
// condition, so we don't select X<void>::f(...).
X<void>().f(0); // expected-note {{instantiation of}}
X<void>::n = 1; // expected-note {{instantiation of}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/constexpr-instantiate.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify %s
namespace UseBeforeDefinition {
struct A {
template<typename T> static constexpr T get() { return T(); }
// ok, not a constant expression.
int n = get<int>();
};
// ok, constant expression.
constexpr int j = A::get<int>();
template<typename T> constexpr int consume(T);
// ok, not a constant expression.
const int k = consume(0); // expected-note {{here}}
template<typename T> constexpr int consume(T) { return 0; }
// ok, constant expression.
constexpr int l = consume(0);
constexpr int m = k; // expected-error {{constant expression}} expected-note {{initializer of 'k'}}
}
namespace IntegralConst {
template<typename T> constexpr T f(T n) { return n; }
enum E {
v = f(0), w = f(1) // ok
};
static_assert(w == 1, "");
char arr[f('x')]; // ok
static_assert(sizeof(arr) == 'x', "");
}
namespace ConvertedConst {
template<typename T> constexpr T f(T n) { return n; }
int f() {
switch (f()) {
case f(4): return 0;
}
return 1;
}
}
namespace OverloadResolution {
template<typename T> constexpr T f(T t) { return t; }
template<int n> struct S { };
template<typename T> auto g(T t) -> S<f(sizeof(T))> &;
char &f(...);
template<typename T> auto h(T t[f(sizeof(T))]) -> decltype(&*t) {
return t;
}
S<4> &k = g(0);
int *p, *q = h(p);
}
namespace DataMember {
template<typename T> struct S { static const int k; };
const int n = S<int>::k; // expected-note {{here}}
template<typename T> const int S<T>::k = 0;
constexpr int m = S<int>::k; // ok
constexpr int o = n; // expected-error {{constant expression}} expected-note {{initializer of 'n'}}
}
namespace Reference {
const int k = 5;
template<typename T> struct S {
static volatile int &r;
};
template<typename T> volatile int &S<T>::r = const_cast<volatile int&>(k);
constexpr int n = const_cast<int&>(S<int>::r);
static_assert(n == 5, "");
}
namespace Unevaluated {
// We follow g++ in treating any reference to a constexpr function template
// specialization as requiring an instantiation, even if it occurs in an
// unevaluated context.
//
// We go slightly further than g++, and also trigger the implicit definition
// of a defaulted special member in the same circumstances. This seems scary,
// since a lot of classes have constexpr special members in C++11, but the
// only observable impact should be the implicit instantiation of constexpr
// special member templates (defaulted special members should only be
// generated if they are well-formed, and non-constexpr special members in a
// base or member cause the class's special member to not be constexpr).
//
// FIXME: None of this is required by the C++ standard. The rules in this
// area are poorly specified, so this is subject to change.
namespace NotConstexpr {
template<typename T> struct S {
S() : n(0) {}
S(const S&) : n(T::error) {}
int n;
};
struct U : S<int> {};
decltype(U(U())) u; // ok, don't instantiate S<int>::S() because it wasn't declared constexpr
}
namespace Constexpr {
template<typename T> struct S {
constexpr S() : n(0) {}
constexpr S(const S&) : n(T::error) {} // expected-error {{has no members}}
int n;
};
struct U : S<int> {}; // expected-note {{instantiation}}
decltype(U(U())) u; // expected-note {{here}}
}
namespace PR11851_Comment0 {
template<int x> constexpr int f() { return x; }
template<int i> void ovf(int (&x)[f<i>()]);
void f() { int x[10]; ovf<10>(x); }
}
namespace PR11851_Comment1 {
template<typename T>
constexpr bool Integral() {
return true;
}
template<typename T, bool Int = Integral<T>()>
struct safe_make_unsigned {
typedef T type;
};
template<typename T>
using Make_unsigned = typename safe_make_unsigned<T>::type;
template <typename T>
struct get_distance_type {
using type = int;
};
template<typename R>
auto size(R) -> Make_unsigned<typename get_distance_type<R>::type>;
auto check() -> decltype(size(0));
}
namespace PR11851_Comment6 {
template<int> struct foo {};
template<class> constexpr int bar() { return 0; }
template<class T> foo<bar<T>()> foobar();
auto foobar_ = foobar<int>();
}
namespace PR11851_Comment9 {
struct S1 {
constexpr S1() {}
constexpr operator int() const { return 0; }
};
int k1 = sizeof(short{S1(S1())});
struct S2 {
constexpr S2() {}
constexpr operator int() const { return 123456; }
};
int k2 = sizeof(short{S2(S2())}); // expected-error {{cannot be narrowed}} expected-note {{insert an explicit cast to silence this issue}}
}
namespace PR12288 {
template <typename> constexpr bool foo() { return true; }
template <bool> struct bar {};
template <typename T> bar<foo<T>()> baz() { return bar<foo<T>()>(); }
int main() { baz<int>(); }
}
namespace PR13423 {
template<bool, typename> struct enable_if {};
template<typename T> struct enable_if<true, T> { using type = T; };
template<typename T> struct F {
template<typename U>
static constexpr bool f() { return sizeof(T) < U::size; }
template<typename U>
static typename enable_if<f<U>(), void>::type g() {} // expected-note {{disabled by 'enable_if'}}
};
struct U { static constexpr int size = 2; };
void h() { F<char>::g<U>(); }
void i() { F<int>::g<U>(); } // expected-error {{no matching function}}
}
namespace PR14203 {
struct duration { constexpr duration() {} };
template <typename>
void sleep_for() {
constexpr duration max = duration();
}
}
}
namespace NoInstantiationWhenSelectingOverload {
// Check that we don't instantiate conversion functions when we're checking
// for the existence of an implicit conversion sequence, only when a function
// is actually chosen by overload resolution.
struct S {
template<typename T> constexpr S(T) : n(T::error) {} // expected-error {{no members}}
int n;
};
int f(S);
int f(int);
void g() { f(0); }
void h() { (void)sizeof(f(0)); }
void i() { (void)sizeof(f("oops")); } // expected-note {{instantiation of}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-function-2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template <typename T> struct S {
S() { }
S(T t);
};
template struct S<int>;
void f() {
S<int> s1;
S<int> s2(10);
}
namespace PR7184 {
template<typename T>
void f() {
typedef T type;
void g(int array[sizeof(type)]);
}
template void f<int>();
}
namespace UsedAttr {
template<typename T>
void __attribute__((used)) foo() {
T *x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
}
void bar() {
foo<int>(); // expected-note{{instantiation of}}
}
}
namespace PR9654 {
typedef void ftype(int);
template<typename T>
ftype f;
void g() {
f<int>(0);
}
}
namespace AliasTagDef {
template<typename T>
T f() {
using S = struct { // expected-warning {{C++11}}
T g() {
return T();
}
};
return S().g();
}
int n = f<int>();
}
namespace PR10273 {
template<typename T> void (f)(T t) {}
void g() {
(f)(17);
}
}
namespace rdar15464547 {
class A {
A();
};
template <typename R> class B {
public:
static void meth1();
static void meth2();
};
A::A() {
extern int compile_time_assert_failed;
B<int>::meth2();
}
template <typename R> void B<R>::meth1() {
extern int compile_time_assert_failed;
}
template <typename R> void B<R>::meth2() {
extern int compile_time_assert_failed;
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/explicit-specialization-member.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
struct X0 {
typedef T* type;
void f0(T);
void f1(type);
};
template<> void X0<char>::f0(char);
template<> void X0<char>::f1(type);
namespace PR6161 {
template<typename _CharT>
class numpunct : public locale::facet // expected-error{{use of undeclared identifier 'locale'}} \
// expected-error{{expected class name}}
{
static locale::id id; // expected-error{{use of undeclared identifier}}
};
numpunct<char>::~numpunct();
}
namespace PR12331 {
template<typename T> struct S {
struct U { static const int n = 5; };
enum E { e = U::n }; // expected-note {{implicit instantiation first required here}}
int arr[e];
};
template<> struct S<int>::U { static const int n = sizeof(int); }; // expected-error {{explicit specialization of 'U' after instantiation}}
}
namespace PR18246 {
template<typename T>
class Baz {
public:
template<int N> void bar();
};
template<typename T>
template<int N>
void Baz<T>::bar() { // expected-note {{couldn't infer template argument 'N'}}
}
// FIXME: We shouldn't try to match this against a prior declaration if
// template parameter matching failed.
template<typename T>
void Baz<T>::bar<0>() { // expected-error {{cannot specialize a member of an unspecialized template}} \
// expected-error {{no function template matches}}
}
}
namespace PR19340 {
template<typename T> struct Helper {
template<int N> static void func(const T *m) {} // expected-note {{failed template argument deduction}}
};
template<typename T> void Helper<T>::func<2>() {} // expected-error {{cannot specialize a member}} \
// expected-error {{no function template matches}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-depth.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 5 -ftemplate-backtrace-limit 4 %s
// RUN: %clang -fsyntax-only -Xclang -verify -ftemplate-depth-5 -ftemplate-backtrace-limit=4 %s
// RUN: %clang -fsyntax-only -Xclang -verify -ftemplate-depth=5 -ftemplate-backtrace-limit=4 %s
#ifndef NOEXCEPT
template<typename T> struct X : X<T*> { }; \
// expected-error{{recursive template instantiation exceeded maximum depth of 5}} \
// expected-note 3 {{instantiation of template class}} \
// expected-note {{skipping 2 contexts in backtrace}} \
// expected-note {{use -ftemplate-depth=N to increase recursive template instantiation depth}}
void test() {
(void)sizeof(X<int>); // expected-note {{instantiation of template class}}
}
#else
// RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 5 -ftemplate-backtrace-limit 4 -std=c++11 -DNOEXCEPT %s
template<typename T> struct S {
S() noexcept(noexcept(T()));
};
struct T : S<T> {}; \
// expected-error{{recursive template instantiation exceeded maximum depth of 5}} \
// expected-note 4 {{in instantiation of exception spec}} \
// expected-note {{skipping 2 contexts in backtrace}} \
// expected-note {{use -ftemplate-depth=N to increase recursive template instantiation depth}}
T t; // expected-note {{implicit default constructor for 'T' first required here}}
#endif
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_arg_type.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T> class A; // expected-note 2 {{template parameter is declared here}} expected-note{{template is declared here}}
// [temp.arg.type]p1
A<0> *a1; // expected-error{{template argument for template type parameter must be a type}}
A<A> *a2; // expected-error{{use of class template 'A' requires template arguments}}
A<int> *a3;
A<int()> *a4;
A<int(float)> *a5;
A<A<int> > *a6;
// Pass an overloaded function template:
template<typename T> void function_tpl(T);
A<function_tpl> a7; // expected-error{{template argument for template type parameter must be a type}}
// Pass a qualified name:
namespace ns {
template<typename T> class B {}; // expected-note{{template is declared here}}
}
A<ns::B> a8; // expected-error{{use of class template 'ns::B' requires template arguments}}
// [temp.arg.type]p2
void f() {
class X { };
A<X> * a = 0; // expected-warning{{template argument uses local type 'X'}}
}
struct { int x; } Unnamed; // expected-note{{unnamed type used in template argument was declared here}}
A<__typeof__(Unnamed)> *a9; // expected-warning{{template argument uses unnamed type}}
template<typename T, unsigned N>
struct Array {
typedef struct { T x[N]; } type;
};
template<typename T> struct A1 { };
A1<Array<int, 17>::type> ax;
// FIXME: [temp.arg.type]p3. The check doesn't really belong here (it
// belongs somewhere in the template instantiation section).
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-static-var.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T, T Divisor>
class X {
public:
static const T value = 10 / Divisor; // expected-error{{in-class initializer for static data member is not a constant expression}}
};
int array1[X<int, 2>::value == 5? 1 : -1];
X<int, 0> xi0; // expected-note{{in instantiation of template class 'X<int, 0>' requested here}}
template<typename T>
class Y {
static const T value = 0; // expected-warning{{in-class initializer for static data member of type 'const float' is a GNU extension}}
};
Y<float> fy; // expected-note{{in instantiation of template class 'Y<float>' requested here}}
// out-of-line static member variables
template<typename T>
struct Z {
static T value;
};
template<typename T>
T Z<T>::value; // expected-error{{no matching constructor}}
struct DefCon {};
struct NoDefCon {
NoDefCon(const NoDefCon&); // expected-note{{candidate constructor}}
};
void test() {
DefCon &DC = Z<DefCon>::value;
NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}}
}
// PR5609
struct X1 {
~X1(); // The errors won't be triggered without this dtor.
};
template <typename T>
struct Y1 {
static char Helper(T);
static const int value = sizeof(Helper(T()));
};
struct X2 {
virtual ~X2();
};
namespace std {
class type_info { };
}
template <typename T>
struct Y2 {
static T &Helper();
static const int value = sizeof(typeid(Helper()));
};
template <int>
struct Z1 {};
void Test() {
Z1<Y1<X1>::value> x;
int y[Y1<X1>::value];
Z1<Y2<X2>::value> x2;
int y2[Y2<X2>::value];
}
// PR5672
template <int n>
struct X3 {};
class Y3 {
public:
~Y3(); // The error isn't triggered without this dtor.
void Foo(X3<1>);
};
template <typename T>
struct SizeOf {
static const int value = sizeof(T);
};
void MyTest3() {
Y3().Foo(X3<SizeOf<char>::value>());
}
namespace PR6449 {
template<typename T>
struct X0 {
static const bool var = false;
};
template<typename T>
const bool X0<T>::var;
template<typename T>
struct X1 : public X0<T> {
static const bool var = false;
};
template<typename T>
const bool X1<T>::var;
template class X0<char>;
template class X1<char>;
}
typedef char MyString[100];
template <typename T>
struct StaticVarWithTypedefString {
static MyString str;
};
template <typename T>
MyString StaticVarWithTypedefString<T>::str = "";
void testStaticVarWithTypedefString() {
(void)StaticVarWithTypedefString<int>::str;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/member-function-template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct X {
template<typename T> T& f0(T);
void g0(int i, double d) {
int &ir = f0(i);
double &dr = f0(d);
}
template<typename T> T& f1(T);
template<typename T, typename U> U& f1(T, U);
void g1(int i, double d) {
int &ir1 = f1(i);
int &ir2 = f1(d, i);
int &ir3 = f1(i, i);
}
};
void test_X_f0(X x, int i, float f) {
int &ir = x.f0(i);
float &fr = x.f0(f);
}
void test_X_f1(X x, int i, float f) {
int &ir1 = x.f1(i);
int &ir2 = x.f1(f, i);
int &ir3 = x.f1(i, i);
}
void test_X_f0_address() {
int& (X::*pm1)(int) = &X::f0;
float& (X::*pm2)(float) = &X::f0;
}
void test_X_f1_address() {
int& (X::*pm1)(int) = &X::f1;
float& (X::*pm2)(float) = &X::f1;
int& (X::*pm3)(float, int) = &X::f1;
}
void test_X_f0_explicit(X x, int i, long l) {
int &ir1 = x.f0<int>(i);
int &ir2 = x.f0<>(i);
long &il1 = x.f0<long>(i);
}
// PR4608
class A { template <class x> x a(x z) { return z+y; } int y; };
// PR5419
struct Functor {
template <typename T>
bool operator()(const T& v) const {
return true;
}
};
void test_Functor(Functor f) {
f(1);
}
// Instantiation on ->
template<typename T>
struct X1 {
template<typename U> U& get();
};
template<typename T> struct X2; // expected-note{{here}}
void test_incomplete_access(X1<int> *x1, X2<int> *x2) {
float &fr = x1->get<float>();
(void)x2->get<float>(); // expected-error{{implicit instantiation of undefined template}}
}
// Instantiation of template template parameters in a member function
// template.
namespace TTP {
template<int Dim> struct X {
template<template<class> class M, class T> void f(const M<T>&);
};
template<typename T> struct Y { };
void test_f(X<3> x, Y<int> y) { x.f(y); }
}
namespace PR7387 {
template <typename T> struct X {};
template <typename T1> struct S {
template <template <typename> class TC> void foo(const TC<T1>& arg);
};
template <typename T1> template <template <typename> class TC>
void S<T1>::foo(const TC<T1>& arg) {}
void test(const X<int>& x) {
S<int> s;
s.foo(x);
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-member-pointers.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
struct Y {
int x;
};
template<typename T>
struct X1 {
int f(T* ptr, int T::*pm) { // expected-error{{member pointer}}
return ptr->*pm;
}
};
template struct X1<Y>;
template struct X1<int>; // expected-note{{instantiation}}
template<typename T, typename Class>
struct X2 {
T f(Class &obj, T Class::*pm) { // expected-error{{to a reference}} \
// expected-error{{member pointer to void}}
return obj.*pm;
}
};
template struct X2<int, Y>;
template struct X2<int&, Y>; // expected-note{{instantiation}}
template struct X2<const void, Y>; // expected-note{{instantiation}}
template<typename T, typename Class, T Class::*Ptr>
struct X3 {
X3<T, Class, Ptr> &operator=(const T& value) {
return *this;
}
};
X3<int, Y, &Y::x> x3;
typedef int Y::*IntMember;
template<IntMember Member>
struct X4 {
X3<int, Y, Member> member;
int &getMember(Y& y) { return y.*Member; }
};
int &get_X4(X4<&Y::x> x4, Y& y) {
return x4.getMember(y);
}
template<IntMember Member>
void accept_X4(X4<Member>);
void test_accept_X4(X4<&Y::x> x4) {
accept_X4(x4);
}
namespace ValueDepMemberPointer {
template <void (*)()> struct instantiate_function {};
template <typename T> struct S {
static void instantiate();
typedef instantiate_function<&S::instantiate> x; // expected-note{{instantiation}}
};
template <typename T> void S<T>::instantiate() {
int a[(int)sizeof(T)-42]; // expected-error{{array with a negative size}}
}
S<int> s;
}
namespace PR18192 {
struct A { struct { int n; }; };
template<int A::*> struct X {};
constexpr int A::*p = &A::n;
X<p> x; // expected-error{{not a pointer to member constant}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s
template<typename T, T val> struct A {};
template<typename T, typename U> constexpr bool is_same = false; // expected-note +{{here}}
template<typename T> constexpr bool is_same<T, T> = true;
namespace String {
A<const char*, "test"> a; // expected-error {{does not refer to any declaration}}
A<const char (&)[5], "test"> b; // expected-error {{does not refer to any declaration}}
}
namespace Array {
char arr[3];
char x;
A<const char*, arr> a;
A<const char(&)[3], arr> b;
A<const char*, &arr[0]> c;
A<const char*, &arr[1]> d; // expected-error {{refers to subobject '&arr[1]'}}
A<const char*, (&arr)[0]> e;
A<const char*, &x> f;
A<const char*, &(&x)[0]> g;
A<const char*, &(&x)[1]> h; // expected-error {{refers to subobject '&x + 1'}}
A<const char*, 0> i; // expected-error {{not allowed in a converted constant}}
A<const char*, nullptr> j;
}
namespace Function {
void f();
void g() noexcept;
void h();
void h(int);
template<typename...T> void i(T...);
typedef A<void (*)(), f> a;
typedef A<void (*)(), &f> a;
typedef A<void (*)(), g> b;
typedef A<void (*)(), &g> b;
typedef A<void (*)(), h> c;
typedef A<void (*)(), &h> c;
typedef A<void (*)(), i> d;
typedef A<void (*)(), &i> d;
typedef A<void (*)(), i<>> d;
typedef A<void (*)(), i<int>> e; // expected-error {{is not implicitly convertible}}
typedef A<void (*)(), 0> x; // expected-error {{not allowed in a converted constant}}
typedef A<void (*)(), nullptr> y;
}
void Func() {
A<const char*, __func__> a; // expected-error {{does not refer to any declaration}}
}
namespace LabelAddrDiff {
void f() {
a: b: A<int, __builtin_constant_p(true) ? (__INTPTR_TYPE__)&&b - (__INTPTR_TYPE__)&&a : 0> s; // expected-error {{label address difference}}
};
}
namespace Temp {
struct S { int n; };
constexpr S &addr(S &&s) { return s; }
A<S &, addr({})> a; // expected-error {{constant}} expected-note 2{{temporary}}
A<S *, &addr({})> b; // expected-error {{constant}} expected-note 2{{temporary}}
A<int &, addr({}).n> c; // expected-error {{constant}} expected-note 2{{temporary}}
A<int *, &addr({}).n> d; // expected-error {{constant}} expected-note 2{{temporary}}
}
namespace std { struct type_info; }
namespace RTTI {
A<const std::type_info&, typeid(int)> a; // expected-error {{does not refer to any declaration}}
A<const std::type_info*, &typeid(int)> b; // expected-error {{does not refer to any declaration}}
}
namespace PtrMem {
struct B { int b; };
struct C : B {};
struct D : B {};
struct E : C, D { int e; };
constexpr int B::*b = &B::b;
constexpr int C::*cb = b;
constexpr int D::*db = b;
constexpr int E::*ecb = cb; // expected-note +{{here}}
constexpr int E::*edb = db; // expected-note +{{here}}
constexpr int E::*e = &E::e;
constexpr int D::*de = (int D::*)e;
constexpr int C::*ce = (int C::*)e;
constexpr int B::*bde = (int B::*)de; // expected-note +{{here}}
constexpr int B::*bce = (int B::*)ce; // expected-note +{{here}}
// FIXME: This should all be accepted, but we don't yet have a representation
// nor mangling for this form of template argument.
using Ab = A<int B::*, b>;
using Ab = A<int B::*, &B::b>;
using Abce = A<int B::*, bce>; // expected-error {{not supported}}
using Abde = A<int B::*, bde>; // expected-error {{not supported}}
static_assert(!is_same<Ab, Abce>, ""); // expected-error {{undeclared}} expected-error {{must be a type}}
static_assert(!is_same<Ab, Abde>, ""); // expected-error {{undeclared}} expected-error {{must be a type}}
static_assert(!is_same<Abce, Abde>, ""); // expected-error 2{{undeclared}} expected-error {{must be a type}}
static_assert(is_same<Abce, A<int B::*, (int B::*)(int C::*)&E::e>, ""); // expected-error {{undeclared}} expected-error {{not supported}}
using Ae = A<int E::*, e>;
using Ae = A<int E::*, &E::e>;
using Aecb = A<int E::*, ecb>; // expected-error {{not supported}}
using Aedb = A<int E::*, edb>; // expected-error {{not supported}}
static_assert(!is_same<Ae, Aecb>, ""); // expected-error {{undeclared}} expected-error {{must be a type}}
static_assert(!is_same<Ae, Aedb>, ""); // expected-error {{undeclared}} expected-error {{must be a type}}
static_assert(!is_same<Aecb, Aedb>, ""); // expected-error 2{{undeclared}} expected-error {{must be a type}}
static_assert(is_same<Aecb, A<int E::*, (int E::*)(int C::*)&B::b>, ""); // expected-error {{undeclared}} expected-error {{not supported}}
using An = A<int E::*, nullptr>;
using A0 = A<int E::*, (int E::*)0>;
static_assert(is_same<An, A0>);
}
namespace DeduceDifferentType {
template<int N> struct A {};
template<long N> int a(A<N>); // expected-note {{does not have the same type}}
int a_imp = a(A<3>()); // expected-error {{no matching function}}
int a_exp = a<3>(A<3>());
template<decltype(nullptr)> struct B {};
template<int *P> int b(B<P>); // expected-note {{could not match}} expected-note {{not implicitly convertible}}
int b_imp = b(B<nullptr>()); // expected-error {{no matching function}}
int b_exp = b<nullptr>(B<nullptr>()); // expected-error {{no matching function}}
struct X { constexpr operator int() { return 0; } } x;
template<X &> struct C {};
template<int N> int c(C<N>); // expected-note {{does not have the same type}} expected-note {{not implicitly convertible}}
int c_imp = c(C<x>()); // expected-error {{no matching function}}
int c_exp = c<x>(C<x>()); // expected-error {{no matching function}}
struct Z;
struct Y { constexpr operator Z&(); } y;
struct Z { constexpr operator Y&() { return y; } } z;
constexpr Y::operator Z&() { return z; }
template<Y &> struct D {};
template<Z &z> int d(D<z>); // expected-note {{does not have the same type}}
int d_imp = d(D<y>()); // expected-error {{no matching function}}
int d_exp = d<y>(D<y>());
}
namespace DeclMatch {
template<typename T, T> int f();
template<typename T> class X { friend int f<T, 0>(); static int n; };
template<typename T, T> int f() { return X<T>::n; }
int k = f<int, 0>(); // ok, friend
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-declref-ice.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
template<int i> struct x {
static const int j = i;
x<j>* y;
};
template<int i>
const int x<i>::j;
int array0[x<2>::j];
template<typename T>
struct X0 {
static const unsigned value = sizeof(T);
};
template<typename T>
const unsigned X0<T>::value;
int array1[X0<int>::value == sizeof(int)? 1 : -1];
const unsigned& testX0() { return X0<int>::value; }
int array2[X0<int>::value == sizeof(int)? 1 : -1];
template<typename T>
struct X1 {
static const unsigned value;
};
template<typename T>
const unsigned X1<T>::value = sizeof(T);
int array3[X1<int>::value == sizeof(int)? 1 : -1];
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-type-identity.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// This test concerns the identity of dependent types within the
// canonical type system. This corresponds to C++ [temp.type], which
// specifies type equivalence within a template.
//
// FIXME: template template parameters
namespace N {
template<typename T>
struct X2 {
template<typename U>
struct apply {
typedef U* type;
};
};
}
namespace Nalias = N;
template<typename T>
struct X0 { };
using namespace N;
template<typename T, typename U>
struct X1 {
typedef T type;
typedef U U_type;
void f0(T); // expected-note{{previous}}
void f0(U);
void f0(type); // expected-error{{redeclar}}
void f1(T*); // expected-note{{previous}}
void f1(U*);
void f1(type*); // expected-error{{redeclar}}
void f2(X0<T>*); // expected-note{{previous}}
void f2(X0<U>*);
void f2(X0<type>*); // expected-error{{redeclar}}
void f3(X0<T>*); // expected-note{{previous}}
void f3(X0<U>*);
void f3(::X0<type>*); // expected-error{{redeclar}}
void f4(typename T::template apply<U>*); // expected-note{{previous}}
void f4(typename U::template apply<U>*);
void f4(typename type::template apply<T>*);
void f4(typename type::template apply<U_type>*); // expected-error{{redeclar}}
void f5(typename T::template apply<U>::type*); // expected-note{{previous}}
void f5(typename U::template apply<U>::type*);
void f5(typename U::template apply<T>::type*);
void f5(typename type::template apply<T>::type*);
void f5(typename type::template apply<U_type>::type*); // expected-error{{redeclar}}
void f6(typename N::X2<T>::template apply<U> *); // expected-note{{previous}}
void f6(typename N::X2<U>::template apply<U> *);
void f6(typename N::X2<U>::template apply<T> *);
void f6(typename ::N::X2<type>::template apply<U_type> *); // expected-error{{redeclar}}
void f7(typename N::X2<T>::template apply<U> *); // expected-note{{previous}}
void f7(typename N::X2<U>::template apply<U> *);
void f7(typename N::X2<U>::template apply<T> *);
void f7(typename X2<type>::template apply<U_type> *); // expected-error{{redeclar}}
void f8(typename N::X2<T>::template apply<U> *); // expected-note{{previous}}
void f8(typename N::X2<U>::template apply<U> *);
void f8(typename N::X2<U>::template apply<T> *);
void f8(typename ::Nalias::X2<type>::template apply<U_type> *); // expected-error{{redeclar}}
};
namespace PR6851 {
template <bool v>
struct S;
struct N {
template <bool w>
S< S<w>::cond && 1 > foo();
};
struct Alien;
bool operator&&(const Alien&, const Alien&);
template <bool w>
S< S<w>::cond && 1 > N::foo() { }
}
namespace PR7460 {
template <typename T>
struct TemplateClass2
{
enum { SIZE = 100 };
static T member[SIZE];
};
template <typename T>
T TemplateClass2<T>::member[TemplateClass2<T>::SIZE];
}
namespace PR18275 {
template<typename T> struct A {
void f(const int);
void g(int);
void h(const T);
void i(T);
};
template<typename T>
void A<T>::f(int x) { x = 0; }
template<typename T>
void A<T>::g(const int x) { // expected-note {{declared const here}}
x = 0; // expected-error {{cannot assign to variable 'x'}}
}
template<typename T>
void A<T>::h(T) {} // FIXME: Should reject this. Type is different from prior decl if T is an array type.
template<typename T>
void A<T>::i(const T) {} // FIXME: Should reject this. Type is different from prior decl if T is an array type.
template struct A<int>;
template struct A<int[1]>;
}
namespace PR21289 {
template<typename T> using X = int;
template<typename T, decltype(sizeof(0))> using Y = int;
template<typename ...Ts> struct S {};
template<typename ...Ts> void f() {
// This is a dependent type. It is *not* S<int>, even though it canonically
// contains no template parameters.
using Type = S<X<Ts>...>;
Type s;
using Type = S<int, int, int>;
}
void g() { f<void, void, void>(); }
template<typename ...Ts> void h(S<int>) {}
// Pending a core issue, it's not clear if these are redeclarations, but they
// are probably intended to be... even though substitution can succeed for one
// of them but fail for the other!
template<typename ...Ts> void h(S<X<Ts>...>) {} // expected-note {{previous}}
template<typename ...Ts> void h(S<Y<Ts, sizeof(Ts)>...>) {} // expected-error {{redefinition}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-backtrace.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T> struct A; // expected-note 4{{template is declared here}}
template<typename T> struct B : A<T*> { }; // expected-error{{implicit instantiation of undefined template}} \
// expected-error{{implicit instantiation of undefined template 'A<X *>'}}
template<typename T> struct C : B<T> { } ; // expected-note{{instantiation of template class}}
template<typename T> struct D : C<T> { }; // expected-note{{instantiation of template class}}
template<typename T> struct E : D<T> { }; // expected-note{{instantiation of template class}}
template<typename T> struct F : E<T(T)> { }; // expected-note{{instantiation of template class}}
void f() {
(void)sizeof(F<int>); // expected-note{{instantiation of template class}}
}
typedef struct { } X;
void g() {
(void)sizeof(B<X>); // expected-note{{in instantiation of template class 'B<X>' requested here}}
}
template<typename T>
struct G : A<T>, // expected-error{{implicit instantiation of undefined template 'A<int>'}}
A<T*> // expected-error{{implicit instantiation of undefined template 'A<int *>'}}
{ };
void h() {
(void)sizeof(G<int>); // expected-note{{in instantiation of template class 'G<int>' requested here}}
}
namespace PR13365 {
template <class T> class ResultTy { // expected-warning {{does not declare any constructor}}
T t; // expected-note {{reference member 't' will never be initialized}}
};
template <class T1, class T2>
typename ResultTy<T2>::error Deduce( void (T1::*member)(T2) ) {} // \
// expected-note {{instantiation of template class 'PR13365::ResultTy<int &>'}} \
// expected-note {{substitution failure [with T1 = PR13365::Cls, T2 = int &]}}
struct Cls {
void method(int&);
};
void test() {
Deduce(&Cls::method); // expected-error {{no matching function}} \
// expected-note {{substituting deduced template arguments into function template 'Deduce' [with T1 = PR13365::Cls, T2 = int &]}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_class_spec_blocks.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
// expected-no-diagnostics
template<typename T>
struct is_unary_block {
static const bool value = false;
};
template<typename T, typename U>
struct is_unary_block<T (^)(U)> {
static const bool value = true;
};
int is_unary_block0[is_unary_block<int>::value ? -1 : 1];
int is_unary_block1[is_unary_block<int (^)()>::value ? -1 : 1];
int is_unary_block2[is_unary_block<int (^)(int, bool)>::value ? -1 : 1];
int is_unary_block3[is_unary_block<int (^)(bool)>::value ? 1 : -1];
int is_unary_block4[is_unary_block<int (^)(int)>::value ? 1 : -1];
template<typename T>
struct is_unary_block_with_same_return_type_as_argument_type {
static const bool value = false;
};
template<typename T>
struct is_unary_block_with_same_return_type_as_argument_type<T (^)(T)> {
static const bool value = true;
};
int is_unary_block5[is_unary_block_with_same_return_type_as_argument_type<int>::value ? -1 : 1];
int is_unary_block6[is_unary_block_with_same_return_type_as_argument_type<int (^)()>::value ? -1 : 1];
int is_unary_block7[is_unary_block_with_same_return_type_as_argument_type<int (^)(int, bool)>::value ? -1 : 1];
int is_unary_block8[is_unary_block_with_same_return_type_as_argument_type<int (^)(bool)>::value ? -1 : 1];
int is_unary_block9[is_unary_block_with_same_return_type_as_argument_type<int (^)(int)>::value ? 1 : -1];
int is_unary_block10[is_unary_block_with_same_return_type_as_argument_type<int (^)(int, ...)>::value ? -1 : 1];
int is_unary_block11[is_unary_block_with_same_return_type_as_argument_type<int (^ const)(int)>::value ? -1 : 1];
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-default-1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T, typename U = const T> struct Def1;
template<> struct Def1<int> {
void foo();
};
template<> struct Def1<const int> { // expected-note{{previous definition is here}}
void bar();
};
template<> struct Def1<int&> {
void wibble();
};
void test_Def1(Def1<int, const int> *d1, Def1<const int, const int> *d2,
Def1<int&, int&> *d3) {
d1->foo();
d2->bar();
d3->wibble();
}
template<typename T, // FIXME: bad error message below, needs better location info
typename T2 = const T*> // expected-error{{'T2' declared as a pointer to a reference}}
struct Def2;
template<> struct Def2<int> {
void foo();
};
void test_Def2(Def2<int, int const*> *d2) {
d2->foo();
}
typedef int& int_ref_t;
Def2<int_ref_t> *d2; // expected-note{{in instantiation of default argument for 'Def2<int &>' required here}}
template<> struct Def1<const int, const int> { }; // expected-error{{redefinition of 'Def1<const int>'}}
template<typename T, typename T2 = T&> struct Def3;
template<> struct Def3<int> {
void foo();
};
template<> struct Def3<int&> {
void bar();
};
void test_Def3(Def3<int, int&> *d3a, Def3<int&, int&> *d3b) {
d3a->foo();
d3b->bar();
}
template<typename T, typename T2 = T[]> struct Def4;
template<> struct Def4<int> {
void foo();
};
void test_Def4(Def4<int, int[]> *d4a) {
d4a->foo();
}
template<typename T, typename T2 = T const[12]> struct Def5;
template<> struct Def5<int> {
void foo();
};
template<> struct Def5<int, int const[13]> {
void bar();
};
void test_Def5(Def5<int, const int[12]> *d5a, Def5<int, const int[13]> *d5b) {
d5a->foo();
d5b->bar();
}
template<typename R, typename Arg1, typename Arg2 = Arg1,
typename FuncType = R (*)(Arg1, Arg2)>
struct Def6;
template<> struct Def6<int, float> {
void foo();
};
template<> struct Def6<bool, int[5], float(double, double)> {
void bar();
};
bool test_Def6(Def6<int, float, float> *d6a,
Def6<int, float, float, int (*)(float, float)> *d6b,
Def6<bool, int[5], float(double, double),
bool(*)(int*, float(*)(double, double))> *d6c) {
d6a->foo();
d6b->foo();
d6c->bar();
return d6a == d6b;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/lookup-dependent-bases.cpp
|
// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %s
namespace basic {
struct C {
static void foo2() {}
};
template <typename T>
struct A {
typedef C D;
};
template <typename T>
struct B : A<T> {
void foo() {
D::foo2(); // expected-warning {{use of undeclared identifier 'D'; unqualified lookup into dependent bases of class template 'B' is a Microsoft extension}}
}
};
template struct B<int>; // Instantiation has no warnings.
}
namespace nested_nodep_base {
// There are limits to our hacks, MSVC accepts this, but we don't.
struct A {
struct D { static void foo2(); };
};
template <typename T>
struct B : T {
struct C {
void foo() {
D::foo2(); // expected-error {{use of undeclared identifier 'D'}}
}
};
};
template struct B<A>; // Instantiation has no warnings.
}
namespace nested_dep_base {
// We actually accept this because the inner class has a dependent base even
// though it isn't a template.
struct A {
struct D { static void foo2(); };
};
template <typename T>
struct B {
struct C : T {
void foo() {
D::foo2(); // expected-warning {{use of undeclared identifier 'D'; unqualified lookup into dependent bases of class template 'C' is a Microsoft extension}}
}
};
};
template struct B<A>; // Instantiation has no warnings.
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-clang.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// Test template instantiation for Clang-specific features.
// ---------------------------------------------------------------------
// Vector types
// ---------------------------------------------------------------------
typedef __attribute__(( ext_vector_type(2) )) double double2;
typedef __attribute__(( ext_vector_type(4) )) double double4;
template<typename T>
struct ExtVectorAccess0 {
void f(T v1, double4 v2) {
v1.xy = v2.yx;
}
};
template struct ExtVectorAccess0<double2>;
template struct ExtVectorAccess0<double4>;
typedef __attribute__(( ext_vector_type(2) )) double double2;
template<typename T, typename U, int N, int M>
struct ShuffleVector0 {
void f(T t, U u, double2 a, double2 b) {
(void)__builtin_shufflevector(t, u, N, M); // expected-error{{index}}
(void)__builtin_shufflevector(a, b, N, M); // expected-error{{index}}
(void)__builtin_shufflevector(a, b, 2, 1);
}
};
template struct ShuffleVector0<double2, double2, 2, 1>;
template struct ShuffleVector0<double2, double2, 4, 3>; // expected-note{{instantiation}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// PR5311
template<typename T>
class StringSwitch {
public:
template<unsigned N>
void Case(const char (&S)[N], const int & Value) {
}
};
void test_stringswitch(int argc, char *argv[]) {
(void)StringSwitch<int>();
}
namespace PR6986 {
template<class Class,typename Type,Type Class::*>
struct non_const_member_base
{
};
template<class Class,typename Type,Type Class::*PtrToMember>
struct member: non_const_member_base<Class,Type,PtrToMember>
{
};
struct test_class
{
int int_member;
};
typedef member< test_class,const int,&test_class::int_member > ckey_m;
void test()
{
ckey_m m;
}
}
namespace rdar8980215 {
enum E { E1, E2, E3 };
template<typename T, E e = E2>
struct X0 {
X0() {}
template<typename U> X0(const X0<U, e> &);
};
template<typename T>
struct X1 : X0<T> {
X1() {}
template<typename U> X1(const X1<U> &x) : X0<T>(x) { }
};
X1<int> x1i;
X1<float> x1f(x1i);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/class-template-decl.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T> class A;
extern "C++" {
template<typename T> class B;
}
namespace N {
template<typename T> class C;
}
extern "C" {
template<typename T> class D; // expected-error{{templates must have C++ linkage}}
}
extern "C" {
class PR17968 {
template<typename T> class D; // expected-error{{templates must have C++ linkage}}
template<typename T> void f(); // expected-error{{templates must have C++ linkage}}
};
}
template<class U> class A; // expected-note{{previous template declaration is here}}
template<int N> class A; // expected-error{{template parameter has a different kind in template redeclaration}}
template<int N> class NonTypeTemplateParm;
typedef int INT;
template<INT M> class NonTypeTemplateParm; // expected-note{{previous non-type template parameter with type 'INT' (aka 'int') is here}}
template<long> class NonTypeTemplateParm; // expected-error{{template non-type parameter has a different type 'long' in template redeclaration}}
template<template<typename T> class X> class TemplateTemplateParm;
template<template<class> class Y> class TemplateTemplateParm; // expected-note{{previous template declaration is here}} \
// expected-note{{previous template template parameter is here}}
template<typename> class TemplateTemplateParm; // expected-error{{template parameter has a different kind in template redeclaration}}
template<template<typename T, int> class X> class TemplateTemplateParm; // expected-error{{too many template parameters in template template parameter redeclaration}}
template<typename T>
struct test {}; // expected-note{{previous definition}}
template<typename T>
struct test : T {}; // expected-error{{redefinition}}
class X {
public:
template<typename T> class C;
};
void f() {
template<typename T> class X; // expected-error{{expression}}
}
template<typename T> class X1 var; // expected-warning{{variable templates are a C++14 extension}} \
// expected-error {{variable has incomplete type 'class X1'}} \
// expected-note {{forward declaration of 'X1'}}
namespace M {
}
template<typename T> class M::C3 { }; // expected-error{{out-of-line definition of 'C3' does not match any declaration in namespace 'M'}}
namespace PR8001 {
template<typename T1>
struct Foo {
template<typename T2> class Bar;
typedef Bar<T1> Baz;
template<typename T2>
struct Bar {
Bar() {}
};
};
void pr8001() {
Foo<int>::Baz x;
Foo<int>::Bar<int> y(x);
}
}
namespace rdar9676205 {
template <unsigned, class _Tp> class tuple_element;
template <class _T1, class _T2> class pair;
template <class _T1, class _T2>
class tuple_element<0, pair<_T1, _T2> >
{
template <class _Tp>
struct X
{
template <class _Up, bool = X<_Up>::value>
struct Y
: public X<_Up>,
public Y<_Up>
{ };
};
};
}
namespace redecl {
int A; // expected-note {{here}}
template<typename T> struct A; // expected-error {{different kind of symbol}}
int B; // expected-note {{here}}
template<typename T> struct B { // expected-error {{different kind of symbol}}
};
template<typename T> struct F;
template<typename T> struct K;
int G, H; // expected-note {{here}}
struct S {
int C; // expected-note {{here}}
template<typename T> struct C; // expected-error {{different kind of symbol}}
int D; // expected-note {{here}}
template<typename T> struct D { // expected-error {{different kind of symbol}}
};
int E;
template<typename T> friend struct E { // expected-error {{cannot define a type in a friend}}
};
int F;
template<typename T> friend struct F; // ok, redecl::F
template<typename T> struct G; // ok
template<typename T> friend struct H; // expected-error {{different kind of symbol}}
int I, J, K;
struct U {
template<typename T> struct I; // ok
template<typename T> struct J { // ok
};
template<typename T> friend struct K; // ok, redecl::K
};
};
}
extern "C" template <typename T> // expected-error{{templates must have C++ linkage}}
void DontCrashOnThis() {
T &pT = T();
pT;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/crash-10438657.cpp
|
// RUN: not %clang_cc1 -fsyntax-only %s 2> %t
// RUN: FileCheck %s < %t
// CHECK: 10 errors
template<typename _CharT>
class collate : public locale::facet {
protected:
virtual ~collate() {}
class wxObject;
class __attribute__ ((visibility("default"))) wxGDIRefData
: public wxObjectRefData {};
class __attribute__ ((visibility("default"))) wxGDIObject : public wxObject { \
public:
virtual bool IsOk() const {
return m_refData && static_cast<wxGDIRefData *>(m_refData)->IsOk();
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/address-spaces.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
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;
};
typedef int __attribute__((address_space(1))) int_1;;
typedef int __attribute__((address_space(2))) int_2;;
typedef int __attribute__((address_space(1))) *int_1_ptr;
typedef int_2 *int_2_ptr;
// Check that we maintain address spaces through template argument
// deduction from a type.
template<typename T>
struct remove_pointer {
typedef T type;
};
template<typename T>
struct remove_pointer<T *> {
typedef T type;
};
int check_remove0[is_same<remove_pointer<int_1_ptr>::type, int_1>::value? 1 : -1];
int check_remove1[is_same<remove_pointer<int_2_ptr>::type, int_2>::value? 1 : -1];
int check_remove2[is_same<remove_pointer<int_2_ptr>::type, int>::value? -1 : 1];
int check_remove3[is_same<remove_pointer<int_2_ptr>::type, int_1>::value? -1 : 1];
template<typename T>
struct is_pointer_in_address_space_1 {
static const bool value = false;
};
template<typename T>
struct is_pointer_in_address_space_1<T __attribute__((address_space(1))) *> {
static const bool value = true;
};
int check_ptr_in_as1[is_pointer_in_address_space_1<int_1_ptr>::value? 1 : -1];
int check_ptr_in_as2[is_pointer_in_address_space_1<int_2_ptr>::value? -1 : 1];
int check_ptr_in_as3[is_pointer_in_address_space_1<int*>::value? -1 : 1];
// Check that we maintain address spaces through template argument
// deduction for a call.
template<typename T>
void accept_any_pointer(T*) {
T *x = 1; // expected-error{{cannot initialize a variable of type '__attribute__((address_space(1))) int *' with an rvalue of type 'int'}} \
// expected-error{{cannot initialize a variable of type '__attribute__((address_space(3))) int *' with an rvalue of type 'int'}}
}
void test_accept_any_pointer(int_1_ptr ip1, int_2_ptr ip2) {
static __attribute__((address_space(3))) int array[17];
accept_any_pointer(ip1); // expected-note{{in instantiation of}}
accept_any_pointer(array); // expected-note{{in instantiation of}}
}
template<typename T> struct identity {};
template<typename T>
identity<T> accept_arg_in_address_space_1(__attribute__((address_space(1))) T &ir1);
template<typename T>
identity<T> accept_any_arg(T &ir1);
void test_arg_in_address_space_1() {
static int __attribute__((address_space(1))) int_1;
identity<int> ii = accept_arg_in_address_space_1(int_1);
identity<int __attribute__((address_space(1)))> ii2 = accept_any_arg(int_1);
}
// Partial ordering
template<typename T> int &order1(__attribute__((address_space(1))) T&);
template<typename T> float &order1(T&);
void test_order1() {
static __attribute__((address_space(1))) int i1;
int i;
int &ir = order1(i1);
float &fr = order1(i);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/extern-templates.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
class X0 {
public:
void f(T t);
struct Inner {
void g(T t);
};
};
template<typename T>
void X0<T>::f(T t) {
t = 17; // expected-error{{incompatible}}
}
extern template class X0<int>;
extern template class X0<int*>;
template<typename T>
void X0<T>::Inner::g(T t) {
t = 17; // expected-error{{incompatible}}
}
void test_intptr(X0<int*> xi, X0<int*>::Inner xii) {
xi.f(0);
xii.g(0);
}
extern template class X0<long*>;
void test_longptr(X0<long*> xl, X0<long*>::Inner xli) {
xl.f(0);
xli.g(0);
}
template class X0<long*>; // expected-note 2{{instantiation}}
template<typename T>
class X1 {
public:
void f(T t) { t += 2; }
void g(T t);
};
template<typename T>
void X1<T>::g(T t) {
t += 2;
}
extern template class X1<void*>;
void g_X1(X1<void*> x1, void *ptr) {
x1.g(ptr);
}
extern template void X1<const void*>::g(const void*);
void g_X1_2(X1<const void *> x1, const void *ptr) {
x1.g(ptr);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_explicit_cxx0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
namespace N1 {
template<typename T> struct X0 { }; // expected-note{{here}}
namespace Inner {
template<typename T> struct X1 { };
}
template struct X0<int>;
template struct Inner::X1<int>;
}
template<typename T> struct X2 { }; // expected-note{{here}}
template struct ::N1::Inner::X1<float>;
namespace N2 {
using namespace N1;
template struct X0<double>; // expected-error{{must occur in namespace 'N1'}}
template struct X2<float>; // expected-error{{at global scope}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/typename-specifier-2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename MetaFun, typename T>
struct bind_metafun {
typedef typename MetaFun::template apply<T> type;
};
struct add_pointer {
template<typename T>
struct apply {
typedef T* type;
};
};
int i;
// FIXME: if we make the declarator below a pointer (e.g., with *ip),
// the error message isn't so good because we don't get the handy
// 'aka' telling us that we're dealing with an int**. Should we fix
// getDesugaredType to dig through pointers and such?
bind_metafun<add_pointer, int>::type::type ip = &i;
bind_metafun<add_pointer, float>::type::type fp = &i; // expected-error{{cannot initialize a variable of type 'bind_metafun<add_pointer, float>::type::type' (aka 'float *') with an rvalue of type 'int *'}}
template<typename T>
struct extract_type_type {
typedef typename T::type::type t;
};
double d;
extract_type_type<bind_metafun<add_pointer, double> >::t dp = &d;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/anonymous-union.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// PR5868
struct T0 {
int x;
union {
void *m0;
};
};
template <typename T>
struct T1 : public T0, public T { //expected-warning{{direct base 'T0' is inaccessible due to ambiguity:\n struct T1<struct A> -> struct T0\n struct T1<struct A> -> struct A -> struct T0}}
void f0() {
m0 = 0; // expected-error{{ambiguous conversion}}
}
};
struct A : public T0 { };
void f1(T1<A> *S) { S->f0(); } // expected-note{{instantiation of member function}} expected-note{{in instantiation of template class 'T1<A>' requested here}}
namespace rdar8635664 {
template<typename T>
struct X {
struct inner;
struct inner {
union {
int x;
float y;
};
typedef T type;
};
};
void test() {
X<int>::inner i;
i.x = 0;
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-depth-subst.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify %s -ftemplate-depth 2
// PR9793
template<typename T> auto f(T t) -> decltype(f(t)); // \
// expected-error {{recursive template instantiation exceeded maximum depth of 2}} \
// expected-note 2 {{while substituting}}
struct S {};
int k = f(S{}); // expected-note {{while substituting}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ms-class-specialization-class-scope.cpp
|
// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s -Wno-microsoft
// RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify %s -Wno-microsoft
class A {
public:
template<typename T> struct X { typedef int x; };
X<int>::x a; // expected-note {{implicit instantiation first required here}}
template<> struct X<int>; // expected-error {{explicit specialization of 'A::X<int>' after instantiation}}
template<> struct X<char>; // expected-note {{forward declaration}}
X<char>::x b; // expected-error {{incomplete type 'A::X<char>' named in nested name specifier}}
template<> struct X<double> {
typedef int y;
};
X<double>::y c;
template<> struct X<float> {}; // expected-note {{previous definition is here}}
template<> struct X<float> {}; // expected-error {{redefinition of 'A::X<float>'}}
};
A::X<void>::x axv;
A::X<float>::x axf; // expected-error {{no type named 'x'}}
template<class T> class B {
public:
template<typename U> struct X { typedef int x; };
typename X<int>::x a; // expected-note {{implicit instantiation first required here}}
template<> struct X<int>; // expected-error {{explicit specialization of 'X<int>' after instantiation}}
template<> struct X<char>; // expected-note {{forward declaration}}
typename X<char>::x b; // expected-error {{incomplete type 'B<float>::X<char>' named in nested name specifier}}
template<> struct X<double> {
typedef int y;
};
typename X<double>::y c;
template<> struct X<float> {}; // expected-note {{previous definition is here}}
template<> struct X<T> {}; // expected-error {{redefinition of 'X<float>'}}
};
B<float> b; // expected-note {{in instantiation of}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-member-expr.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic
template<typename T>
struct S {
S() { }
};
template<typename T>
struct vector {
void push_back(const T&) { int a[sizeof(T) ? -1: -1]; } // expected-error {{array with a negative size}}
};
class ExprEngine {
public:
typedef vector<S<void *> >CheckersOrdered;
CheckersOrdered Checkers;
template <typename CHECKER>
void registerCheck(CHECKER *check) {
Checkers.push_back(S<void *>()); // expected-note {{in instantiation of member function 'vector<S<void *> >::push_back' requested here}}
}
};
class RetainReleaseChecker { };
void f(ExprEngine& Eng) {
Eng.registerCheck(new RetainReleaseChecker); // expected-note {{in instantiation of function template specialization 'ExprEngine::registerCheck<RetainReleaseChecker>' requested here}}
}
// PR 5838
namespace test1 {
template<typename T> struct A {
int a;
};
template<typename T> struct B : A<float>, A<T> {
void f() {
a = 0; // should not be ambiguous
}
};
template struct B<int>;
struct O {
int a;
template<typename T> struct B : A<T> {
void f() {
a = 0; // expected-error {{'test1::O::a' is not a member of class 'test1::O::B<int>'}}
}
};
};
template struct O::B<int>; // expected-note {{in instantiation}}
}
// PR7248
namespace test2 {
template <class T> struct A {
void foo() {
T::bar(); // expected-error {{type 'int' cannot}}
}
};
template <class T> class B {
void foo(A<T> a) {
a.test2::template A<T>::foo(); // expected-note {{in instantiation}}
}
};
template class B<int>;
}
namespace PR14124 {
template<typename T> struct S {
int value;
};
template<typename T> void f() { S<T>::value; } // expected-error {{invalid use of non-static data member 'value'}}
template void f<int>(); // expected-note {{in instantiation of}}
struct List { List *next; };
template<typename T, T *(T::*p) = &T::next> struct A {};
A<List> a; // ok
void operator&(struct Whatever);
template<typename T, T *(T::*p) = &T::next> struct B {};
B<List> b; // still ok
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_class_spec.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
struct is_pointer {
static const bool value = false;
};
template<typename T>
struct is_pointer<T*> {
static const bool value = true;
};
template<typename T>
struct is_pointer<const T*> {
static const bool value = true;
};
int array0[is_pointer<int>::value? -1 : 1];
int array1[is_pointer<int*>::value? 1 : -1];
int array2[is_pointer<const int*>::value? 1 : -1];
template<typename T>
struct is_lvalue_reference {
static const bool value = false;
};
template<typename T>
struct is_lvalue_reference<T&> {
static const bool value = true;
};
int lvalue_ref0[is_lvalue_reference<int>::value? -1 : 1];
int lvalue_ref1[is_lvalue_reference<const int&>::value? 1 : -1];
template<typename T>
struct is_const {
static const bool value = false;
};
template<typename T>
struct is_const<const T> {
static const bool value = true;
};
int is_const0[is_const<int>::value? -1 : 1];
int is_const1[is_const<const int>::value? 1 : -1];
int is_const2[is_const<const volatile int>::value? 1 : -1];
int is_const3[is_const<const int [3]>::value? 1 : -1];
int is_const4[is_const<const volatile int[3]>::value? 1 : -1];
int is_const5[is_const<volatile int[3]>::value? -1 : 1];
template<typename T>
struct is_volatile {
static const bool value = false;
};
template<typename T>
struct is_volatile<volatile T> {
static const bool value = true;
};
int is_volatile0[is_volatile<int>::value? -1 : 1];
int is_volatile1[is_volatile<volatile int>::value? 1 : -1];
int is_volatile2[is_volatile<const volatile int>::value? 1 : -1];
int is_volatile3[is_volatile<volatile char[3]>::value? 1 : -1];
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;
};
typedef int INT;
typedef INT* int_ptr;
int is_same0[is_same<int, int>::value? 1 : -1];
int is_same1[is_same<int, INT>::value? 1 : -1];
int is_same2[is_same<const int, int>::value? -1 : 1];
int is_same3[is_same<int_ptr, int>::value? -1 : 1];
template<typename T>
struct remove_reference {
typedef T type;
};
template<typename T>
struct remove_reference<T&> {
typedef T type;
};
int remove_ref0[is_same<remove_reference<int>::type, int>::value? 1 : -1];
int remove_ref1[is_same<remove_reference<int&>::type, int>::value? 1 : -1];
template<typename T>
struct remove_const {
typedef T type;
};
template<typename T>
struct remove_const<const T> {
typedef T type;
};
int remove_const0[is_same<remove_const<const int>::type, int>::value? 1 : -1];
int remove_const1[is_same<remove_const<const int[3]>::type, int[3]>::value? 1 : -1];
template<typename T>
struct is_incomplete_array {
static const bool value = false;
};
template<typename T>
struct is_incomplete_array<T[]> {
static const bool value = true;
};
int incomplete_array0[is_incomplete_array<int>::value ? -1 : 1];
int incomplete_array1[is_incomplete_array<int[1]>::value ? -1 : 1];
int incomplete_array2[is_incomplete_array<bool[]>::value ? 1 : -1];
int incomplete_array3[is_incomplete_array<int[]>::value ? 1 : -1];
template<typename T>
struct is_array_with_4_elements {
static const bool value = false;
};
template<typename T>
struct is_array_with_4_elements<T[4]> {
static const bool value = true;
};
int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1];
int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1];
int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1];
int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1];
template<typename T>
struct get_array_size;
template<typename T, unsigned N>
struct get_array_size<T[N]> {
static const unsigned value = N;
};
int array_size0[get_array_size<int[12]>::value == 12? 1 : -1];
template<typename T>
struct remove_extent {
typedef T type;
};
template<typename T>
struct remove_extent<T[]> {
typedef T type;
};
template<typename T, unsigned N>
struct remove_extent<T[N]> {
typedef T type;
};
int remove_extent0[is_same<remove_extent<int[][5]>::type, int[5]>::value? 1 : -1];
int remove_extent1[is_same<remove_extent<const int[][5]>::type, const int[5]>::value? 1 : -1];
template<typename T>
struct is_unary_function {
static const bool value = false;
};
template<typename T, typename U>
struct is_unary_function<T (*)(U)> {
static const bool value = true;
};
int is_unary_function0[is_unary_function<int>::value ? -1 : 1];
int is_unary_function1[is_unary_function<int (*)()>::value ? -1 : 1];
int is_unary_function2[is_unary_function<int (*)(int, bool)>::value ? -1 : 1];
int is_unary_function3[is_unary_function<int (*)(bool)>::value ? 1 : -1];
int is_unary_function4[is_unary_function<int (*)(int)>::value ? 1 : -1];
template<typename T>
struct is_unary_function_with_same_return_type_as_argument_type {
static const bool value = false;
};
template<typename T>
struct is_unary_function_with_same_return_type_as_argument_type<T (*)(T)> {
static const bool value = true;
};
int is_unary_function5[is_unary_function_with_same_return_type_as_argument_type<int>::value ? -1 : 1];
int is_unary_function6[is_unary_function_with_same_return_type_as_argument_type<int (*)()>::value ? -1 : 1];
int is_unary_function7[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, bool)>::value ? -1 : 1];
int is_unary_function8[is_unary_function_with_same_return_type_as_argument_type<int (*)(bool)>::value ? -1 : 1];
int is_unary_function9[is_unary_function_with_same_return_type_as_argument_type<int (*)(int)>::value ? 1 : -1];
int is_unary_function10[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, ...)>::value ? -1 : 1];
int is_unary_function11[is_unary_function_with_same_return_type_as_argument_type<int (* const)(int)>::value ? -1 : 1];
template<typename T>
struct is_binary_function {
static const bool value = false;
};
template<typename R, typename T1, typename T2>
struct is_binary_function<R(T1, T2)> {
static const bool value = true;
};
int is_binary_function0[is_binary_function<int(float, double)>::value? 1 : -1];
template<typename T>
struct is_member_pointer {
static const bool value = false;
};
template<typename T, typename Class>
struct is_member_pointer<T Class::*> {
static const bool value = true;
};
struct X { };
int is_member_pointer0[is_member_pointer<int X::*>::value? 1 : -1];
int is_member_pointer1[is_member_pointer<const int X::*>::value? 1 : -1];
int is_member_pointer2[is_member_pointer<int (X::*)()>::value? 1 : -1];
int is_member_pointer3[is_member_pointer<int (X::*)(int) const>::value? 1 : -1];
int is_member_pointer4[is_member_pointer<int (X::**)(int) const>::value? -1 : 1];
int is_member_pointer5[is_member_pointer<int>::value? -1 : 1];
template<typename T>
struct is_member_function_pointer {
static const bool value = false;
};
template<typename T, typename Class>
struct is_member_function_pointer<T (Class::*)()> {
static const bool value = true;
};
template<typename T, typename Class>
struct is_member_function_pointer<T (Class::*)() const> {
static const bool value = true;
};
template<typename T, typename Class>
struct is_member_function_pointer<T (Class::*)() volatile> {
static const bool value = true;
};
template<typename T, typename Class>
struct is_member_function_pointer<T (Class::*)() const volatile> {
static const bool value = true;
};
template<typename T, typename Class, typename A1>
struct is_member_function_pointer<T (Class::*)(A1)> {
static const bool value = true;
};
template<typename T, typename Class, typename A1>
struct is_member_function_pointer<T (Class::*)(A1) const> {
static const bool value = true;
};
template<typename T, typename Class, typename A1>
struct is_member_function_pointer<T (Class::*)(A1) volatile> {
static const bool value = true;
};
template<typename T, typename Class, typename A1>
struct is_member_function_pointer<T (Class::*)(A1) const volatile> {
static const bool value = true;
};
int is_member_function_pointer0[
is_member_function_pointer<int X::*>::value? -1 : 1];
int is_member_function_pointer1[
is_member_function_pointer<int (X::*)()>::value? 1 : -1];
int is_member_function_pointer2[
is_member_function_pointer<X (X::*)(X&)>::value? 1 : -1];
int is_member_function_pointer3[
is_member_function_pointer<int (X::*)() const>::value? 1 : -1];
int is_member_function_pointer4[
is_member_function_pointer<int (X::*)(float) const>::value? 1 : -1];
// Test substitution of non-dependent arguments back into the template
// argument list of the class template partial specialization.
template<typename T, typename ValueType = T>
struct is_nested_value_type_identity {
static const bool value = false;
};
template<typename T>
struct is_nested_value_type_identity<T, typename T::value_type> {
static const bool value = true;
};
template<typename T>
struct HasValueType {
typedef T value_type;
};
struct HasIdentityValueType {
typedef HasIdentityValueType value_type;
};
struct NoValueType { };
int is_nested_value_type_identity0[
is_nested_value_type_identity<HasValueType<int> >::value? -1 : 1];
int is_nested_value_type_identity1[
is_nested_value_type_identity<HasIdentityValueType>::value? 1 : -1];
int is_nested_value_type_identity2[
is_nested_value_type_identity<NoValueType>::value? -1 : 1];
// C++ [temp.class.spec]p4:
template<class T1, class T2, int I> class A { }; //#1
template<class T, int I> class A<T, T*, I> { }; //#2
template<class T1, class T2, int I> class A<T1*, T2, I> { }; //#3
template<class T> class A<int, T*, 5> { }; //#4
template<class T1, class T2, int I> class A<T1, T2*, I> { }; //#5
// Redefinition of class template partial specializations
template<typename T, T N, typename U> class A0;
template<typename T, T N> class A0<T, N, int> { }; // expected-note{{here}}
template<typename T, T N> class A0<T, N, int>;
template<typename T, T N> class A0<T, N, int> { }; // expected-error{{redef}}
namespace PR6025 {
template< int N > struct A;
namespace N
{
template< typename F >
struct B;
}
template< typename Protect, typename Second >
struct C;
template <class T>
struct C< T, A< N::B<T>::value > >
{
};
}
namespace PR6181 {
template <class T>
class a;
class s;
template <class U>
class a<s> // expected-error{{partial specialization of 'a' does not use any of its template parameters}}
{
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-declref.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace N {
struct Outer {
struct Inner {
template<typename T>
struct InnerTemplate {
struct VeryInner {
typedef T type;
static enum K1 { K1Val = sizeof(T) } Kind1;
static enum { K2Val = sizeof(T)*2 } Kind2;
enum { K3Val = sizeof(T)*2 } Kind3;
void foo() {
K1 k1 = K1Val;
Kind1 = K1Val;
Outer::Inner::InnerTemplate<type>::VeryInner::Kind2 = K2Val;
Kind3 = K3Val;
}
struct UeberInner {
void bar() {
K1 k1 = K1Val;
Kind1 = K1Val;
Outer::Inner::InnerTemplate<type>::VeryInner::Kind2 = K2Val;
InnerTemplate t;
InnerTemplate<type> t2;
}
};
};
};
};
};
}
typedef int INT;
template struct N::Outer::Inner::InnerTemplate<INT>::VeryInner;
template struct N::Outer::Inner::InnerTemplate<INT>::UeberInner; // expected-error{{no struct named 'UeberInner' in 'N::Outer::Inner::InnerTemplate<int>'}}
namespace N2 {
struct Outer2 {
template<typename T, typename U = T>
struct Inner {
void foo() {
enum { K1Val = sizeof(T) } k1;
enum K2 { K2Val = sizeof(T)*2 } k2a;
K2 k2b = K2Val;
struct S { T x, y; } s1;
struct { U x, y; } s2;
s1.x = s2.x; // expected-error{{incompatible}}
typedef T type;
type t2 = s1.x;
typedef struct { T z; } type2;
type2 t3 = { s1.x };
Inner i1;
i1.foo();
Inner<T> i2;
i2.foo();
}
};
};
}
template struct N2::Outer2::Inner<float>;
template struct N2::Outer2::Inner<int*, float*>; // expected-note{{instantiation}}
// Test dependent pointer-to-member expressions.
template<typename T>
struct smart_ptr {
struct safe_bool {
int member;
};
operator int safe_bool::*() const {
return ptr? &safe_bool::member : 0;
}
T* ptr;
};
void test_smart_ptr(smart_ptr<int> p) {
if (p) { }
}
// PR5517
namespace test0 {
template <int K> struct X {
X() { extern void x(); }
};
void g() { X<2>(); }
}
// <rdar://problem/8302161>
namespace test1 {
template <typename T> void f(T const &t) {
union { char c; T t_; };
c = 'a'; // <- this shouldn't silently fail to instantiate
T::foo(); // expected-error {{has no members}}
}
template void f(int const &); // expected-note {{requested here}}
}
namespace test2 {
template<typename T> void f() {
T::error; // expected-error {{no member}}
}
void g() {
// This counts as an odr-use, so should trigger the instantiation of f<int>.
(void)&f<int>; // expected-note {{here}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiation-depth-defarg.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 128 -ftemplate-backtrace-limit 4 %s
template<int N> struct S {
typedef typename S<N-1>::type type;
static int f(int n = S<N-1>::f()); // \
// expected-error{{recursive template instantiation exceeded maximum depth of 128}} \
// expected-note 3 {{instantiation of default function argument}} \
// expected-note {{skipping 125 contexts in backtrace}} \
// expected-note {{use -ftemplate-depth=N to increase recursive template instantiation depth}}
};
template<> struct S<0> {
typedef int type;
};
// Incrementally instantiate up to S<2048>.
template struct S<128>;
template struct S<256>;
template struct S<384>;
template struct S<512>;
template struct S<640>;
template struct S<768>;
template struct S<896>;
template struct S<1024>;
template struct S<1152>;
template struct S<1280>;
template struct S<1408>;
template struct S<1536>;
template struct S<1664>;
template struct S<1792>;
template struct S<1920>;
template struct S<2048>;
// Check that we actually bail out when we hit the instantiation depth limit for
// the default arguments.
void g() { S<2048>::f(); } // expected-note {{required here}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-enum-2.cpp
|
// RUN: %clang_cc1 %s -fsyntax-only -verify
// expected-no-diagnostics
template<int IntBits> struct X {
enum {
IntShift = (unsigned long long)IntBits,
ShiftedIntMask = (1 << IntShift)
};
};
X<1> x;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-call.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace N1 {
struct X0 { };
int& f0(X0);
}
namespace N2 {
char& f0(char);
template<typename T, typename Result>
struct call_f0 {
void test_f0(T t) {
Result result = f0(t);
}
};
}
template struct N2::call_f0<int, char&>;
template struct N2::call_f0<N1::X0, int&>;
namespace N3 {
template<typename T, typename Result>
struct call_f0 {
void test_f0(T t) {
Result &result = f0(t); // expected-error {{undeclared identifier}} \
expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
}
};
}
template struct N3::call_f0<int, char&>; // expected-note{{instantiation}}
template struct N3::call_f0<N1::X0, int&>;
short& f0(char); // expected-note {{should be declared prior to the call site}}
namespace N4 {
template<typename T, typename Result>
struct call_f0 {
void test_f0(T t) {
Result &result = f0(t);
}
};
}
template struct N4::call_f0<int, short&>;
template struct N4::call_f0<N1::X0, int&>;
template struct N3::call_f0<int, short&>; // expected-note{{instantiation}}
// FIXME: test overloaded function call operators, calls to member
// functions, etc.
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-attr.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
template <typename T>
struct A {
char a __attribute__((aligned(16)));
struct B {
typedef T __attribute__((aligned(16))) i16;
i16 x;
};
};
int a[sizeof(A<int>) == 16 ? 1 : -1];
int a2[sizeof(A<int>::B) == 16 ? 1 : -1];
// rdar://problem/8243419
namespace test1 {
template <typename T> struct A {
int a;
T b[0];
} __attribute__((packed));
typedef A<unsigned long> type;
int test0[sizeof(type) == 4 ? 1 : -1];
int test1[__builtin_offsetof(type, a) == 0 ? 1 : -1];
int test2[__builtin_offsetof(type, b) == 4 ? 1 : -1];
}
namespace test2 {
template <class type>
struct fastscriptmember {
type Member __attribute__ ((packed));
char x;
};
int test0[sizeof(fastscriptmember<int>) == 5 ? 1 : -1];
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/atomics.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// PR8345
template<typename T> T f(T* value) {
return __sync_add_and_fetch(value, 1);
}
int g(long long* x) { return f(x); }
int g(int* x) { return f(x); }
namespace PR11320 {
template<typename T>
void g(unsigned *x) {
__sync_bool_compare_and_swap(x, 1, 4);
}
void h() { g<int>(0); }
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-try-catch.cpp
|
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -std=c++11 -verify %s
template<typename T> struct TryCatch0 {
void f() {
try {
} catch (T&&) { // expected-error 2{{cannot catch exceptions by rvalue reference}}
}
}
};
template struct TryCatch0<int&>; // okay
template struct TryCatch0<int&&>; // expected-note{{instantiation}}
template struct TryCatch0<int>; // expected-note{{instantiation}}
namespace PR10232 {
template <typename T>
class Templated {
struct Exception {
private:
Exception(const Exception&); // expected-note{{declared private here}}
};
void exception() {
try {
} catch(Exception e) { // expected-error{{calling a private constructor of class 'PR10232::Templated<int>::Exception'}}
}
}
};
template class Templated<int>; // expected-note{{in instantiation of member function 'PR10232::Templated<int>::exception' requested here}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/class-template-ctor-initializer.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<class X> struct A {};
template<class X> struct B : A<X> {
B() : A<X>() {}
};
B<int> x;
template<class X> struct B1 : A<X> {
typedef A<X> Base;
B1() : Base() {}
};
B1<int> x1;
template<typename T> struct Tmpl { };
template<typename T> struct TmplB { };
struct TmplC : Tmpl<int> {
TmplC() :
Tmpl<int>(),
TmplB<int>() { } // expected-error {{type 'TmplB<int>' is not a direct or virtual base of 'TmplC'}}
};
struct TmplD : Tmpl<char>, TmplB<char> {
TmplD():
Tmpl<int>(), // expected-error {{type 'Tmpl<int>' is not a direct or virtual base of 'TmplD'}}
TmplB<char>() {}
};
namespace PR7259 {
class Base {
public:
Base() {}
};
template <class ParentClass>
class Derived : public ParentClass {
public:
Derived() : Base() {}
};
class Final : public Derived<Base> {
};
int
main (void)
{
Final final;
return 0;
}
}
namespace NonDependentError {
struct Base { Base(int); }; // expected-note 2{{candidate}}
template<typename T>
struct Derived1 : Base {
Derived1() : Base(1, 2) {} // expected-error {{no matching constructor}}
};
template<typename T>
struct Derived2 : Base {
Derived2() : BaseClass(1) {} // expected-error {{does not name a non-static data member or base}}
};
Derived1<void> d1;
Derived2<void> d2;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/unused-variables.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wunused -verify %s
struct X0 {
~X0();
};
struct X1 { };
template<typename T>
void f() {
X0 x0;
X1 x1; // expected-warning{{unused variable 'x1'}}
}
template<typename T, typename U>
void g() {
T t;
U u; // expected-warning{{unused variable 'u'}}
}
template void g<X0, X1>(); // expected-note{{in instantiation of}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/class-template-spec.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T, typename U = int> struct A; // expected-note {{template is declared here}} \
// expected-note{{explicitly specialized}}
template<> struct A<double, double>; // expected-note{{forward declaration}}
template<> struct A<float, float> { // expected-note{{previous definition}}
int x;
};
template<> struct A<float> { // expected-note{{previous definition}}
int y;
};
int test_specs(A<float, float> *a1, A<float, int> *a2) {
return a1->x + a2->y;
}
int test_incomplete_specs(A<double, double> *a1,
A<double> *a2)
{
(void)a1->x; // expected-error{{member access into incomplete type}}
(void)a2->x; // expected-error{{implicit instantiation of undefined template 'A<double, int>'}}
}
typedef float FLOAT;
template<> struct A<float, FLOAT>;
template<> struct A<FLOAT, float> { }; // expected-error{{redefinition}}
template<> struct A<float, int> { }; // expected-error{{redefinition}}
template<typename T, typename U = int> struct X;
template <> struct X<int, int> { int foo(); }; // #1
template <> struct X<float> { int bar(); }; // #2
typedef int int_type;
void testme(X<int_type> *x1, X<float, int> *x2) {
(void)x1->foo(); // okay: refers to #1
(void)x2->bar(); // okay: refers to #2
}
// Make sure specializations are proper classes.
template<>
struct A<char> {
A();
};
A<char>::A() { }
// Make sure we can see specializations defined before the primary template.
namespace N{
template<typename T> struct A0;
}
namespace N {
template<>
struct A0<void> {
typedef void* pointer;
};
}
namespace N {
template<typename T>
struct A0 {
void foo(A0<void>::pointer p = 0);
};
}
// Diagnose specialization errors
struct A<double> { }; // expected-error{{template specialization requires 'template<>'}}
template<> struct ::A<double>;
namespace N {
template<typename T> struct B; // expected-note 2{{explicitly specialized}}
template<> struct ::N::B<char>; // okay
template<> struct ::N::B<short>; // okay
template<> struct ::N::B<int>; // okay
int f(int);
}
template<> struct N::B<int> { }; // okay
template<> struct N::B<float> { }; // expected-warning{{C++11 extension}}
namespace M {
template<> struct ::N::B<short> { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}}
template<> struct ::A<long double>; // expected-error{{must occur at global scope}}
}
template<> struct N::B<char> {
int testf(int x) { return f(x); }
};
// PR5264
template <typename T> class Foo;
Foo<int>* v;
Foo<int>& F() { return *v; }
template <typename T> class Foo {};
Foo<int> x;
// Template template parameters
template<template<class T> class Wibble>
class Wibble<int> { }; // expected-error{{cannot specialize a template template parameter}}
namespace rdar9676205 {
template<typename T>
struct X {
template<typename U>
struct X<U*> { // expected-error{{explicit specialization of 'X' in class scope}}
};
};
}
namespace PR18009 {
template <typename T> struct A {
template <int N, int M> struct S;
template <int N> struct S<N, sizeof(T)> {};
};
A<int>::S<8, sizeof(int)> a; // ok
template <typename T> struct B {
template <int N, int M> struct S; // expected-note {{declared here}}
template <int N> struct S<N, sizeof(T) +
N // expected-error {{non-type template argument depends on a template parameter of the partial specialization}}
> {};
};
B<int>::S<8, sizeof(int) + 8> s; // expected-error {{undefined}}
template<int A> struct outer {
template<int B, int C> struct inner {};
template<int C> struct inner<A * 2, C> {};
};
}
namespace PR16519 {
template<typename T, T...N> struct integer_sequence { typedef T value_type; }; // expected-warning {{extension}}
template<typename T> struct __make_integer_sequence;
template<typename T, T N> using make_integer_sequence = typename __make_integer_sequence<T>::template make<N, N % 2>::type; // expected-warning {{extension}}
template<typename T, typename T::value_type ...Extra> struct __make_integer_sequence_impl; // expected-warning {{extension}}
template<typename T, T ...N, T ...Extra> struct __make_integer_sequence_impl<integer_sequence<T, N...>, Extra...> { // expected-warning 2{{extension}}
typedef integer_sequence<T, N..., sizeof...(N) + N..., Extra...> type;
};
template<typename T> struct __make_integer_sequence {
template<T N, T Parity, typename = void> struct make;
template<typename Dummy> struct make<0, 0, Dummy> { typedef integer_sequence<T> type; };
template<typename Dummy> struct make<1, 1, Dummy> { typedef integer_sequence<T, 0> type; };
template<T N, typename Dummy> struct make<N, 0, Dummy> : __make_integer_sequence_impl<make_integer_sequence<T, N/2> > {};
template<T N, typename Dummy> struct make<N, 1, Dummy> : __make_integer_sequence_impl<make_integer_sequence<T, N/2>, N - 1> {};
};
using X = make_integer_sequence<int, 5>; // expected-warning {{extension}}
using X = integer_sequence<int, 0, 1, 2, 3, 4>; // expected-warning {{extension}}
}
namespace DefaultArgVsPartialSpec {
// Check that the diagnostic points at the partial specialization, not just at
// the default argument.
template<typename T, int N =
sizeof(T) // expected-note {{template parameter is used in default argument declared here}}
> struct X {};
template<typename T> struct X<T> {}; // expected-error {{non-type template argument depends on a template parameter of the partial specialization}}
template<typename T,
T N = 0 // expected-note {{template parameter is declared here}}
> struct S;
template<typename T> struct S<T> {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'T'}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/deduction-crash.cpp
|
// RUN: not %clang_cc1 -fsyntax-only %s -std=c++11 2>&1| FileCheck %s
// Note that the error count below doesn't matter. We just want to
// make sure that the parser doesn't crash.
// CHECK: 16 errors
// PR7511
template<a>
struct int_;
template<a>
template<int,typename T1,typename>
struct ac
{
typedef T1 ae
};
template<class>struct aaa
{
typedef ac<1,int,int>::ae ae
};
template<class>
struct state_machine
{
typedef aaa<int>::ae aaa;
int start()
{
ant(0);
}
template<class>
struct region_processing_helper
{
template<class,int=0>
struct In;
template<int my>
struct In<a::int_<aaa::a>,my>;
template<class Event>
int process(Event)
{
In<a::int_<0> > a;
}
}
template<class Event>
int ant(Event)
{
region_processing_helper<int>* helper;
helper->process(0)
}
};
int a()
{
state_machine<int> p;
p.ant(0);
}
// PR9974
template <int> struct enable_if;
template <class > struct remove_reference ;
template <class _Tp> struct remove_reference<_Tp&> ;
template <class > struct __tuple_like;
template <class _Tp, class _Up, int = __tuple_like<typename remove_reference<_Tp>::type>::value>
struct __tuple_convertible;
struct pair
{
template<class _Tuple, int = enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
pair(_Tuple&& );
};
template <class> struct basic_ostream;
template <int>
void endl( ) ;
extern basic_ostream<char> cout;
int operator<<( basic_ostream<char> , pair ) ;
void register_object_imp ( )
{
cout << endl<1>;
}
// PR12933
namespacae PR12933 {
template<typename S>
template<typename T>
void function(S a, T b) {}
int main() {
function(0, 1);
return 0;
}
}
// A buildbot failure from libcxx
namespace libcxx_test {
template <class _Ptr, bool> struct __pointer_traits_element_type;
template <class _Ptr> struct __pointer_traits_element_type<_Ptr, true>;
template <template <class, class...> class _Sp, class _Tp, class ..._Args> struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> {
typedef char type;
};
template <class T> struct B {};
__pointer_traits_element_type<B<int>, true>::type x;
}
namespace PR14281_part1 {
template <class P, int> struct A;
template <class P> struct A<P, 1>;
template <template <class, int> class S, class T> struct A<S<T, 1>, 1> {
typedef char type;
};
template <class T, int i> struct B {};
A<B<int, 1>, 1>::type x;
}
namespace PR14281_part2 {
typedef decltype(nullptr) nullptr_t;
template <class P, nullptr_t> struct A;
template <class P> struct A<P, nullptr>;
template <template <class, nullptr_t> class S, class T> struct A<S<T, nullptr>, nullptr> {
typedef char type;
};
template <class T, nullptr_t i> struct B {};
A<B<int, nullptr>, nullptr>::type x;
}
namespace PR14281_part3 {
extern int some_decl;
template <class P, int*> struct A;
template <class P> struct A<P, &some_decl>;
template <template <class, int*> class S, class T> struct A<S<T, &some_decl>, &some_decl> {
typedef char type;
};
template <class T, int* i> struct B {};
A<B<int, &some_decl>, &some_decl>::type x;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-expr-2.cpp
|
// RUN: %clang_cc1 -fsyntax-only %s
typedef char one_byte;
typedef char (&two_bytes)[2];
typedef char (&four_bytes)[4];
typedef char (&eight_bytes)[8];
template<int N> struct A { };
namespace N1 {
struct X { };
}
namespace N2 {
struct Y { };
two_bytes operator+(Y, Y);
}
namespace N3 {
struct Z { };
eight_bytes operator+(Z, Z);
}
namespace N4 {
one_byte operator+(N1::X, N2::Y);
template<typename T, typename U>
struct BinOpOverload {
typedef A<sizeof(T() + U())> type;
};
}
namespace N1 {
four_bytes operator+(X, X);
}
namespace N3 {
eight_bytes operator+(Z, Z); // redeclaration
}
void test_bin_op_overload(A<1> *a1, A<2> *a2, A<4> *a4, A<8> *a8) {
typedef N4::BinOpOverload<N1::X, N2::Y>::type XY;
XY *xy = a1;
typedef N4::BinOpOverload<N1::X, N1::X>::type XX;
XX *xx = a4;
typedef N4::BinOpOverload<N2::Y, N2::Y>::type YY;
YY *yy = a2;
typedef N4::BinOpOverload<N3::Z, N3::Z>::type ZZ;
ZZ *zz = a8;
}
namespace N3 {
eight_bytes operator-(::N3::Z);
}
namespace N4 {
template<typename T>
struct UnaryOpOverload {
typedef A<sizeof(-T())> type;
};
}
void test_unary_op_overload(A<8> *a8) {
typedef N4::UnaryOpOverload<N3::Z>::type UZ;
UZ *uz = a8;
}
/*
namespace N5 {
template<int I>
struct Lookup {
enum { val = I, more = val + 1 };
};
template<bool B>
struct Cond {
enum Junk { is = B ? Lookup<B>::more : Lookup<Lookup<B+1>::more>::val };
};
enum { resultT = Cond<true>::is,
resultF = Cond<false>::is };
}
*/
namespace N6 {
// non-typedependent
template<int I>
struct Lookup {};
template<bool B, typename T, typename E>
struct Cond {
typedef Lookup<B ? sizeof(T) : sizeof(E)> True;
typedef Lookup<!B ? sizeof(T) : sizeof(E)> False;
};
typedef Cond<true, int, char>::True True;
typedef Cond<true, int, char>::False False;
// check that we have the right types
Lookup<1> const &L1(False());
Lookup<sizeof(int)> const &L2(True());
}
namespace N7 {
// type dependent
template<int I>
struct Lookup {};
template<bool B, typename T, typename E>
struct Cond {
T foo() { return B ? T() : E(); }
typedef Lookup<sizeof(B ? T() : E())> Type;
};
//Cond<true, int*, double> C; // Errors
//int V(C.foo()); // Errors
//typedef Cond<true, int*, double>::Type Type; // Errors
typedef Cond<true, int, double>::Type Type;
}
template<typename T, unsigned long N> struct IntegralConstant { };
template<typename T>
struct X0 {
void f(T x, IntegralConstant<T, sizeof(x)>);
};
void test_X0(X0<int> x, IntegralConstant<int, sizeof(int)> ic) {
x.f(5,ic);
}
namespace N8 {
struct X {
X operator+(const X&) const;
};
template<typename T>
T test_plus(const T* xp, const T& x, const T& y) {
x.operator+(y);
return xp->operator+(y);
}
void test_test_plus(X x) {
test_plus(&x, x, x);
}
}
namespace N9 {
struct A {
bool operator==(int value);
};
template<typename T> struct B {
bool f(A a) {
return a == 1;
}
};
template struct B<int>;
}
namespace N10 {
template <typename T>
class A {
struct X { };
public:
~A() {
f(reinterpret_cast<X *>(0), reinterpret_cast<X *>(0));
}
private:
void f(X *);
void f(X *, X *);
};
template class A<int>;
}
namespace N12 {
// PR5224
template<typename T>
struct A { typedef int t0; };
struct C {
C(int);
template<typename T>
static C *f0(T a0) {return new C((typename A<T>::t0) 1); }
};
void f0(int **a) { C::f0(a); }
}
namespace PR7202 {
template<typename U, typename T>
struct meta {
typedef T type;
};
struct X {
struct dummy;
template<typename T>
X(T, typename meta<T, dummy*>::type = 0);
template<typename T, typename A>
X(T, A);
};
template<typename T>
struct Z { };
template<typename T> Z<T> g(T);
struct Y {
template<typename T>
void f(T t) {
new X(g(*this));
}
};
template void Y::f(int);
}
namespace N13 {
class A{
A(const A&);
public:
~A();
A(int);
template<typename T> A &operator<<(const T&);
};
template<typename T>
void f(T t) {
A(17) << t;
}
template void f(int);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/array-to-pointer-decay.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
struct mystruct {
int member;
};
template <int i>
int foo() {
mystruct s[1];
return s->member;
}
int main() {
foo<1>();
}
// PR7405
struct hb_sanitize_context_t {
int start;
};
template <typename Type> static bool sanitize() {
hb_sanitize_context_t c[1];
return !c->start;
}
bool closure = sanitize<int>();
// PR16206
typedef struct {
char x[4];
} chars;
chars getChars();
void use(char *);
void test() {
use(getChars().x);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-class-member-operator.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// PR7837
template<class T> struct C1 { void operator()(T); };
template<class T> struct C2; // expected-note {{template is declared here}}
template<class T> void foo(T);
void wrap() {
foo(&C1<int>::operator());
foo(&C1<int>::operator+); // expected-error {{no member named 'operator+' in 'C1<int>'}}
foo(&C2<int>::operator+); // expected-error {{implicit instantiation of undefined template 'C2<int>'}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/nested-template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class A;
class S {
public:
template<typename T> struct A {
struct Nested {
typedef T type;
};
};
};
int i;
S::A<int>::Nested::type *ip = &i;
template<typename T>
struct Outer {
template<typename U>
class Inner0;
template<typename U>
class Inner1 {
struct ReallyInner;
T foo(U);
template<typename V> T bar(V);
template<typename V> T* bar(V);
static T value1;
static U value2;
};
};
template<typename X>
template<typename Y>
class Outer<X>::Inner0 {
public:
void f(X, Y);
};
template<typename X>
template<typename Y>
void Outer<X>::Inner0<Y>::f(X, Y) {
}
template<typename X>
template<typename Y>
struct Outer<X>::Inner1<Y>::ReallyInner {
static Y value3;
void g(X, Y);
};
template<typename X>
template<typename Y>
void Outer<X>::Inner1<Y>::ReallyInner::g(X, Y) {
}
template<typename X>
template<typename Y>
X Outer<X>::Inner1<Y>::foo(Y) {
return X();
}
template<typename X>
template<typename Y>
template<typename Z>
X Outer<X>::Inner1<Y>::bar(Z) {
return X();
}
template<typename X>
template<typename Y>
template<typename Z>
X* Outer<X>::Inner1<Y>::bar(Z) {
return 0;
}
template<typename X>
template<typename Y>
X Outer<X>::Inner1<Y>::value1 = 0;
template<typename X>
template<typename Y>
Y Outer<X>::Inner1<Y>::value2 = Y();
template<typename X>
template<typename Y>
Y Outer<X>::Inner1<Y>::ReallyInner::value3 = Y();
template<typename X>
template<typename Y>
Y Outer<X>::Inner1<Y*>::ReallyInner::value4; // expected-error{{Outer<X>::Inner1<Y *>::ReallyInner::}}
template<typename T>
struct X0 { };
template<typename T>
struct X0<T*> {
template<typename U>
void f(U u = T()) { }
};
// PR5103
template<typename>
struct X1 {
template<typename, bool = false> struct B { };
};
template struct X1<int>::B<bool>;
// Template template parameters
template<typename T>
struct X2 {
template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}} \
// expected-note{{previous non-type template}}
struct Inner { };
};
template<typename T,
int Value> // expected-note{{template non-type parameter}}
struct X2_arg;
X2<int>::Inner<X2_arg> x2i1;
X2<float> x2a; // expected-note{{instantiation}}
X2<long>::Inner<X2_arg> x2i3; // expected-error{{template template argument has different}}
namespace PR10896 {
template<typename TN>
class Foo {
public:
void foo() {}
private:
template<typename T>
T SomeField; // expected-error {{member 'SomeField' declared as a template}}
template<> int SomeField2; // expected-error {{extraneous 'template<>' in declaration of member 'SomeField2'}}
};
void g() {
Foo<int> f;
f.foo();
}
}
namespace PR10924 {
template< class Topology, class ctype >
struct ReferenceElement
{
};
template< class Topology, class ctype >
template< int codim >
class ReferenceElement< Topology, ctype > :: BaryCenterArray // expected-error{{out-of-line definition of 'BaryCenterArray' does not match any declaration in 'ReferenceElement<Topology, ctype>'}}
{
};
}
class Outer1 {
template <typename T> struct X;
template <typename T> int X<T>::func() {} // expected-error{{out-of-line definition of 'func' from class 'X<T>' without definition}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/default-expr-arguments.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
class C { C(int a0 = 0); };
template<>
C<char>::C(int a0);
struct S { }; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
template<typename T> void f1(T a, T b = 10) { } // expected-error{{no viable conversion}} \
// expected-note{{passing argument to parameter 'b' here}}
template<typename T> void f2(T a, T b = T()) { }
template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('S' and 'S')}}
void g() {
f1(10);
f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<S>' required here}}
f2(10);
f2(S());
f3(10);
f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<S>' required here}}
}
template<typename T> struct F {
F(T t = 10); // expected-error{{no viable conversion}} \
// expected-note{{passing argument to parameter 't' here}}
void f(T t = 10); // expected-error{{no viable conversion}} \
// expected-note{{passing argument to parameter 't' here}}
};
struct FD : F<int> { };
void g2() {
F<int> f;
FD fd;
}
void g3(F<int> f, F<struct S> s) {
f.f();
s.f(); // expected-note{{in instantiation of default function argument expression for 'f<S>' required here}}
F<int> f2;
F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<S>' required here}}
}
template<typename T> struct G {
G(T) {}
};
void s(G<int> flags = 10) { }
// Test default arguments
template<typename T>
struct X0 {
void f(T = T()); // expected-error{{no matching}}
};
template<typename U>
void X0<U>::f(U) { }
void test_x0(X0<int> xi) {
xi.f();
xi.f(17);
}
struct NotDefaultConstructible { // expected-note 2{{candidate}}
NotDefaultConstructible(int); // expected-note 2{{candidate}}
};
void test_x0_not_default_constructible(X0<NotDefaultConstructible> xn) {
xn.f(NotDefaultConstructible(17));
xn.f(42);
xn.f(); // expected-note{{in instantiation of default function argument}}
}
template<typename T>
struct X1 {
typedef T value_type;
X1(const value_type& value = value_type());
};
void test_X1() {
X1<int> x1;
}
template<typename T>
struct X2 {
void operator()(T = T()); // expected-error{{no matching}}
};
void test_x2(X2<int> x2i, X2<NotDefaultConstructible> x2n) {
x2i();
x2i(17);
x2n(NotDefaultConstructible(17));
x2n(); // expected-note{{in instantiation of default function argument}}
}
// PR5283
namespace PR5283 {
template<typename T> struct A {
A(T = 1); // expected-error 3 {{cannot initialize a parameter of type 'int *' with an rvalue of type 'int'}} \
// expected-note 3{{passing argument to parameter here}}
};
struct B : A<int*> {
B();
};
B::B() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
struct C : virtual A<int*> {
C();
};
C::C() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
struct D {
D();
A<int*> a;
};
D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
}
// PR5301
namespace pr5301 {
void f(int, int = 0);
template <typename T>
void g(T, T = 0);
template <int I>
void i(int a = I);
template <typename T>
void h(T t) {
f(0);
g(1);
g(t);
i<2>();
}
void test() {
h(0);
}
}
// PR5810
namespace PR5810 {
template<typename T>
struct allocator {
allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error2 {{array with a negative size}}
};
template<typename T>
struct vector {
vector(const allocator<T>& = allocator<T>()) {} // expected-note2 {{instantiation of}}
};
struct A { };
struct B { };
template<typename>
void FilterVTs() {
vector<A> Result;
}
void f() {
vector<A> Result;
}
template<typename T>
struct X {
vector<B> bs;
X() { }
};
void f2() {
X<float> x; // expected-note{{member function}}
}
}
template<typename T> void f4(T, int = 17);
template<> void f4<int>(int, int);
void f4_test(int i) {
f4(i);
}
// Instantiate for initialization
namespace InstForInit {
template<typename T>
struct Ptr {
typedef T* type;
Ptr(type);
};
template<typename T>
struct Holder {
Holder(int i, Ptr<T> ptr = 0);
};
void test_holder(int i) {
Holder<int> h(i);
}
};
namespace PR5810b {
template<typename T>
T broken() {
T t;
double**** not_it = t;
}
void f(int = broken<int>());
void g() { f(17); }
}
namespace PR5810c {
template<typename T>
struct X {
X() {
T t;
double *****p = t; // expected-error{{cannot initialize a variable of type 'double *****' with an lvalue of type 'int'}}
}
X(const X&) { }
};
struct Y : X<int> { // expected-note{{instantiation of}}
};
void f(Y y = Y());
void g() { f(); }
}
namespace PR8127 {
template< typename T > class PointerClass {
public:
PointerClass( T * object_p ) : p_( object_p ) {
p_->acquire();
}
private:
T * p_;
};
class ExternallyImplementedClass;
class MyClass {
void foo( PointerClass<ExternallyImplementedClass> = 0 );
};
}
namespace rdar8427926 {
template<typename T>
struct Boom {
~Boom() {
T t;
double *******ptr = t; // expected-error 2{{cannot initialize}}
}
};
Boom<float> *bfp;
struct X {
void f(Boom<int> = Boom<int>()) { } // expected-note{{requested here}}
void g(int x = (delete bfp, 0)); // expected-note{{requested here}}
};
void test(X *x) {
x->f();
x->g();
}
}
namespace PR8401 {
template<typename T>
struct A {
A() { T* x = 1; } // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
};
template<typename T>
struct B {
B(const A<T>& a = A<T>()); // expected-note{{in instantiation of}}
};
void f(B<int> b = B<int>());
void g() {
f();
}
}
namespace PR12581 {
const int a = 0;
template < typename > struct A;
template < typename MatrixType, int =
A < MatrixType >::Flags ? : A < MatrixType >::Flags & a > class B;
void
fn1 ()
{
}
}
namespace PR13758 {
template <typename T> struct move_from {
T invalid;
};
template <class K>
struct unordered_map {
explicit unordered_map(int n = 42);
unordered_map(move_from<K> other);
};
template<typename T>
void StripedHashTable() {
new unordered_map<void>();
new unordered_map<void>;
}
void tt() {
StripedHashTable<int>();
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/temp_class_spec_neg.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T> struct vector;
// C++ [temp.class.spec]p6:
namespace N {
namespace M {
template<typename T> struct A; // expected-note{{here}}
}
}
template<typename T>
struct N::M::A<T*> { }; // expected-warning{{C++11 extension}}
// C++ [temp.class.spec]p9
// bullet 1
template <int I, int J> struct A {};
template <int I> struct A<I+5, I*2> {}; // expected-error{{depends on}}
template <int I, int J> struct B {};
template <int I> struct B<I, I> {}; //OK
// bullet 2
template <class T, T t> struct C {}; // expected-note{{declared here}}
template <class T> struct C<T, 1>; // expected-error{{specializes}}
template <class T, T* t> struct C<T*, t>; // okay
template< int X, int (*array_ptr)[X] > class A2 {}; // expected-note{{here}}
int array[5];
template< int X > class A2<X, &array> { }; // expected-error{{specializes}}
template<typename T, int N, template<typename X> class TT>
struct Test0;
// bullet 3
template<typename T, int N, template<typename X> class TT>
struct Test0<T, N, TT>; // expected-error{{does not specialize}}
// C++ [temp.class.spec]p10
template<typename T = int, // expected-error{{default template argument}}
int N = 17, // expected-error{{default template argument}}
template<typename X> class TT = ::vector> // expected-error{{default template argument}}
struct Test0<T*, N, TT> { };
template<typename T> struct Test1;
template<typename T, typename U> // expected-note{{non-deducible}}
struct Test1<T*> { }; // expected-warning{{never be used}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/alias-templates.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
template<typename S>
struct A {
typedef S B;
template<typename T> using C = typename T::B;
template<typename T> struct D {
template<typename U> using E = typename A<U>::template C<A<T>>;
template<typename U> using F = A<E<U>>;
template<typename U> using G = C<F<U>>;
G<T> g;
};
typedef decltype(D<B>().g) H;
D<H> h;
template<typename T> using I = A<decltype(h.g)>;
template<typename T> using J = typename A<decltype(h.g)>::template C<I<T>>;
};
A<int> a;
A<char>::D<double> b;
template<typename T> T make();
namespace X {
template<typename T> struct traits {
typedef T thing;
typedef decltype(val(make<thing>())) inner_ptr;
template<typename U> using rebind_thing = typename thing::template rebind<U>;
template<typename U> using rebind = traits<rebind_thing<U>>;
inner_ptr &&alloc();
void free(inner_ptr&&);
};
template<typename T> struct ptr_traits {
typedef T *type;
};
template<typename T> using ptr = typename ptr_traits<T>::type;
template<typename T> struct thing {
typedef T inner;
typedef ptr<inner> inner_ptr;
typedef traits<thing<inner>> traits_type;
template<typename U> using rebind = thing<U>;
thing(traits_type &traits) : traits(traits), val(traits.alloc()) {}
~thing() { traits.free(static_cast<inner_ptr&&>(val)); }
traits_type &traits;
inner_ptr val;
friend inner_ptr val(const thing &t) { return t.val; }
};
template<> struct ptr_traits<bool> {
typedef bool &type;
};
template<> bool &traits<thing<bool>>::alloc() { static bool b; return b; }
template<> void traits<thing<bool>>::free(bool&) {}
}
typedef X::traits<X::thing<int>> itt;
itt::thing::traits_type itr;
itt::thing ith(itr);
itt::rebind<bool> btr;
itt::rebind_thing<bool> btt(btr);
namespace PR11848 {
template<typename T> using U = int;
template<typename T, typename ...Ts>
void f1(U<T> i, U<Ts> ...is) { // expected-note 2{{couldn't infer template argument 'T'}}
return i + f1<Ts...>(is...);
}
// FIXME: This note is technically correct, but could be better. We
// should really say that we couldn't infer template argument 'Ts'.
template<typename ...Ts>
void f2(U<Ts> ...is) { } // expected-note {{requires 0 arguments, but 1 was provided}}
template<typename...> struct type_tuple {};
template<typename ...Ts>
void f3(type_tuple<Ts...>, U<Ts> ...is) {} // expected-note {{requires 4 arguments, but 3 were provided}}
void g() {
f1(U<void>()); // expected-error {{no match}}
f1(1, 2, 3, 4, 5); // expected-error {{no match}}
f2(); // ok
f2(1); // expected-error {{no match}}
f3(type_tuple<>());
f3(type_tuple<void, void, void>(), 1, 2); // expected-error {{no match}}
f3(type_tuple<void, void, void>(), 1, 2, 3);
}
template<typename ...Ts>
struct S {
S(U<Ts>...ts);
};
template<typename T>
struct Hidden1 {
template<typename ...Ts>
Hidden1(typename T::template U<Ts> ...ts);
};
template<typename T, typename ...Ts>
struct Hidden2 {
Hidden2(typename T::template U<Ts> ...ts);
};
struct Hide {
template<typename T> using U = int;
};
Hidden1<Hide> h1;
Hidden2<Hide, double, char> h2(1, 2);
}
namespace Core22036 {
struct X {};
void h(...);
template<typename T> using Y = X;
template<typename T, typename ...Ts> struct S {
// An expression can contain an unexpanded pack without being type or
// value dependent. This is true even if the expression's type is a pack
// expansion type.
void f1(Y<T> a) { h(g(a)); } // expected-error {{undeclared identifier 'g'}}
void f2(Y<Ts>...as) { h(g(as)...); } // expected-error {{undeclared identifier 'g'}}
void f3(Y<Ts>...as) { g(as...); } // ok
void f4(Ts ...ts) { h(g(sizeof(ts))...); } // expected-error {{undeclared identifier 'g'}}
// FIXME: We can reject this, since it has no valid instantiations because
// 'g' never has any associated namespaces.
void f5(Ts ...ts) { g(sizeof(ts)...); } // ok
};
}
namespace PR13243 {
template<typename A> struct X {};
template<int I> struct C {};
template<int I> using Ci = C<I>;
template<typename A, int I> void f(X<A>, Ci<I>) {}
template void f(X<int>, C<0>);
}
namespace PR13136 {
template <typename T, T... Numbers>
struct NumberTuple { };
template <unsigned int... Numbers>
using MyNumberTuple = NumberTuple<unsigned int, Numbers...>;
template <typename U, unsigned int... Numbers>
void foo(U&&, MyNumberTuple<Numbers...>);
template <typename U, unsigned int... Numbers>
void bar(U&&, NumberTuple<unsigned int, Numbers...>);
int main() {
foo(1, NumberTuple<unsigned int, 0, 1>());
bar(1, NumberTuple<unsigned int, 0, 1>());
return 0;
}
}
namespace PR16646 {
namespace test1 {
template <typename T> struct DefaultValue { const T value=0;};
template <typename ... Args> struct tuple {};
template <typename ... Args> using Zero = tuple<DefaultValue<Args> ...>;
template <typename ... Args> void f(const Zero<Args ...> &t);
void f() {
f(Zero<int,double,double>());
}
}
namespace test2 {
template<int x> struct X {};
template <template<int x> class temp> struct DefaultValue { const temp<0> value; };
template <typename ... Args> struct tuple {};
template <template<int x> class... Args> using Zero = tuple<DefaultValue<Args> ...>;
template <template<int x> class... Args> void f(const Zero<Args ...> &t);
void f() {
f(Zero<X,X,X>());
}
}
}
namespace PR16904 {
template <typename,typename>
struct base {
template <typename> struct derived;
};
// FIXME: The diagnostics here are terrible.
template <typename T, typename U, typename V>
using derived = base<T, U>::template derived<V>; // expected-error {{expected a type}} expected-error {{expected ';'}}
template <typename T, typename U, typename V>
using derived2 = ::PR16904::base<T, U>::template derived<V>; // expected-error {{expected a type}} expected-error {{expected ';'}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/attributes.cpp
|
// RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
namespace attribute_aligned {
template<int N>
struct X {
char c[1] __attribute__((__aligned__((N)))); // expected-error {{alignment is not a power of 2}}
};
template <bool X> struct check {
int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}}
};
template <int N> struct check_alignment {
typedef check<N == sizeof(X<N>)> t; // expected-note {{in instantiation}}
};
check_alignment<1>::t c1;
check_alignment<2>::t c2;
check_alignment<3>::t c3; // expected-note 2 {{in instantiation}}
check_alignment<4>::t c4;
template<unsigned Size, unsigned Align>
class my_aligned_storage
{
__attribute__((aligned(Align))) char storage[Size];
};
template<typename T>
class C {
public:
C() {
static_assert(sizeof(t) == sizeof(T), "my_aligned_storage size wrong");
static_assert(alignof(t) == alignof(T), "my_aligned_storage align wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
}
private:
my_aligned_storage<sizeof(T), alignof(T)> t;
};
C<double> cd;
}
namespace PR9049 {
extern const void *CFRetain(const void *ref);
template<typename T> __attribute__((cf_returns_retained))
inline T WBCFRetain(T aValue) { return aValue ? (T)CFRetain(aValue) : (T)0; }
extern void CFRelease(const void *ref);
template<typename T>
inline void WBCFRelease(__attribute__((cf_consumed)) T aValue) { if(aValue) CFRelease(aValue); }
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -triple %itanium_abi_triple -std=c++11 -ftemplate-depth 16 -fcxx-exceptions -fexceptions %s
// DR1330: an exception specification for a function template is only
// instantiated when it is needed.
// Note: the test is Itanium-specific because it depends on key functions in the
// PR12763 namespace.
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 exception spec}}
}
template<typename T> struct A {
template<typename U> struct B {
static void f() noexcept(A<U>().n);
};
constexpr A() : n(true) {}
bool n;
};
static_assert(noexcept(A<int>::B<char>::f()), "");
template<unsigned N> struct S {
static void recurse() noexcept(noexcept(S<N+1>::recurse())); // \
// expected-error {{no member named 'recurse'}} \
// expected-note 9{{instantiation of exception spec}}
};
decltype(S<0>::recurse()) *pVoid1 = 0; // ok, exception spec not needed
decltype(&S<0>::recurse) pFn = 0; // ok, exception spec not needed
template<> struct S<10> {};
void (*pFn2)() noexcept = &S<0>::recurse; // expected-note {{instantiation of exception spec}} expected-error {{not superset}}
namespace dr1330_example {
template <class T> struct A {
void f(...) throw (typename T::X); // expected-error {{'int'}}
void f(int);
};
int main() {
A<int>().f(42);
}
struct S {
template<typename T>
static int f() noexcept(noexcept(A<T>().f("boo!"))) { return 0; } // \
// expected-note {{instantiation of exception spec}}
typedef decltype(f<S>()) X;
};
int test2() {
S().f<S>(); // ok
S().f<int>(); // expected-note {{instantiation of exception spec}}
}
template<typename T>
struct U {
void f() noexcept(T::error);
void (g)() noexcept(T::error);
};
U<int> uint; // ok
}
namespace core_19754_example {
template<typename T> T declval() noexcept;
template<typename T, typename = decltype(T(declval<T&&>()))>
struct is_movable { static const bool value = true; };
template<typename T>
struct wrap {
T val;
void irrelevant(wrap &p) noexcept(is_movable<T>::value);
};
template<typename T>
struct base {
base() {}
base(const typename T::type1 &);
base(const typename T::type2 &);
};
template<typename T>
struct type1 {
wrap<typename T::base> base;
};
template<typename T>
struct type2 {
wrap<typename T::base> base;
};
struct types {
typedef base<types> base;
typedef type1<types> type1;
typedef type2<types> type2;
};
base<types> val = base<types>();
}
namespace pr9485 {
template <typename T> void f1(T) throw(typename T::exception); // expected-note {{candidate}}
template <typename T> void f1(T, int = 0) throw(typename T::noitpecxe); // expected-note {{candidate}}
template <typename T> void f2(T) noexcept(T::throws); // expected-note {{candidate}}
template <typename T> void f2(T, int = 0) noexcept(T::sworht); // expected-note {{candidate}}
void test() {
f1(0); // expected-error {{ambiguous}}
f2(0); // expected-error {{ambiguous}}
}
}
struct Exc1 { char c[4]; };
struct Exc2 { double x, y, z; };
struct Base {
virtual void f() noexcept; // expected-note {{overridden}}
};
template<typename T> struct Derived : Base {
void f() noexcept (sizeof(T) == 4); // expected-error {{is more lax}}
void g() noexcept (T::error);
};
Derived<Exc1> d1; // ok
Derived<Exc2> d2; // expected-note {{in instantiation of}}
// If the vtable for a derived class is used, the exception specification of
// any member function which ends up in that vtable is needed, even if it was
// declared in a base class.
namespace PR12763 {
template<bool *B> struct T {
virtual void f() noexcept (*B); // expected-error {{constant expression}} expected-note {{read of non-const}}
};
bool b; // expected-note {{here}}
struct X : public T<&b> {
virtual void g();
};
void X::g() {} // expected-note {{in instantiation of}}
}
namespace Variadic {
template<bool B> void check() { static_assert(B, ""); }
template<bool B, bool B2, bool ...Bs> void check() { static_assert(B, ""); check<B2, Bs...>(); }
template<typename ...T> void consume(T...);
template<typename ...T> void f(void (*...p)() throw (T)) {
void (*q[])() = { p... };
consume((p(),0)...);
}
template<bool ...B> void g(void (*...p)() noexcept (B)) {
consume((p(),0)...);
check<noexcept(p()) == B ...>();
}
template<typename ...T> void i() {
consume([]() throw(T) {} ...);
consume([]() noexcept(sizeof(T) == 4) {} ...);
}
template<bool ...B> void j() {
consume([](void (*p)() noexcept(B)) {
void (*q)() noexcept = p; // expected-error {{not superset of source}}
} ...);
}
void z() {
f<int, char, double>(nullptr, nullptr, nullptr);
g<true, false, true>(nullptr, nullptr, nullptr);
i<int, long, short>();
j<true, true>();
j<true, false>(); // expected-note {{in instantiation of}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/operator-function-id-template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
template<typename T>
struct A {
template<typename U> A<T> operator+(U);
};
template<int Value, typename T> bool operator==(A<T>, A<T>);
template<> bool operator==<0>(A<int>, A<int>);
bool test_qualified_id(A<int> ai) {
return ::operator==<0, int>(ai, ai);
}
void test_op(A<int> a, int i) {
const A<int> &air = a.operator+<int>(i);
}
template<typename T>
void test_op_template(A<T> at, T x) {
const A<T> &atr = at.template operator+<T>(x);
const A<T> &atr2 = at.A::template operator+<T>(x);
// FIXME: unrelated template-name instantiation issue
// const A<T> &atr3 = at.template A<T>::template operator+<T>(x);
}
template void test_op_template<float>(A<float>, float);
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-invalid.cpp
|
// RUN: not %clang_cc1 -fsyntax-only %s
namespace PR6375 {
template<class Conv> class rasterizer_sl_clip Conv::xi(x2), Conv::yi(y2));
namespace agg
{
template<class Clip=rasterizer_sl_clip_int> class rasterizer_scanline_aa
{
template<class Scanline> bool sweep_scanline(Scanline& sl)
{
unsigned num_cells = m_outline.scanline_num_cells(m_scan_y);
while(num_cells) { }
}
}
class scanline_u8 {}
template<class PixelFormat> class renderer_base { }
}
template<class Rasterizer, class Scanline, class BaseRenderer, class ColorT>
void render_scanlines_aa_solid(Rasterizer& ras, Scanline& sl, BaseRenderer& ren, const ColorT& color)
{
while(ras.sweep_scanline(sl))
{
}
};
namespace agg
{
struct rgba8
{
};
template<class Rasterizer, class Scanline, class Renderer, class Ctrl>
void render_ctrl(Rasterizer& ras, Scanline& sl, Renderer& r, Ctrl& c)
{
unsigned i;
render_scanlines_aa_solid(ras, sl, r, c.color(i));
}
template<class ColorT> class rbox_ctrl : public rbox_ctrl_impl
{
const ColorT& color(unsigned i) const { return *m_colors[i]; }
}
class the_application : public agg::platform_support
{
agg::rbox_ctrl<agg::rgba8> m_polygons;
virtual void on_init()
{
typedef agg::renderer_base<pixfmt_type> base_ren_type;
base_ren_type ren_base(pf);
agg::scanline_u8 sl;
agg::rasterizer_scanline_aa<> ras;
agg::render_ctrl(ras, sl, ren_base, m_polygons);
}
};
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/template-id-printing.cpp
|
// RUN: %clang_cc1 -fsyntax-only -ast-print %s | FileCheck %s
namespace N {
template<typename T, typename U> void f(U);
template<int> void f();
}
void g() {
// CHECK: N::f<int>(3.14
N::f<int>(3.14);
// CHECK: N::f<double>
void (*fp)(int) = N::f<double>;
}
// (NNS qualified) DeclRefExpr.
namespace DRE {
template <typename T>
void foo();
void test() {
// CHECK: DRE::foo<int>;
DRE::foo<int>;
// CHECK: DRE::template foo<int>;
DRE::template foo<int>;
// CHECK: DRE::foo<int>();
DRE::foo<int>();
// CHECK: DRE::template foo<int>();
DRE::template foo<int>();
}
} // namespace DRE
// MemberExpr.
namespace ME {
struct S {
template <typename T>
void mem();
};
void test() {
S s;
// CHECK: s.mem<int>();
s.mem<int>();
// CHECK: s.template mem<int>();
s.template mem<int>();
}
} // namespace ME
// UnresolvedLookupExpr.
namespace ULE {
template <typename T>
int foo();
template <typename T>
void test() {
// CHECK: ULE::foo<T>;
ULE::foo<T>;
// CHECK: ULE::template foo<T>;
ULE::template foo<T>;
}
} // namespace ULE
// UnresolvedMemberExpr.
namespace UME {
struct S {
template <typename T>
void mem();
};
template <typename U>
void test() {
S s;
// CHECK: s.mem<U>();
s.mem<U>();
// CHECK: s.template mem<U>();
s.template mem<U>();
}
} // namespace UME
// DependentScopeDeclRefExpr.
namespace DSDRE {
template <typename T>
struct S;
template <typename T>
void test() {
// CHECK: S<T>::foo;
S<T>::foo;
// CHECK: S<T>::template foo;
S<T>::template foo;
// CHECK: S<T>::template foo<>;
S<T>::template foo<>;
// CHECK: S<T>::template foo<T>;
S<T>::template foo<T>;
}
} // namespace DSDRE
// DependentScopeMemberExpr.
namespace DSME {
template <typename T>
struct S;
template <typename T>
void test() {
S<T> s;
// CHECK: s.foo;
s.foo;
// CHECK: s.template foo;
s.template foo;
// CHECK: s.template foo<>;
s.template foo<>;
// CHECK: s.template foo<T>;
s.template foo<T>;
}
} // namespace DSME
namespace DSDRE_withImplicitTemplateArgs {
template <typename T> void foo() {
// CHECK: T::template bar();
T::template bar();
}
} // namespace DSDRE_withImplicitTemplateArgs
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp
|
// RUN: not %clang_cc1 -fsyntax-only -std=c++11 -ferror-limit 1 %s 2>&1 | FileCheck %s
unknown_type foo(unknown_type);
// CHECK: fatal error: too many errors emitted, stopping now
template <typename>
class Bar {};
extern template class Bar<int>;
template class Bar<int>;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-decl-init.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// PR5426 - the non-dependent obj would be fully processed and wrapped in a
// CXXConstructExpr at definition time, which would lead to a failure at
// instantiation time.
struct arg {
arg();
};
struct oldstylemove {
oldstylemove(oldstylemove&);
oldstylemove(const arg&);
};
template <typename T>
void fn(T t, const arg& arg) {
oldstylemove obj(arg);
}
void test() {
fn(1, arg());
}
struct X0 { };
struct X1 {
explicit X1(const X0 &x0 = X0());
};
template<typename T>
void f0() {
X1 x1;
}
template void f0<int>();
template void f0<float>();
struct NonTrivial {
NonTrivial();
~NonTrivial();
};
template<int N> void f1() {
NonTrivial array[N];
}
template<> void f1<2>();
namespace PR20346 {
struct S { short inner_s; };
struct outer_struct {
wchar_t arr[32];
S outer_s;
};
template <class T>
void OpenFileSession() {
// Ensure that we don't think the ImplicitValueInitExpr generated here
// during the initial parse only initializes the first array element!
outer_struct asdfasdf = {};
};
void foo() {
OpenFileSession<int>();
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/dependent-names.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
typedef double A;
template<typename T> class B {
typedef int A;
};
template<typename T> struct X : B<T> {
static A a;
};
int a0[sizeof(X<int>::a) == sizeof(double) ? 1 : -1];
// PR4365.
template<class T> class Q;
template<class T> class R : Q<T> {T current;};
namespace test0 {
template <class T> class Base {
public:
void instance_foo();
static void static_foo();
class Inner {
public:
void instance_foo();
static void static_foo();
};
};
template <class T> class Derived1 : Base<T> {
public:
void test0() {
Base<T>::static_foo();
Base<T>::instance_foo();
}
void test1() {
Base<T>::Inner::static_foo();
Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
}
static void test2() {
Base<T>::static_foo();
Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
}
static void test3() {
Base<T>::Inner::static_foo();
Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
}
};
template <class T> class Derived2 : Base<T>::Inner {
public:
void test0() {
Base<T>::static_foo();
Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
}
void test1() {
Base<T>::Inner::static_foo();
Base<T>::Inner::instance_foo();
}
static void test2() {
Base<T>::static_foo();
Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
}
static void test3() {
Base<T>::Inner::static_foo();
Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
}
};
void test0() {
Derived1<int> d1;
d1.test0();
d1.test1(); // expected-note {{in instantiation of member function}}
d1.test2(); // expected-note {{in instantiation of member function}}
d1.test3(); // expected-note {{in instantiation of member function}}
Derived2<int> d2;
d2.test0(); // expected-note {{in instantiation of member function}}
d2.test1();
d2.test2(); // expected-note {{in instantiation of member function}}
d2.test3(); // expected-note {{in instantiation of member function}}
}
}
namespace test1 {
template <class T> struct Base {
void foo(T); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
};
template <class T> struct Derived : Base<T> {
void doFoo(T v) {
foo(v); // expected-error {{use of undeclared identifier}}
}
};
template struct Derived<int>; // expected-note {{requested here}}
}
namespace PR8966 {
template <class T>
class MyClassCore
{
};
template <class T>
class MyClass : public MyClassCore<T>
{
public:
enum {
N
};
// static member declaration
static const char* array [N];
void f() {
MyClass<T>::InBase = 17;
}
};
// static member definition
template <class T>
const char* MyClass<T>::array [MyClass<T>::N] = { "A", "B", "C" };
}
namespace std {
inline namespace v1 {
template<typename T> struct basic_ostream;
}
namespace inner {
template<typename T> struct vector {};
}
using inner::vector;
template<typename T, typename U> struct pair {};
typedef basic_ostream<char> ostream;
extern ostream cout;
std::ostream &operator<<(std::ostream &out, const char *);
}
namespace PR10053 {
template<typename T> struct A {
T t;
A() {
f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
}
};
void f(int&); // expected-note {{'f' should be declared prior to the call site}}
A<int> a; // expected-note {{in instantiation of member function}}
namespace N {
namespace M {
template<typename T> int g(T t) {
f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
};
}
void f(char&); // expected-note {{'f' should be declared prior to the call site}}
}
void f(char&);
int k = N::M::g<char>(0);; // expected-note {{in instantiation of function}}
namespace O {
void f(char&); // expected-note {{candidate function not viable}}
template<typename T> struct C {
static const int n = f(T()); // expected-error {{no matching function}}
};
}
int f(double); // no note, shadowed by O::f
O::C<double> c; // expected-note {{requested here}}
// Example from www/compatibility.html
namespace my_file {
template <typename T> T Squared(T x) {
return Multiply(x, x); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
}
int Multiply(int x, int y) { // expected-note {{should be declared prior to the call site}}
return x * y;
}
int main() {
Squared(5); // expected-note {{here}}
}
}
// Example from www/compatibility.html
namespace my_file2 {
template<typename T>
void Dump(const T& value) {
std::cout << value << "\n"; // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
}
namespace ns {
struct Data {};
}
std::ostream& operator<<(std::ostream& out, ns::Data data) { // expected-note {{should be declared prior to the call site or in namespace 'PR10053::my_file2::ns'}}
return out << "Some data";
}
void Use() {
Dump(ns::Data()); // expected-note {{here}}
}
}
namespace my_file2_a {
template<typename T>
void Dump(const T &value) {
print(std::cout, value); // expected-error 4{{neither visible in the template definition nor found by argument-dependent lookup}}
}
namespace ns {
struct Data {};
}
namespace ns2 {
struct Data {};
}
std::ostream &print(std::ostream &out, int); // expected-note-re {{should be declared prior to the call site{{$}}}}
std::ostream &print(std::ostream &out, ns::Data); // expected-note {{should be declared prior to the call site or in namespace 'PR10053::my_file2_a::ns'}}
std::ostream &print(std::ostream &out, std::vector<ns2::Data>); // expected-note {{should be declared prior to the call site or in namespace 'PR10053::my_file2_a::ns2'}}
std::ostream &print(std::ostream &out, std::pair<ns::Data, ns2::Data>); // expected-note {{should be declared prior to the call site or in an associated namespace of one of its arguments}}
void Use() {
Dump(0); // expected-note {{requested here}}
Dump(ns::Data()); // expected-note {{requested here}}
Dump(std::vector<ns2::Data>()); // expected-note {{requested here}}
Dump(std::pair<ns::Data, ns2::Data>()); // expected-note {{requested here}}
}
}
namespace unary {
template<typename T>
T Negate(const T& value) {
return !value; // expected-error {{call to function 'operator!' that is neither visible in the template definition nor found by argument-dependent lookup}}
}
namespace ns {
struct Data {};
}
ns::Data operator!(ns::Data); // expected-note {{should be declared prior to the call site or in namespace 'PR10053::unary::ns'}}
void Use() {
Negate(ns::Data()); // expected-note {{requested here}}
}
}
}
namespace PR10187 {
namespace A1 {
template<typename T>
struct S {
void f() {
for (auto &a : e)
__range(a); // expected-error {{undeclared identifier '__range'}}
}
int e[10];
};
void g() {
S<int>().f(); // expected-note {{here}}
}
}
namespace A2 {
template<typename T>
struct S {
void f() {
for (auto &a : e)
__range(a); // expected-error {{undeclared identifier '__range'}}
}
T e[10];
};
void g() {
S<int>().f(); // expected-note {{here}}
}
struct X {};
void __range(X);
void h() {
S<X>().f();
}
}
namespace B {
template<typename T> void g(); // expected-note {{not viable}}
template<typename T> void f() {
g<int>(T()); // expected-error {{no matching function}}
}
namespace {
struct S {};
}
void g(S);
template void f<S>(); // expected-note {{here}}
}
}
namespace rdar11242625 {
template <typename T>
struct Main {
struct default_names {
typedef int id;
};
template <typename T2 = typename default_names::id>
struct TS {
T2 q;
};
};
struct Sub : public Main<int> {
TS<> ff;
};
int arr[sizeof(Sub)];
}
namespace PR11421 {
template < unsigned > struct X {
static const unsigned dimension = 3;
template<unsigned dim=dimension>
struct Y: Y<dim> { }; // expected-error{{circular inheritance between 'Y<dim>' and 'Y<dim>'}}
};
typedef X<3> X3;
X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
}
namespace rdar12629723 {
template<class T>
struct X {
struct C : public C { }; // expected-error{{circular inheritance between 'rdar12629723::X::C' and 'rdar12629723::X::C'}}
struct B;
struct A : public B { // expected-note{{'rdar12629723::X::A' declared here}}
virtual void foo() { }
};
struct D : T::foo { };
struct E : D { };
};
template<class T>
struct X<T>::B : public A { // expected-error{{circular inheritance between 'rdar12629723::X::A' and 'rdar12629723::X::B'}}
virtual void foo() { }
};
}
namespace test_reserved_identifiers {
template<typename A, typename B> void tempf(A a, B b) {
a + b; // expected-error{{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}}
}
namespace __gnu_cxx { struct X {}; }
namespace ns { struct Y {}; }
void operator+(__gnu_cxx::X, ns::Y); // expected-note{{or in namespace 'test_reserved_identifiers::ns'}}
void test() {
__gnu_cxx::X x;
ns::Y y;
tempf(x, y); // expected-note{{in instantiation of}}
}
}
// This test must live in the global namespace.
struct PR14695_X {};
// FIXME: This note is bogus; it is the using directive which would need to move
// to prior to the call site to fix the problem.
namespace PR14695_A { void PR14695_f(PR14695_X); } // expected-note {{'PR14695_f' should be declared prior to the call site or in the global namespace}}
template<typename T> void PR14695_g(T t) { PR14695_f(t); } // expected-error {{call to function 'PR14695_f' that is neither visible in the template definition nor found by argument-dependent lookup}}
using namespace PR14695_A;
template void PR14695_g(PR14695_X); // expected-note{{requested here}}
namespace OperatorNew {
template<typename T> void f(T t) {
operator new(100, t); // expected-error{{call to function 'operator new' that is neither visible in the template definition nor found by argument-dependent lookup}}
// FIXME: This should give the same error.
new (t) int;
}
struct X {};
};
using size_t = decltype(sizeof(0));
void *operator new(size_t, OperatorNew::X); // expected-note-re {{should be declared prior to the call site{{$}}}}
template void OperatorNew::f(OperatorNew::X); // expected-note {{instantiation of}}
namespace PR19936 {
template<typename T> decltype(*T()) f() {} // expected-note {{previous}}
template<typename T> decltype(T() * T()) g() {} // expected-note {{previous}}
// Create some overloaded operators so we build an overload operator call
// instead of a builtin operator call for the dependent expression.
enum E {};
int operator*(E);
int operator*(E, E);
// Check that they still profile the same.
template<typename T> decltype(*T()) f() {} // expected-error {{redefinition}}
template<typename T> decltype(T() * T()) g() {} // expected-error {{redefinition}}
}
template <typename> struct CT2 {
template <class U> struct X;
};
template <typename T> int CT2<int>::X<>; // expected-error {{template parameter list matching the non-templated nested type 'CT2<int>' should be empty}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-deeply.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wall -verify %s
// expected-no-diagnostics
template<typename a> struct A {
template <typename b> struct B {
template <typename c> struct C {
template <typename d> struct D {
template <typename e> struct E {
e field;
E() : field(0) {
d v1 = 4;
c v2 = v1 * v1;
b v3 = 8;
a v4 = v3 * v3;
field += v2 + v4;
}
};
};
};
};
};
A<int>::B<int>::C<int>::D<int>::E<int> global;
// PR5352
template <typename T>
class Foo {
public:
Foo() {}
struct Bar {
T value;
};
Bar u;
};
template class Foo<int>;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/ms-if-exists.cpp
|
// RUN: %clang_cc1 -fms-extensions -std=c++11 %s -verify
struct Nontemplate {
typedef int type;
};
template<typename T>
struct X {
__if_exists(Nontemplate::type) {
typedef Nontemplate::type type;
}
__if_exists(Nontemplate::value) {
typedef Nontemplate::value type2;
}
__if_not_exists(Nontemplate::value) {
typedef int type3;
}
__if_exists(T::X) { // expected-warning{{dependent __if_exists declarations are ignored}}
typedef T::X type4;
}
};
X<int>::type i1;
X<int>::type2 i2; // expected-error{{no type named 'type2' in 'X<int>'}}
X<int>::type3 i3;
X<int>::type4 i4; // expected-error{{no type named 'type4' in 'X<int>'}}
struct HasFoo {
void foo();
};
struct HasBar {
void bar(int);
void bar(float);
};
template<typename T>
void f(T t) {
__if_exists(T::foo) {
{ }
t.foo();
}
__if_not_exists(T::bar) {
int *i = t; // expected-error{{no viable conversion from 'HasFoo' to 'int *'}}
{ }
}
int array2[] = {
0,
__if_exists(T::bar) {2, }// expected-warning{{dependent __if_exists declarations are ignored}}
3
};
}
template void f(HasFoo); // expected-note{{in instantiation of function template specialization 'f<HasFoo>' requested here}}
template void f(HasBar);
template<typename T, typename ...Ts>
void g(T, Ts...) {
__if_exists(T::operator Ts) { // expected-error{{__if_exists name contains unexpanded parameter pack 'Ts'}}
}
__if_not_exists(Ts::operator T) { // expected-error{{__if_not_exists name contains unexpanded parameter pack 'Ts'}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-member-initializers.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wall -verify %s
template<typename T> struct A {
A() : a(1) { } // expected-error{{cannot initialize a member subobject of type 'void *' with an rvalue of type 'int'}}
T a;
};
A<int> a0;
A<void*> a1; // expected-note{{in instantiation of member function 'A<void *>::A' requested here}}
template<typename T> struct B {
B() : b(1), // expected-warning {{field 'b' will be initialized after field 'a'}}
a(2) { }
int a;
int b;
};
B<int> b0; // expected-note {{in instantiation of member function 'B<int>::B' requested here}}
template <class T> struct AA { AA(int); };
template <class T> class BB : public AA<T> {
public:
BB() : AA<T>(1) {}
};
BB<int> x;
struct X {
X();
};
template<typename T>
struct Y {
Y() : x() {}
X x;
};
Y<int> y;
template<typename T> struct Array {
int a[3];
Array() : a() {}
};
Array<int> s;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/nested-linkage.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
extern "C" { extern "C++" { template<class C> C x(); } }
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/canonical-expr-type.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
void f();
// Test typeof(expr) canonicalization
template<typename T>
void f0(T x, __typeof__(f(x)) y) { } // expected-note{{previous}}
template<typename T>
void f0(T x, __typeof__((f)(x)) y) { }
template<typename U>
void f0(U u, __typeof__(f(u))) { } // expected-error{{redefinition}}
// Test insane typeof(expr) overload set canonicalization
void f(int);
void f(double);
template<typename T, T N>
void f0a(T x, __typeof__(f(N)) y) { } // expected-note{{previous}}
void f(int);
template<typename T, T N>
void f0a(T x, __typeof__(f(N)) y) { } // expected-error{{redefinition}}
void f(float);
// Test dependently-sized array canonicalization
template<typename T, int N, int M>
void f1(T (&array)[N + M]) { } // expected-note{{previous}}
template<typename T, int N, int M>
void f1(T (&array)[M + N]) { }
template<typename T, int M, int N>
void f1(T (&array)[M + N]) { } // expected-error{{redefinition}}
// Test dependently-sized extended vector type canonicalization
template<typename T, int N, int M>
struct X2 {
typedef T __attribute__((ext_vector_type(N))) type1;
typedef T __attribute__((ext_vector_type(M))) type2;
typedef T __attribute__((ext_vector_type(N))) type3;
void f0(type1); // expected-note{{previous}}
void f0(type2);
void f0(type3); // expected-error{{redeclared}}
};
// Test canonicalization doesn't conflate different literal suffixes.
template<typename T> void literal_suffix(int (&)[sizeof(T() + 0)]) {}
template<typename T> void literal_suffix(int (&)[sizeof(T() + 0L)]) {}
template<typename T> void literal_suffix(int (&)[sizeof(T() + 0LL)]) {}
template<typename T> void literal_suffix(int (&)[sizeof(T() + 0.f)]) {}
template<typename T> void literal_suffix(int (&)[sizeof(T() + 0.)]) {}
template<typename T> void literal_suffix(int (&)[sizeof(T() + 0.l)]) {}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/instantiate-dependent-nested-name.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// PR4382
template<typename T> struct X { static const T A = 1; };
template<typename T, bool = X<T>::A> struct Y { typedef T A; };
template<typename T> struct Z { typedef typename Y<T>::A A; };
extern int x;
extern Z<int>::A x;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/deduction.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
// Template argument deduction with template template parameters.
template<typename T, template<T> class A>
struct X0 {
static const unsigned value = 0;
};
template<template<int> class A>
struct X0<int, A> {
static const unsigned value = 1;
};
template<int> struct X0i;
template<long> struct X0l;
int array_x0a[X0<long, X0l>::value == 0? 1 : -1];
int array_x0b[X0<int, X0i>::value == 1? 1 : -1];
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;
};
template<typename T> struct allocator { };
template<typename T, typename Alloc = allocator<T> > struct vector {};
// Fun with meta-lambdas!
struct _1 {};
struct _2 {};
// Replaces all occurrences of _1 with Arg1 and _2 with Arg2 in T.
template<typename T, typename Arg1, typename Arg2>
struct Replace {
typedef T type;
};
// Replacement of the whole type.
template<typename Arg1, typename Arg2>
struct Replace<_1, Arg1, Arg2> {
typedef Arg1 type;
};
template<typename Arg1, typename Arg2>
struct Replace<_2, Arg1, Arg2> {
typedef Arg2 type;
};
// Replacement through cv-qualifiers
template<typename T, typename Arg1, typename Arg2>
struct Replace<const T, Arg1, Arg2> {
typedef typename Replace<T, Arg1, Arg2>::type const type;
};
// Replacement of templates
template<template<typename> class TT, typename T1, typename Arg1, typename Arg2>
struct Replace<TT<T1>, Arg1, Arg2> {
typedef TT<typename Replace<T1, Arg1, Arg2>::type> type;
};
template<template<typename, typename> class TT, typename T1, typename T2,
typename Arg1, typename Arg2>
struct Replace<TT<T1, T2>, Arg1, Arg2> {
typedef TT<typename Replace<T1, Arg1, Arg2>::type,
typename Replace<T2, Arg1, Arg2>::type> type;
};
// Just for kicks...
template<template<typename, typename> class TT, typename T1,
typename Arg1, typename Arg2>
struct Replace<TT<T1, _2>, Arg1, Arg2> {
typedef TT<typename Replace<T1, Arg1, Arg2>::type, Arg2> type;
};
int array0[is_same<Replace<_1, int, float>::type, int>::value? 1 : -1];
int array1[is_same<Replace<const _1, int, float>::type, const int>::value? 1 : -1];
int array2[is_same<Replace<vector<_1>, int, float>::type, vector<int> >::value? 1 : -1];
int array3[is_same<Replace<vector<const _1>, int, float>::type, vector<const int> >::value? 1 : -1];
int array4[is_same<Replace<vector<int, _2>, double, float>::type, vector<int, float> >::value? 1 : -1];
// PR5911
template <typename T, int N> void f(const T (&a)[N]);
int iarr[] = { 1 };
void test_PR5911() { f(iarr); }
// Must not examine base classes of incomplete type during template argument
// deduction.
namespace PR6257 {
template <typename T> struct X {
template <typename U> X(const X<U>& u);
};
struct A;
void f(A& a);
void f(const X<A>& a);
void test(A& a) { (void)f(a); }
}
// PR7463
namespace PR7463 {
const int f ();
template <typename T_> void g (T_&); // expected-note{{T_ = int}}
void h (void) { g(f()); } // expected-error{{no matching function for call}}
}
namespace test0 {
template <class T> void make(const T *(*fn)()); // expected-note {{candidate template ignored: can't deduce a type for 'T' that would make 'const T' equal 'char'}}
char *char_maker();
void test() {
make(char_maker); // expected-error {{no matching function for call to 'make'}}
}
}
namespace test1 {
template<typename T> void foo(const T a[3][3]);
void test() {
int a[3][3];
foo(a);
}
}
// PR7708
namespace test2 {
template<typename T> struct Const { typedef void const type; };
template<typename T> void f(T, typename Const<T>::type*);
template<typename T> void f(T, void const *);
void test() {
void *p = 0;
f(0, p);
}
}
// rdar://problem/8537391
namespace test3 {
struct Foo {
template <void F(char)> static inline void foo();
};
class Bar {
template<typename T> static inline void wobble(T ch);
public:
static void madness() {
Foo::foo<wobble<char> >();
}
};
}
// Verify that we can deduce enum-typed arguments correctly.
namespace test14 {
enum E { E0, E1 };
template <E> struct A {};
template <E e> void foo(const A<e> &a) {}
void test() {
A<E0> a;
foo(a);
}
}
namespace PR21536 {
template<typename ...T> struct X;
template<typename A, typename ...B> struct S {
static_assert(sizeof...(B) == 1, "");
void f() {
using T = A;
using T = int;
using U = X<B...>;
using U = X<int>;
}
};
template<typename ...T> void f(S<T...>);
void g() { f(S<int, int>()); }
}
namespace PR19372 {
template <template<typename...> class C, typename ...Us> struct BindBack {
template <typename ...Ts> using apply = C<Ts..., Us...>;
};
template <typename, typename...> struct Y;
template <typename ...Ts> using Z = Y<Ts...>;
using T = BindBack<Z, int>::apply<>;
using T = Z<int>;
using U = BindBack<Z, int, int>::apply<char>;
using U = Z<char, int, int>;
namespace BetterReduction {
template<typename ...> struct S;
template<typename ...A> using X = S<A...>; // expected-note {{parameter}}
template<typename ...A> using Y = X<A..., A...>;
template<typename ...A> using Z = X<A..., 1, 2, 3>; // expected-error {{must be a type}}
using T = Y<int>;
using T = S<int, int>;
}
}
namespace PR18645 {
template<typename F> F Quux(F &&f);
auto Baz = Quux(Quux<float>);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/friend-template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// PR5057
namespace test0 {
namespace std {
class X {
public:
template<typename T> friend struct Y;
};
}
namespace std {
template<typename T> struct Y {};
}
}
namespace test1 {
template<typename T> void f1(T) { } // expected-note{{here}}
class X {
template<typename T> friend void f0(T);
template<typename T> friend void f1(T);
};
template<typename T> void f0(T) { }
template<typename T> void f1(T) { } // expected-error{{redefinition}}
}
// PR4768
namespace test2 {
template<typename T> struct X0 {
template<typename U> friend struct X0;
};
template<typename T> struct X0<T*> {
template<typename U> friend struct X0;
};
template<> struct X0<int> {
template<typename U> friend struct X0;
};
template<typename T> struct X1 {
template<typename U> friend void f2(U);
template<typename U> friend void f3(U);
};
template<typename U> void f2(U);
X1<int> x1i;
X0<int*> x0ip;
template<> void f2(int);
// FIXME: Should this declaration of f3 be required for the specialization of
// f3<int> (further below) to work? GCC and EDG don't require it, we do...
template<typename U> void f3(U);
template<> void f3(int);
}
// PR5332
namespace test3 {
template <typename T> class Foo {
template <typename U>
friend class Foo;
};
Foo<int> foo;
template<typename T, T Value> struct X2a;
template<typename T, int Size> struct X2b;
template<typename T>
class X3 {
template<typename U, U Value> friend struct X2a;
// FIXME: the redeclaration note ends up here because redeclaration
// lookup ends up finding the friend target from X3<int>.
template<typename U, T Value> friend struct X2b; // expected-error {{template non-type parameter has a different type 'long' in template redeclaration}} \
// expected-note {{previous non-type template parameter with type 'int' is here}}
};
X3<int> x3i; // okay
X3<long> x3l; // expected-note {{in instantiation}}
}
// PR5716
namespace test4 {
template<typename> struct A {
template<typename T> friend void f(const A<T>&);
};
template<typename T> void f(const A<T>&) {
int a[sizeof(T) ? -1 : -1]; // expected-error {{array with a negative size}}
}
void f() {
f(A<int>()); // expected-note {{in instantiation of function template specialization}}
}
}
namespace test5 {
class outer {
class foo;
template <typename T> friend struct cache;
};
class outer::foo {
template <typename T> friend struct cache;
};
}
// PR6022
namespace PR6022 {
template <class T1, class T2 , class T3 > class A;
namespace inner {
template<class T1, class T2, class T3, class T>
A<T1, T2, T3>& f0(A<T1, T2, T3>&, T);
}
template<class T1, class T2, class T3>
class A {
template<class U1, class U2, class U3, class T>
friend A<U1, U2, U3>& inner::f0(A<U1, U2, U3>&, T);
};
}
namespace FriendTemplateDefinition {
template<unsigned > struct int_c { };
template<typename T>
struct X {
template<unsigned N>
friend void f(X, int_c<N>) {
int value = N;
};
};
void test_X(X<int> x, int_c<5> i5) {
f(x, i5);
}
}
namespace PR7013a {
template<class > struct X0
{
typedef int type;
};
template<typename > struct X1
{
};
template<typename , typename T> struct X2
{
typename T::type e;
};
namespace N
{
template <typename = int, typename = X1<int> > struct X3
{
template <typename T1, typename T2, typename B> friend void op(X2<T1, T2>& , B);
};
template <typename Ch, typename Tr, typename B> void op(X2<Ch, Tr>& , B)
{
X2<int, Tr> s;
}
}
int n()
{
X2<int, X0<int> > ngs;
N::X3<> b;
op(ngs, b);
return 0;
}
}
namespace PR7013b {
template<class > struct X0
{
typedef int type;
};
template<typename > struct X1
{
};
template<typename , typename T> struct X2
{
typename T::type e;
};
namespace N
{
template <typename = X1<int> > struct X3
{
template <typename T1, typename T2, typename B> friend void op(X2<T1, T2>& , B);
};
template <typename Ch, typename Tr, typename B> void op(X2<Ch, Tr>& , B)
{
X2<int, Tr> s;
}
}
int n()
{
X2<int, X0<int> > ngs;
N::X3<> b;
op(ngs, b);
return 0;
}
}
namespace PR8649 {
template<typename T, typename U, unsigned N>
struct X {
template<unsigned M> friend class X<T, U, M>; // expected-error{{partial specialization cannot be declared as a friend}}
};
X<int, float, 7> x;
}
// Don't crash, and error on invalid friend type template.
namespace friend_type_template_no_tag {
template <typename T> struct S {
template <typename U> friend S<U>; // expected-error{{friend type templates must use an elaborated type}}
};
template struct S<int>;
}
namespace PR10660 {
struct A {
template <> friend class B; // expected-error{{extraneous 'template<>' in declaration of class 'B'}}
};
}
namespace rdar11147355 {
template <class T>
struct A {
template <class U> class B;
template <class S> template <class U> friend class A<S>::B; // expected-warning {{dependent nested name specifier 'A<S>::' for friend template declaration is not supported; ignoring this friend declaration}}
private:
int n; // expected-note {{here}}
};
template <class S> template <class U> class A<S>::B {
public:
// FIXME: This should be permitted.
int f(A<S*> a) { return a.n; } // expected-error {{private}}
};
A<double>::B<double> ab;
A<double*> a;
int k = ab.f(a); // expected-note {{instantiation of}}
}
namespace RedeclUnrelated {
struct S {
int packaged_task;
template<typename> class future {
template<typename> friend class packaged_task;
};
future<void> share;
};
}
namespace PR12557 {
template <typename>
struct Foo;
template <typename Foo_>
struct Bar {
typedef Foo_ Foo; // expected-note {{previous}}
template <typename> friend struct Foo; // expected-error {{redefinition of 'Foo' as different kind of symbol}}
};
Bar<int> b;
}
namespace PR12585 {
struct A { };
template<typename> struct B {
template<typename> friend class A::does_not_exist; // \
// expected-error {{friend declaration of 'does_not_exist' does not match any declaration in 'PR12585::A'}}
};
struct C {
template<typename> struct D;
};
template<typename> class E {
int n;
template<typename> friend struct C::D;
};
template<typename T> struct C::D {
int f() {
return E<int>().n;
}
};
int n = C::D<void*>().f();
struct F {
template<int> struct G;
};
template<typename T> struct H {
// FIXME: As with cases above, the note here is on an unhelpful declaration,
// and should point to the declaration of G within F.
template<T> friend struct F::G; // \
// expected-error {{different type 'char' in template redeclaration}} \
// expected-note {{previous}}
};
H<int> h1; // ok
H<char> h2; // expected-note {{instantiation}}
}
// Ensure that we can still instantiate a friend function template
// after the friend declaration is instantiated during the delayed
// parsing of a member function, but before the friend function has
// been parsed.
namespace rdar12350696 {
template <class T> struct A {
void foo() {
A<int> a;
}
template <class U> friend void foo(const A<U> & a) {
int array[sizeof(T) == sizeof(U) ? -1 : 1]; // expected-error {{negative size}}
}
};
void test() {
A<int> b;
foo(b); // expected-note {{in instantiation}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/injected-class-name.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
struct X {
X<T*> *ptr;
};
X<int> x;
template<>
struct X<int***> {
typedef X<int***> *ptr;
};
X<float>::X<int> xi = x; // expected-error{{qualified reference to 'X' is a constructor name rather than a template name wherever a constructor can be declared}}
// [temp.local]p1:
// FIXME: test template template parameters
template<typename T, typename U>
struct X0 {
typedef T type;
typedef U U_type;
typedef U_type U_type2;
void f0(const X0&); // expected-note{{here}}
void f0(X0&);
void f0(const X0<T, U>&); // expected-error{{redecl}}
void f1(const X0&); // expected-note{{here}}
void f1(X0&);
void f1(const X0<type, U_type2>&); // expected-error{{redecl}}
void f2(const X0&); // expected-note{{here}}
void f2(X0&);
void f2(const ::X0<type, U_type2>&); // expected-error{{redecl}}
};
template<typename T, T N>
struct X1 {
void f0(const X1&); // expected-note{{here}}
void f0(X1&);
void f0(const X1<T, N>&); // expected-error{{redecl}}
};
namespace pr6326 {
template <class T> class A {
friend class A;
};
template class A<int>;
}
namespace ForwardDecls {
template<typename T>
struct X;
template<typename T>
struct X {
typedef T foo;
typedef X<T> xt;
typename xt::foo *t;
};
}
namespace ConflictingRedecl {
template<typename> struct Nested {
template<typename> struct Nested; // expected-error {{member 'Nested' has the same name as its class}}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaTemplate/crash.cpp
|
// RUN: not %clang_cc1 -verify %s -std=c++11
// PR17730
template <typename T>
void S<T>::mem1();
template <typename T>
void S<T>::mem2() {
const int I = sizeof(T);
(void)I;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.