From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/SemaTemplate/instantiate-expr-4.cpp | 354 +++++++++++++++++++++++++ 1 file changed, 354 insertions(+) create mode 100644 clang/test/SemaTemplate/instantiate-expr-4.cpp (limited to 'clang/test/SemaTemplate/instantiate-expr-4.cpp') diff --git a/clang/test/SemaTemplate/instantiate-expr-4.cpp b/clang/test/SemaTemplate/instantiate-expr-4.cpp new file mode 100644 index 0000000..d95ccfe --- /dev/null +++ b/clang/test/SemaTemplate/instantiate-expr-4.cpp @@ -0,0 +1,354 @@ +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s + +// --------------------------------------------------------------------- +// C++ Functional Casts +// --------------------------------------------------------------------- +template +struct ValueInit0 { + int f() { + return int(); + } +}; + +template struct ValueInit0<5>; + +template +struct FunctionalCast0 { + int f() { + return int(N); + } +}; + +template struct FunctionalCast0<5>; + +struct X { // expected-note 3 {{candidate constructor (the implicit copy constructor)}} + X(int, int); // expected-note 3 {{candidate constructor}} +}; + +template +struct BuildTemporary0 { + X f() { + return X(N, M); + } +}; + +template struct BuildTemporary0<5, 7>; + +template +struct Temporaries0 { + void f() { + (void)X(N, M); + } +}; + +template struct Temporaries0<5, 7>; + +// Ensure that both the constructor and the destructor are instantiated by +// checking for parse errors from each. +template struct BadX { + BadX() { int a[-N]; } // expected-error {{array with a negative size}} + ~BadX() { int a[-N]; } // expected-error {{array with a negative size}} +}; + +template +struct PR6671 { + void f() { (void)BadX<1>(); } // expected-note 2 {{instantiation}} +}; +template struct PR6671<1>; + +// --------------------------------------------------------------------- +// new/delete expressions +// --------------------------------------------------------------------- +struct Y { }; + +template +struct New0 { + T* f(bool x) { + if (x) + return new T; // expected-error{{no matching}} + else + return new T(); + } +}; + +template struct New0; +template struct New0; +template struct New0; // expected-note{{instantiation}} + +template +struct New1 { + T* f(bool x, Arg1 a1) { + return new T(a1); // expected-error{{no matching}} + } +}; + +template struct New1; +template struct New1; +template struct New1; // expected-note{{instantiation}} + +template +struct New2 { + T* f(bool x, Arg1 a1, Arg2 a2) { + return new T(a1, a2); // expected-error{{no matching}} + } +}; + +template struct New2; +template struct New2; // expected-note{{instantiation}} +// FIXME: template struct New2; + +// PR5833 +struct New3 { + New3(); + + void *operator new[](__SIZE_TYPE__) __attribute__((unavailable)); // expected-note{{explicitly made unavailable}} +}; + +template +void* object_creator() { + return new C(); // expected-error{{call to unavailable function 'operator new[]'}} +} + +template void *object_creator(); // expected-note{{instantiation}} + +template +struct Delete0 { + void f(T t) { + delete t; // expected-error{{cannot delete}} + ::delete [] t; // expected-error{{cannot delete}} + } +}; + +template struct Delete0; +template struct Delete0; +template struct Delete0; // expected-note{{instantiation}} + +namespace PR5755 { + template + void Foo() { + char* p = 0; + delete[] p; + } + + void Test() { + Foo(); + } +} + +namespace PR10480 { + template + struct X { + X(); + ~X() { + T *ptr = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} + } + }; + + template + void f() { + new X[1]; // expected-note{{in instantiation of member function 'PR10480::X::~X' requested here}} + } + + template void f(); +} + +// --------------------------------------------------------------------- +// throw expressions +// --------------------------------------------------------------------- +template +struct Throw1 { + void f(T t) { + throw; + throw t; // expected-error{{incomplete type}} + } +}; + +struct Incomplete; // expected-note 2{{forward}} + +template struct Throw1; +template struct Throw1; +template struct Throw1; // expected-note{{instantiation}} + +// --------------------------------------------------------------------- +// typeid expressions +// --------------------------------------------------------------------- + +namespace std { + class type_info; +} + +template +struct TypeId0 { + const std::type_info &f(T* ptr) { + if (ptr) + return typeid(ptr); + else + return typeid(T); // expected-error{{'typeid' of incomplete type 'Incomplete'}} + } +}; + +struct Abstract { + virtual void f() = 0; +}; + +template struct TypeId0; +template struct TypeId0; // expected-note{{instantiation of member function}} +template struct TypeId0; + +// --------------------------------------------------------------------- +// type traits +// --------------------------------------------------------------------- +template +struct is_pod { + static const bool value = __is_pod(T); +}; + +static int is_pod0[is_pod::value? -1 : 1]; +static int is_pod1[is_pod::value? 1 : -1]; + +// --------------------------------------------------------------------- +// initializer lists +// --------------------------------------------------------------------- +template +struct InitList1 { + void f(Val1 val1) { + T x = { val1 }; + } +}; + +struct APair { + int *x; + const float *y; +}; + +template struct InitList1; +template struct InitList1; + +template +struct InitList2 { + void f(Val1 val1, Val2 val2) { + T x = { val1, val2 }; // expected-error{{cannot initialize}} + } +}; + +template struct InitList2; +template struct InitList2; // expected-note{{instantiation}} + +// --------------------------------------------------------------------- +// member references +// --------------------------------------------------------------------- +template +struct DotMemRef0 { + void f(T t) { + Result result = t.m; // expected-error{{non-const lvalue reference to type}} + } +}; + +struct MemInt { + int m; +}; + +struct InheritsMemInt : MemInt { }; + +struct MemIntFunc { + static int m(int); +}; + +template struct DotMemRef0; +template struct DotMemRef0; +template struct DotMemRef0; +template struct DotMemRef0; // expected-note{{instantiation}} + +template +struct ArrowMemRef0 { + void f(T t) { + Result result = t->m; // expected-error 2{{non-const lvalue reference}} + } +}; + +template +struct ArrowWrapper { + T operator->(); +}; + +template struct ArrowMemRef0; +template struct ArrowMemRef0; +template struct ArrowMemRef0; +template struct ArrowMemRef0; // expected-note{{instantiation}} + +template struct ArrowMemRef0, int&>; +template struct ArrowMemRef0, int&>; +template struct ArrowMemRef0, int (*)(int)>; +template struct ArrowMemRef0, float&>; // expected-note{{instantiation}} +template struct ArrowMemRef0 >, int&>; + +struct UnresolvedMemRefArray { + int f(int); + int f(char); +}; +UnresolvedMemRefArray Arr[10]; +template int UnresolvedMemRefArrayT(U u) { + return Arr->f(u); +} +template int UnresolvedMemRefArrayT(int); + +// FIXME: we should be able to return a MemInt without the reference! +MemInt &createMemInt(int); + +template +struct NonDepMemberExpr0 { + void f() { + createMemInt(N).m = N; + } +}; + +template struct NonDepMemberExpr0<0>; + +template +struct MemberFuncCall0 { + void f(T t) { + Result result = t.f(); + } +}; + +template +struct HasMemFunc0 { + T f(); +}; + + +template struct MemberFuncCall0, const int&>; + +template +struct ThisMemberFuncCall0 { + Result g(); + + void f() { + Result r1 = g(); + Result r2 = this->g(); + } +}; + +template struct ThisMemberFuncCall0; + +template +struct NonDepMemberCall0 { + void foo(HasMemFunc0 x) { + T result = x.f(); // expected-error{{non-const lvalue reference}} + } +}; + +template struct NonDepMemberCall0; +template struct NonDepMemberCall0; +template struct NonDepMemberCall0; // expected-note{{instantiation}} + + +template +struct QualifiedDeclRef0 { + T f() { + return is_pod::value; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'const bool'}} + } +}; + +template struct QualifiedDeclRef0; +template struct QualifiedDeclRef0; // expected-note{{instantiation}} -- cgit v1.2.3