diff options
| author | Ed Schouten <ed@FreeBSD.org> | 2009-06-27 10:45:02 +0000 |
|---|---|---|
| committer | Ed Schouten <ed@FreeBSD.org> | 2009-06-27 10:45:02 +0000 |
| commit | 4ebdf5c4f587daef4e0be499802eac3a7a49bf2f (patch) | |
| tree | 2c5a83521a20c02e7805581a174008aa9bc23579 /test/CXX | |
| parent | f698f7e71940663e26a4806a96fb0bdfa160c886 (diff) | |
Notes
Diffstat (limited to 'test/CXX')
| -rw-r--r-- | test/CXX/class/class.local/p1.cpp | 18 | ||||
| -rw-r--r-- | test/CXX/class/class.local/p2.cpp | 12 | ||||
| -rw-r--r-- | test/CXX/class/class.local/p3.cpp | 30 | ||||
| -rw-r--r-- | test/CXX/class/class.local/p4.cpp | 10 | ||||
| -rw-r--r-- | test/CXX/class/class.nested.type/p1.cpp | 11 | ||||
| -rw-r--r-- | test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp | 13 | ||||
| -rw-r--r-- | test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp | 21 | ||||
| -rw-r--r-- | test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp | 6 | ||||
| -rw-r--r-- | test/CXX/temp/temp.decls/temp.fct/temp.over.link/p4-neg.cpp | 27 | ||||
| -rw-r--r-- | test/CXX/temp/temp.decls/temp.fct/temp.over.link/p4.cpp | 13 | ||||
| -rw-r--r-- | test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp | 28 | ||||
| -rw-r--r-- | test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp | 31 | ||||
| -rw-r--r-- | test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp | 60 |
13 files changed, 280 insertions, 0 deletions
diff --git a/test/CXX/class/class.local/p1.cpp b/test/CXX/class/class.local/p1.cpp new file mode 100644 index 000000000000..8a84f5dbed8a --- /dev/null +++ b/test/CXX/class/class.local/p1.cpp @@ -0,0 +1,18 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +int x; +void f() +{ + static int s; + int x; // expected-note{{'x' declared here}} + extern int g(); + + struct local { + int g() { return x; } // expected-error{{reference to local variable 'x' declared in enclosed function 'f'}} + int h() { return s; } + int k() { return :: x; } + int l() { return g(); } + }; +} + +local* p = 0; // expected-error{{unknown type name 'local'}} diff --git a/test/CXX/class/class.local/p2.cpp b/test/CXX/class/class.local/p2.cpp new file mode 100644 index 000000000000..854415fe307d --- /dev/null +++ b/test/CXX/class/class.local/p2.cpp @@ -0,0 +1,12 @@ +// RUN: clang-cc -fsyntax-only -verify %s -faccess-control + +struct A { }; + +void f() { + struct B : private A {}; // expected-note{{'private' inheritance specifier here}} + + B b; + + A *a = &b; // expected-error{{conversion from 'struct B' to inaccessible base class 'struct A'}} \ + expected-error{{incompatible type initializing 'struct B *', expected 'struct A *'}} +} diff --git a/test/CXX/class/class.local/p3.cpp b/test/CXX/class/class.local/p3.cpp new file mode 100644 index 000000000000..d888a6d93633 --- /dev/null +++ b/test/CXX/class/class.local/p3.cpp @@ -0,0 +1,30 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +void f1() { + struct X { + struct Y; + }; + + struct X::Y { + void f() {} + }; +} + +void f2() { + struct X { + struct Y; + + struct Y { + void f() {} + }; + }; +} + +// A class nested within a local class is a local class. +void f3(int a) { // expected-note{{'a' declared here}} + struct X { + struct Y { + int f() { return a; } // expected-error{{reference to local variable 'a' declared in enclosed function 'f3'}} + }; + }; +}
\ No newline at end of file diff --git a/test/CXX/class/class.local/p4.cpp b/test/CXX/class/class.local/p4.cpp new file mode 100644 index 000000000000..40702ad96899 --- /dev/null +++ b/test/CXX/class/class.local/p4.cpp @@ -0,0 +1,10 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +void f() { + struct X { + static int a; // expected-error {{static data member 'a' not allowed in local class 'X'}} + int b; + + static void f() { } + }; +}
\ No newline at end of file diff --git a/test/CXX/class/class.nested.type/p1.cpp b/test/CXX/class/class.nested.type/p1.cpp new file mode 100644 index 000000000000..33bf4b4473e5 --- /dev/null +++ b/test/CXX/class/class.nested.type/p1.cpp @@ -0,0 +1,11 @@ +class X { +public: + typedef int I; + class Y { }; + I a; +}; + +I b; // expected-error{{unknown type name 'I'}} +Y c; // expected-error{{unknown type name 'Y'}} +X::Y d; +X::I e;
\ No newline at end of file diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp new file mode 100644 index 000000000000..fa3101c6736c --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp @@ -0,0 +1,13 @@ +// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x +void f() { + auto a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}} +} + +struct S { auto a; }; // expected-error{{'auto' not allowed in struct member}} + +void f(auto a) // expected-error{{'auto' not allowed in function prototype}} +{ + try { } catch (auto a) { } // expected-error{{'auto' not allowed in exception declaration}} +} + +template <auto a = 10> class C { }; // expected-error{{'auto' not allowed in template parameter}} diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp new file mode 100644 index 000000000000..d97f2b83d1a7 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp @@ -0,0 +1,21 @@ +// RUN: clang-cc -fsyntax-only -std=c++0x -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; +}; + +const int&& foo(); +int i; +struct A { double x; }; +const A* a = new A(); + +static_assert(is_same<decltype(foo()), const int&&>::value, ""); +static_assert(is_same<decltype(i), int>::value, ""); +static_assert(is_same<decltype(a->x), double>::value, ""); +static_assert(is_same<decltype((a->x)), const double&>::value, ""); diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp new file mode 100644 index 000000000000..9d855349f295 --- /dev/null +++ b/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp @@ -0,0 +1,6 @@ +// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x + +void f() { + int b[5]; + auto a[5] = b; // expected-error{{'a' declared as array of 'auto'}} +} diff --git a/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p4-neg.cpp b/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p4-neg.cpp new file mode 100644 index 000000000000..b482955818cb --- /dev/null +++ b/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p4-neg.cpp @@ -0,0 +1,27 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +template<typename T> void f0(T) { } // expected-note{{previous}} +template<class U> void f0(U) { } // expected-error{{redefinition}} + +template<int I> void f0() { } // expected-note{{previous}} +template<int> void f0() { } // expected-error{{redefinition}} + +typedef int INT; + +template<template<class T, T Value1, INT> class X> + void f0() { } // expected-note{{previous}} +template<template<typename T, T Value1, int> class> + void f0() { } // expected-error{{redefinition}} + +template<typename T> +struct MetaFun; + +template<typename T> + typename MetaFun<T*>::type f0(const T&) { } // expected-note{{previous}} +template<class U> + typename MetaFun<U*>::type f0(const U&) { } // expected-error{{redefinition}} + +// FIXME: We need canonicalization of expressions for this to work +// template<int> struct A { }; +// template<int I> void f0(A<I>) { } // Xpected-note{{previous}} +// template<int J> void f0(A<J>) { } // Xpected-error{{redefinition}}
\ No newline at end of file diff --git a/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p4.cpp b/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p4.cpp new file mode 100644 index 000000000000..de1a883bcd7a --- /dev/null +++ b/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p4.cpp @@ -0,0 +1,13 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +// All of these function templates are distinct. +template<typename T> void f0(T) { } +template<typename T, typename U> void f0(T) { } +template<typename T, typename U> void f0(U) { } +void f0(); +template<typename T> void f0(T*); +void f0(int); +template<int I> void f0(); +template<typename T> void f0(); + + diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp new file mode 100644 index 000000000000..beb6aad2c089 --- /dev/null +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp @@ -0,0 +1,28 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +template<typename T> struct A { }; + +template<typename T> A<T> f0(T*); + +void test_f0(int *ip, float const *cfp) { + A<int> a0 = f0(ip); + A<const float> a1 = f0(cfp); +} + +template<typename T> void f1(T*, int); + +void test_f1(int *ip, float fv) { + f1(ip, fv); +} + +template<typename T> void f2(T*, T*); + +struct ConvToIntPtr { + operator int*() const; +}; + +void test_f2(int *ip, float *fp) { + f2(ip, ConvToIntPtr()); // expected-error{{no matching function}} + f2(ip, ip); // okay + f2(ip, fp); // expected-error{{no matching function}} +} diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp new file mode 100644 index 000000000000..6f27d3636892 --- /dev/null +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp @@ -0,0 +1,31 @@ +// RUN: clang-cc -fsyntax-only -verify %s +template<typename T> struct A { }; + +// bullet 1 +template<typename T> A<T> f0(T* ptr); + +void test_f0_bullet1() { + int arr0[6]; + A<int> a0 = f0(arr0); + const int arr1[] = { 1, 2, 3, 4, 5 }; + A<const int> a1 = f0(arr1); +} + +// bullet 2 +int g0(int, int); +float g1(float); + +void test_f0_bullet2() { + A<int(int, int)> a0 = f0(g0); + A<float(float)> a1 = f0(g1); +} + +// bullet 3 +struct X { }; +const X get_X(); + +template<typename T> A<T> f1(T); + +void test_f1_bullet3() { + A<X> a0 = f1(get_X()); +} diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp new file mode 100644 index 000000000000..c014c663598c --- /dev/null +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp @@ -0,0 +1,60 @@ +// RUN: clang-cc -fsyntax-only %s + +template<typename T> struct A { }; + +// Top-level cv-qualifiers of P's type are ignored for type deduction. +template<typename T> A<T> f0(const T); + +void test_f0(int i, const int ci) { + A<int> a0 = f0(i); + A<int> a1 = f0(ci); +} + +// If P is a reference type, the type referred to by P is used for type +// deduction. +template<typename T> A<T> f1(T&); + +void test_f1(int i, const int ci, volatile int vi) { + A<int> a0 = f1(i); + A<const int> a1 = f1(ci); + A<volatile int> a2 = f1(vi); +} + +template<typename T, unsigned N> struct B { }; +template<typename T, unsigned N> B<T, N> g0(T (&array)[N]); + +void test_g0() { + int array0[5]; + B<int, 5> b0 = g0(array0); + const int array1[] = { 1, 2, 3}; + B<const int, 3> b1 = g0(array1); +} + +template<typename T> B<T, 0> g1(const A<T>&); + +void test_g1(A<float> af) { + B<float, 0> b0 = g1(af); + B<int, 0> b1 = g1(A<int>()); +} + +// - If the original P is a reference type, the deduced A (i.e., the type +// referred to by the reference) can be more cv-qualified than the +// transformed A. +template<typename T> A<T> f2(const T&); + +void test_f2(int i, const int ci, volatile int vi) { + A<int> a0 = f2(i); + A<int> a1 = f2(ci); + A<volatile int> a2 = f2(vi); +} + +// - The transformed A can be another pointer or pointer to member type that +// can be converted to the deduced A via a qualification conversion (4.4). +template<typename T> A<T> f3(T * * const * const); + +void test_f3(int ***ip, volatile int ***vip) { + A<int> a0 = f3(ip); + A<volatile int> a1 = f3(vip); +} + +// FIXME: the next bullet requires a lot of effort. |
