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/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p4.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics namespace PR8598 { template<class T> struct identity { typedef T type; }; template<class T, class C> void f(T C::*, typename identity<T>::type*){} struct X { void f() {}; }; void g() { (f)(&X::f, 0); } } namespace PR12132 { template<typename S> void fun(const int* const S::* member) {} struct A { int* x; }; void foo() { fun(&A::x); } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %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]); template<typename T, unsigned N> B<T, N> g0b(const 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); B<int, 3> b2 = g0b(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); } // PR5913 template <typename T, int N> void Foo(const T (&a)[N]) { T x; x = 0; } const int a[1] = { 0 }; void Test() { Foo(a); } // - 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); } // Also accept conversions for pointer types which require removing // [[noreturn]]. namespace noreturn_stripping { template <class R> void f(R (*function)()); void g() __attribute__ ((__noreturn__)); void h(); void test() { f(g); f(h); } } // - If P is a class, and P has the form template-id, then A can be a // derived class of the deduced A. Likewise, if P is a pointer to a class // of the form template-id, A can be a pointer to a derived class pointed // to by the deduced A. template<typename T, int I> struct C { }; struct D : public C<int, 1> { }; struct E : public D { }; struct F : A<float> { }; struct G : A<float>, C<int, 1> { }; template<typename T, int I> C<T, I> *f4a(const C<T, I>&); template<typename T, int I> C<T, I> *f4b(C<T, I>); template<typename T, int I> C<T, I> *f4c(C<T, I>*); int *f4c(...); void test_f4(D d, E e, F f, G g) { C<int, 1> *ci1a = f4a(d); C<int, 1> *ci2a = f4a(e); C<int, 1> *ci1b = f4b(d); C<int, 1> *ci2b = f4b(e); C<int, 1> *ci1c = f4c(&d); C<int, 1> *ci2c = f4c(&e); C<int, 1> *ci3c = f4c(&g); int *ip1 = f4c(&f); } // PR8462 namespace N { struct T0; struct T1; template<typename X, typename Y> struct B {}; struct J : B<T0,T0> {}; struct K : B<T1,T1> {}; struct D : J, K {}; template<typename X, typename Y> void F(B<Y,X>); void test() { D d; N::F<T0>(d); // Fails N::F<T1>(d); // OK } } namespace PR9233 { template<typename T> void f(const T **q); // expected-note{{candidate template ignored: substitution failure [with T = int]}} void g(int **p) { f(p); // expected-error{{no matching function for call to 'f'}} } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics 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()); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p1-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // Metafunction to extract the Nth type from a set of types. template<unsigned N, typename ...Types> struct get_nth_type; template<unsigned N, typename Head, typename ...Tail> struct get_nth_type<N, Head, Tail...> : get_nth_type<N-1, Tail...> { }; template<typename Head, typename ...Tail> struct get_nth_type<0, Head, Tail...> { typedef Head type; }; // Placeholder type when get_nth_type fails. struct no_type {}; template<unsigned N> struct get_nth_type<N> { typedef no_type type; }; template<typename T, typename U> struct pair { }; template<typename T, typename U> pair<T, U> make_pair(T, U); // For a function parameter pack that occurs at the end of the // parameter-declaration-list, the type A of each remaining argument // of the call is compared with the type P of the declarator-id of the // function parameter pack. template<typename ...Args> typename get_nth_type<0, Args...>::type first_arg(Args...); template<typename ...Args> typename get_nth_type<1, Args...>::type second_arg(Args...); void test_simple_deduction(int *ip, float *fp, double *dp) { int *ip1 = first_arg(ip); int *ip2 = first_arg(ip, fp); int *ip3 = first_arg(ip, fp, dp); no_type nt1 = first_arg(); } template<typename ...Args> typename get_nth_type<0, Args...>::type first_arg_ref(Args&...); template<typename ...Args> typename get_nth_type<1, Args...>::type second_arg_ref(Args&...); void test_simple_ref_deduction(int *ip, float *fp, double *dp) { int *ip1 = first_arg_ref(ip); int *ip2 = first_arg_ref(ip, fp); int *ip3 = first_arg_ref(ip, fp, dp); no_type nt1 = first_arg_ref(); } // FIXME: Use the template parameter names in this diagnostic. template<typename ...Args1, typename ...Args2> typename get_nth_type<0, Args1...>::type first_arg_pair(pair<Args1, Args2>...); // expected-note{{candidate template ignored: could not match 'pair<type-parameter-0-0, type-parameter-0-1>' against 'int'}} template<typename ...Args1, typename ...Args2> typename get_nth_type<1, Args1...>::type second_arg_pair(pair<Args1, Args2>...); void test_pair_deduction(int *ip, float *fp, double *dp) { int *ip1 = first_arg_pair(make_pair(ip, 17)); int *ip2 = first_arg_pair(make_pair(ip, 17), make_pair(fp, 17)); int *ip3 = first_arg_pair(make_pair(ip, 17), make_pair(fp, 17), make_pair(dp, 17)); float *fp1 = second_arg_pair(make_pair(ip, 17), make_pair(fp, 17)); float *fp2 = second_arg_pair(make_pair(ip, 17), make_pair(fp, 17), make_pair(dp, 17)); no_type nt1 = first_arg_pair(); no_type nt2 = second_arg_pair(); no_type nt3 = second_arg_pair(make_pair(ip, 17)); first_arg_pair(make_pair(ip, 17), 16); // expected-error{{no matching function for call to 'first_arg_pair'}} } // For a function parameter pack that does not occur at the end of the // parameter-declaration-list, the type of the parameter pack is a // non-deduced context. template<typename ...Types> struct tuple { }; template<typename ...Types> void pack_not_at_end(tuple<Types...>, Types... values, int); void test_pack_not_at_end(tuple<int*, double*> t2) { pack_not_at_end(t2, 0, 0, 0); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // If P is an rvalue reference to a cv-unqualified template parameter // and the argument is an lvalue, the type "lvalue reference to A" is // used in place of A for type deduction. template<typename T> struct X { }; template<typename T> X<T> f0(T&&); struct Y { }; template<typename T> T prvalue(); template<typename T> T&& xvalue(); template<typename T> T& lvalue(); void test_f0() { X<int> xi0 = f0(prvalue<int>()); X<int> xi1 = f0(xvalue<int>()); X<int&> xi2 = f0(lvalue<int>()); X<Y> xy0 = f0(prvalue<Y>()); X<Y> xy1 = f0(xvalue<Y>()); X<Y&> xy2 = f0(lvalue<Y>()); } template<typename T> X<T> f1(const T&&); // expected-note{{candidate function [with T = int] not viable: no known conversion from 'int' to 'const int &&' for 1st argument}} \ // expected-note{{candidate function [with T = Y] not viable: no known conversion from 'Y' to 'const Y &&' for 1st argument}} void test_f1() { X<int> xi0 = f1(prvalue<int>()); X<int> xi1 = f1(xvalue<int>()); f1(lvalue<int>()); // expected-error{{no matching function for call to 'f1'}} X<Y> xy0 = f1(prvalue<Y>()); X<Y> xy1 = f1(xvalue<Y>()); f1(lvalue<Y>()); // expected-error{{no matching function for call to 'f1'}} } namespace std_example { template <class T> int f(T&&); template <class T> int g(const T&&); // expected-note{{candidate function [with T = int] not viable: no known conversion from 'int' to 'const int &&' for 1st argument}} int i; int n1 = f(i); int n2 = f(0); int n3 = g(i); // expected-error{{no matching function for call to 'g'}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p6.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace test0 { template<class T> void apply(T x, void (*f)(T)) { f(x); } // expected-note 2 {{candidate template ignored: deduced conflicting types for parameter 'T'}}\ // expected-note {{no overload of 'temp2' matching 'void (*)(int)'}} template<class A> void temp(A); void test0() { // okay: deduce T=int from first argument, A=int during overload apply(0, &temp); apply(0, &temp<>); // okay: deduce T=int from first and second arguments apply(0, &temp<int>); // deduction failure: T=int from first, T=long from second apply(0, &temp<long>); // expected-error {{no matching function for call to 'apply'}} } void over(int); int over(long); void test1() { // okay: deductions match apply(0, &over); // deduction failure: deduced T=long from first argument, T=int from second apply(0L, &over); // expected-error {{no matching function for call to 'apply'}} } void over(short); void test2() { // deduce T=int from first arg, second arg is undeduced context, // pick correct overload of 'over' during overload resolution for 'apply' apply(0, &over); } template<class A, class B> B temp2(A); void test3() { // deduce T=int from first arg, A=int B=void during overload resolution apply(0, &temp2); apply(0, &temp2<>); apply(0, &temp2<int>); // overload failure apply(0, &temp2<long>); // expected-error {{no matching function for call to 'apply'}} } } namespace test1 { template<class T> void invoke(void (*f)(T)) { f(T()); } // expected-note 6 {{couldn't infer template argument}} \ // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} template<class T> void temp(T); void test0() { // deduction failure: overload has template => undeduced context invoke(&temp); // expected-error {{no matching function for call to 'invoke'}} invoke(&temp<>); // expected-error {{no matching function for call to 'invoke'}} // okay: full template-id invoke(&temp<int>); } void over(int); int over(long); void test1() { // okay: only one overload matches invoke(&over); } void over(short); void test2() { // deduction failure: overload has multiple matches => undeduced context invoke(&over); // expected-error {{no matching function for call to 'invoke'}} } template<class A, class B> B temp2(A); void test3() { // deduction failure: overload has template => undeduced context // (even though partial application temp2<int> could in theory // let us infer T=int) invoke(&temp2); // expected-error {{no matching function for call to 'invoke'}} invoke(&temp2<>); // expected-error {{no matching function for call to 'invoke'}} invoke(&temp2<int>); // expected-error {{no matching function for call to 'invoke'}} // okay: full template-id invoke(&temp2<int, void>); // overload failure invoke(&temp2<int, int>); // expected-error {{no matching function for call to 'invoke'}} } } namespace rdar8360106 { template<typename R, typename T> void f0(R (*)(T), T); template<typename R, typename T> void f1(R (&)(T) , T); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}} template<typename R, typename T> void f2(R (* const&)(T), T); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}} int g(int); int g(int, int); void h() { f0(g, 1); f0(&g, 1); f1(g, 1); f1(&g, 1); // expected-error{{no matching function for call to 'f1'}} f2(g, 1); // expected-error{{no matching function for call to 'f2'}} f2(&g, 1); } } namespace PR11713 { template<typename T> int f(int, int, int); template<typename T> float f(float, float); template<typename R, typename B1, typename B2, typename A1, typename A2> R& g(R (*)(B1, B2), A1, A2); void h() { float &fr = g(f<int>, 1, 2); } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p9-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // expected-no-diagnostics template<typename T> int &f0(T&); template<typename T> float &f0(T&&); // Core issue 1164 void test_f0(int i) { int &ir0 = f0(i); float &fr0 = f0(5); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p12.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // expected-no-diagnostics // Note: Partial ordering of function templates containing template // parameter packs is independent of the number of deduced arguments // for those template parameter packs. template<class ...> struct Tuple { }; template<class ... Types> int &g(Tuple<Types ...>); // #1 template<class T1, class ... Types> float &g(Tuple<T1, Types ...>); // #2 template<class T1, class ... Types> double &g(Tuple<T1, Types& ...>); // #3 void test_g() { int &ir1 = g(Tuple<>()); float &fr1 = g(Tuple<int, float>()); double &dr1 = g(Tuple<int, float&>()); double &dr2 = g(Tuple<int>()); } template<class ... Types> int &h(int (*)(Types ...)); // #1 template<class T1, class ... Types> float &h(int (*)(T1, Types ...)); // #2 template<class T1, class ... Types> double &h(int (*)(T1, Types& ...)); // #3 void test_h() { int &ir1 = h((int(*)())0); float &fr1 = h((int(*)(int, float))0); double &dr1 = h((int(*)(int, float&))0); double &dr2 = h((int(*)(int))0); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p11.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template <class T> T* f(int); // #1 template <class T, class U> T& f(U); // #2 void g() { int *ip = f<int>(1); // calls #1 } template<typename T> struct identity { typedef T type; }; template <class T> T* f2(int, typename identity<T>::type = 0); template <class T, class U> T& f2(U, typename identity<T>::type = 0); void g2() { int* ip = f2<int>(1); } template<class T, class U> struct A { }; template<class T, class U> inline int *f3( U, A<U,T>* p = 0 ); // #1 expected-note{{candidate function [with T = int, U = int]}} template< class U> inline float *f3( U, A<U,U>* p = 0 ); // #2 expected-note{{candidate function [with U = int]}} void g3() { float *fp = f3<int>( 42, (A<int,int>*)0 ); // Ok, picks #2. f3<int>( 42 ); // expected-error{{call to 'f3' is ambiguous}} } namespace PR9006 { struct X { template <class Get> int &f(char const* name, Get fget, char const* docstr = 0); template <class Get, class Set> float &f(char const* name, Get fget, Set fset, char const* docstr = 0); }; void test(X x) { int &ir = x.f("blah", 0, "blah"); } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.names/p4.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics struct meta { template<typename U> struct apply { typedef U* type; }; }; template<typename T, typename U> void f(typename T::template apply<U>::type); void test_f(int *ip) { f<meta, int>(ip); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.names/p2.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // Ensure that when enforcing access control an unqualified template name with // explicit template arguments, we don't lose the context of the name lookup // because of the required early lookup to determine if it names a template. namespace PR7163 { template <typename R, typename P> void h(R (*func)(P)) {} class C { template <typename T> static void g(T*) {}; public: void f() { h(g<int>); } }; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp
repos/DirectXShaderCompiler/tools/clang/test/CXX/temp/temp.names/p3-0x.cpp
// RUN: %clang_cc1 -std=c++11 %s -verify template<int i> class X { /* ... */ }; X< 1>2 > x1; // expected-error{{expected unqualified-id}} X<(1>2)> x2; // OK template<class T> class Y { /* ... */ }; Y<X<1>> x3; // OK, same as Y<X<1> > x3; Y<X<6>>1>> x4; // expected-error{{expected unqualified-id}} Y<X<(6>>1)>> x5; int a, b; Y<decltype(a < b)> x6;
0
repos/DirectXShaderCompiler/tools/clang/test/CXX
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/p4-0x.cpp
// RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only %s struct S { constexpr S(bool b) : b(b) {} constexpr explicit operator bool() const { return b; } bool b; }; struct T { constexpr operator int() const { return 1; } }; struct U { constexpr operator int() const { return 1; } // expected-note {{candidate}} constexpr operator long() const { return 0; } // expected-note {{candidate}} }; static_assert(S(true), ""); static_assert(S(false), "not so fast"); // expected-error {{not so fast}} static_assert(T(), ""); static_assert(U(), ""); // expected-error {{ambiguous}} static_assert(false, L"\x14hi" "!" R"x(")x"); // expected-error {{static_assert failed L"\024hi!\""}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
// RUN: %clang_cc1 -std=c++11 -verify -fcxx-exceptions %s [[noreturn]] void a() { return; // expected-warning {{function 'a' declared 'noreturn' should not return}} } void a2 [[noreturn]] () { return; // expected-warning {{function 'a2' declared 'noreturn' should not return}} } [[noreturn, noreturn]] void b() { throw 0; } // expected-error {{attribute 'noreturn' cannot appear multiple times in an attribute specifier}} [[noreturn]] [[noreturn]] void b2() { throw 0; } // ok [[noreturn()]] void c(); // expected-error {{attribute 'noreturn' cannot have an argument list}} void d() [[noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to types}} int d2 [[noreturn]]; // expected-error {{'noreturn' attribute only applies to functions}} [[noreturn]] int e() { b2(); } // ok int f(); // expected-note {{declaration missing '[[noreturn]]' attribute is here}} [[noreturn]] int f(); // expected-error {{function declared '[[noreturn]]' after its first declaration}} int f(); [[noreturn]] int g(); int g() { while (true) b(); } // ok [[noreturn]] int g(); [[gnu::noreturn]] int h(); template<typename T> void test_type(T) { T::error; } // expected-error {{has no members}} template<> void test_type(int (*)()) {} void check() { // We do not consider [[noreturn]] to be part of the function's type. // However, we do treat [[gnu::noreturn]] as being part of the type. // // This isn't quite GCC-compatible; it treats [[gnu::noreturn]] as // being part of a function *pointer* type, but not being part of // a function type. test_type(e); test_type(f); test_type(g); test_type(h); // expected-note {{instantiation}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p7.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s template<typename T, typename A, int N> struct X { alignas(T) alignas(A) T buffer[N]; }; static_assert(alignof(X<char, int, sizeof(int)>) == alignof(int), ""); static_assert(alignof(X<int, char, 1>) == alignof(int), ""); template<typename T, typename A, int N> struct Y { alignas(A) T buffer[N]; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'int [1]'}} }; static_assert(alignof(Y<char, int, sizeof(int)>) == alignof(int), ""); static_assert(alignof(Y<int, char, 1>) == alignof(int), ""); // expected-note {{in instantiation of}} void pr16992 () { int x = alignof int; // expected-error {{expected parentheses around type name in alignof expression}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p8.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s alignas(double) void f(); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}} alignas(double) unsigned char c[sizeof(double)]; // expected-note {{previous}} extern unsigned char c[sizeof(double)]; alignas(float) extern unsigned char c[sizeof(double)]; // expected-error {{different alignment}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp
// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -verify %s alignas(1) int n1; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'int'}} alignas(1) alignas(2) int n2; // expected-error {{less than minimum alignment}} alignas(1) alignas(2) alignas(4) int n3; // ok alignas(1) alignas(2) alignas(0) int n4; // expected-error {{less than minimum alignment}} alignas(1) alignas(2) int n5 alignas(4); // ok alignas(1) alignas(4) int n6 alignas(2); // ok alignas(1) int n7 alignas(2), // expected-error {{less than minimum alignment}} n8 alignas(4); // ok alignas(8) int n9 alignas(2); // ok, overaligned alignas(1) extern int n10; // expected-error {{less than minimum alignment}} enum alignas(1) E1 {}; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'E1'}} enum alignas(1) E2 : char {}; // ok enum alignas(4) E3 { e3 = 0 }; // ok enum alignas(4) E4 { e4 = 1ull << 33 }; // expected-error {{requested alignment is less than minimum alignment of 8 for type 'E4'}} enum alignas(8) E5 {}; static_assert(alignof(E5) == 8, ""); typedef __attribute__((aligned(16))) int IntAlign16; enum E6 : IntAlign16 {}; static_assert(alignof(E6) == 4, ""); struct S1 { alignas(8) int n; }; struct alignas(2) S2 { // expected-error {{requested alignment is less than minimum alignment of 4 for type 'S2'}} int n; }; struct alignas(2) S3 { // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S3'}} S1 s1; }; struct alignas(2) S4 : S1 { // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S4'}} }; struct S5 : S1 { alignas(2) S1 s1; // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S1'}} }; struct S6 { S1 s1; }; struct S7 : S1 { }; struct alignas(2) alignas(8) alignas(1) S8 : S1 { }; S1 s1 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S1'}} S6 s6 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S6'}} S7 s7 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S7'}} template<int N, int M, typename T> struct alignas(N) X { // expected-error 3{{requested alignment is less than minimum}} alignas(M) T t; // expected-error 3{{requested alignment is less than minimum}} }; template struct X<1, 1, char>; template struct X<4, 1, char>; template struct X<1, 2, char>; // expected-note {{instantiation}} template struct X<1, 1, short>; // expected-note {{instantiation}} template struct X<2, 1, short>; // expected-note {{instantiation}} template struct X<2, 2, short>; template struct X<16, 8, S1>; template struct X<4, 4, S1>; // expected-note {{instantiation}} template<int N, typename T> struct Y { enum alignas(N) E : T {}; // expected-error {{requested alignment is less than minimum}} }; template struct Y<1, char>; template struct Y<2, char>; template struct Y<1, short>; // expected-note {{instantiation}} template struct Y<2, short>; template<int N, typename T> void f() { alignas(N) T v; // expected-error {{requested alignment is less than minimum}} }; template void f<1, char>(); template void f<2, char>(); template void f<1, short>(); // expected-note {{instantiation}} template void f<2, short>();
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s alignas(4) extern int n1; // expected-note {{previous declaration}} alignas(8) int n1; // expected-error {{redeclaration has different alignment requirement (8 vs 4)}} alignas(8) int n2; // expected-note {{previous declaration}} alignas(4) extern int n2; // expected-error {{different alignment requirement (4 vs 8)}} alignas(8) extern int n3; // expected-note {{previous declaration}} alignas(4) extern int n3; // expected-error {{different alignment requirement (4 vs 8)}} extern int n4; alignas(8) extern int n4; alignas(8) extern int n5; extern int n5; int n6; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} alignas(8) extern int n6; // expected-note {{declared with 'alignas' attribute here}} extern int n7; alignas(8) int n7; alignas(8) extern int n8; // expected-note {{declared with 'alignas' attribute here}} int n8; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} int n9; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} alignas(4) extern int n9; // expected-note {{declared with 'alignas' attribute here}} enum alignas(2) E : char; // expected-note {{declared with 'alignas' attribute here}} enum E : char {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} enum alignas(4) F : char; // expected-note {{previous declaration is here}} enum alignas(2) F : char; // expected-error {{redeclaration has different alignment requirement (2 vs 4)}} enum G : char; enum alignas(8) G : char {}; enum G : char; enum H : char {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} enum alignas(1) H : char; // expected-note {{declared with 'alignas' attribute here}} struct S; struct alignas(16) S; // expected-note {{declared with 'alignas' attribute here}} struct S; struct S { int n; }; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} struct alignas(2) T; struct alignas(2) T { char c; }; // expected-note {{previous declaration is here}} struct T; struct alignas(4) T; // expected-error {{redeclaration has different alignment requirement (4 vs 2)}} struct U; struct alignas(2) U {}; struct V {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} struct alignas(1) V; // expected-note {{declared with 'alignas' attribute here}} template<int M, int N> struct alignas(M) W; template<int M, int N> struct alignas(N) W {}; W<4,4> w44; // ok // FIXME: We should reject this. W<1,2> w12; static_assert(alignof(W<4,4>) == 4, ""); template<int M, int N, int O, int P> struct X { alignas(M) alignas(N) static char Buffer[32]; // expected-note {{previous declaration is here}} }; template<int M, int N, int O, int P> alignas(O) alignas(P) char X<M, N, O, P>::Buffer[32]; // expected-error {{redeclaration has different alignment requirement (8 vs 2)}} char *x1848 = X<1,8,4,8>::Buffer; // ok char *x1248 = X<1,2,4,8>::Buffer; // expected-note {{in instantiation of}} template<int M, int N, int O, int P> struct Y { enum alignas(M) alignas(N) E : char; }; template<int M, int N, int O, int P> enum alignas(O) alignas(P) Y<M,N,O,P>::E : char { e }; int y1848 = Y<1,8,4,8>::e; // FIXME: We should reject this. int y1248 = Y<1,2,4,8>::e; // Don't crash here. alignas(4) struct Incomplete incomplete; // expected-error {{incomplete type}} expected-note {{forward declaration}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p6.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s namespace std_example { int p[10]; void f() { int x = 42, y[5]; // FIXME: Produce a better diagnostic for this case. int(p[[x] { return x; }()]); // expected-error {{expected ']'}} \ // expected-warning {{unknown attribute 'x' ignored}} y[[] { return 2; }()] = 2; // expected-error {{consecutive left square brackets}} } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
// RUN: %clang_cc1 -std=c++1y -verify %s class [[deprecated]] C {}; // expected-note {{'C' has been explicitly marked deprecated here}} C c; // expected-warning {{'C' is deprecated}} typedef int t [[deprecated]]; // expected-note {{'t' has been explicitly marked deprecated here}} t x = 42; // expected-warning {{'t' is deprecated}} [[deprecated]] int old = 42; // expected-note {{'old' has been explicitly marked deprecated here}} int use = old; // expected-warning {{'old' is deprecated}} struct S { [[deprecated]] int member = 42; } s; // expected-note {{'member' has been explicitly marked deprecated here}} int use2 = s.member; // expected-warning {{'member' is deprecated}} [[deprecated]] int f() { return 42; } // expected-note {{'f' has been explicitly marked deprecated here}} int use3 = f(); // expected-warning {{'f' is deprecated}} enum [[deprecated]] e { E }; // expected-note {{'e' has been explicitly marked deprecated here}} e my_enum; // expected-warning {{'e' is deprecated}} template <typename T> class X {}; template <> class [[deprecated]] X<int> {}; // expected-note {{'X<int>' has been explicitly marked deprecated here}} X<char> x1; X<int> x2; // expected-warning {{'X<int>' is deprecated}} template <typename T> class [[deprecated]] X2 {}; template <> class X2<int> {}; X2<char> x3; // FIXME: no warning! X2<int> x4;
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p2.cpp
// RUN: %clang_cc1 -verify -std=c++11 %s int f(int); // expected-note 2{{declaration missing '[[carries_dependency]]' attribute is here}} [[carries_dependency]] int f(int); // expected-error {{function declared '[[carries_dependency]]' after its first declaration}} int f(int n [[carries_dependency]]); // expected-error {{parameter declared '[[carries_dependency]]' after its first declaration}} int g([[carries_dependency]] int n); // expected-note {{declaration missing '[[carries_dependency]]' attribute is here}} int g(int); [[carries_dependency]] int g(int); // expected-error {{function declared '[[carries_dependency]]' after its first declaration}} int g(int n [[carries_dependency]]); int h [[carries_dependency]](); int h(); [[carries_dependency]] int h();
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp
// RUN: %clang_cc1 -verify -std=c++11 %s [[carries_dependency, carries_dependency]] int m1(); // expected-error {{attribute 'carries_dependency' cannot appear multiple times in an attribute specifier}} [[carries_dependency]] [[carries_dependency]] int m2(); // ok [[carries_dependency()]] int m3(); // expected-error {{attribute 'carries_dependency' cannot have an argument list}} [[carries_dependency]] void f1(); // FIXME: warn here [[carries_dependency]] int f2(); // ok int f3(int param [[carries_dependency]]); // ok [[carries_dependency]] int (*f4)(); // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}} int (*f5 [[carries_dependency]])(); // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}} int (*f6)() [[carries_dependency]]; // expected-error {{'carries_dependency' attribute cannot be applied to types}} int (*f7)(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} int (((f8)))(int n [[carries_dependency]]); // ok int (*f9(int n))(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} int typedef f10(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} using T = int(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} struct S { [[carries_dependency]] int f(int n [[carries_dependency]]); // ok int (*p)(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} }; void f() { [[carries_dependency]] int f(int n [[carries_dependency]]); // ok [[carries_dependency]] // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}} int (*p)(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} } auto l1 = [](int n [[carries_dependency]]) {}; // There's no way to write a lambda such that the return value carries // a dependency, because an attribute applied to the lambda appertains to // the *type* of the operator() function, not to the function itself. auto l2 = []() [[carries_dependency]] {}; // expected-error {{'carries_dependency' attribute cannot be applied to types}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s namespace NIL {} // expected-note {{previous definition}} inline namespace NIL {} // expected-error {{cannot be reopened as inline}} inline namespace IL {} // expected-note {{previous definition}} namespace IL {} // expected-warning{{inline namespace cannot be reopened as a non-inline namespace}} namespace {} // expected-note {{previous definition}} inline namespace {} // expected-error {{cannot be reopened as inline}} namespace X { inline namespace {} // expected-note {{previous definition}} namespace {} // expected-warning {{cannot be reopened as a non-inline namespace}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p8.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s // Fun things you can do with inline namespaces: inline namespace X { void f1(); // expected-note {{'f1' declared here}} inline namespace Y { void f2(); template <typename T> class C {}; } // Specialize and partially specialize somewhere else. template <> class C<int> {}; template <typename T> class C<T*> {}; } // Qualified and unqualified lookup as if member of enclosing NS. void foo1() { f1(); ::f1(); X::f1(); Y::f1(); // expected-error {{no member named 'f1' in namespace 'X::Y'; did you mean simply 'f1'?}} f2(); ::f2(); X::f2(); Y::f2(); } template <> class C<float> {}; template <typename T> class C<T&> {}; template class C<double>; // As well as all the fun with ADL. namespace ADL { struct Outer {}; inline namespace IL { struct Inner {}; void fo(Outer); } void fi(Inner); inline namespace IL2 { void fi2(Inner); } } void foo2() { ADL::Outer o; ADL::Inner i; fo(o); fi(i); fi2(i); } // Let's not forget overload sets. struct Distinct {}; inline namespace Over { void over(Distinct); } void over(int); void foo3() { Distinct d; ::over(d); } // Don't forget to do correct lookup for redeclarations. namespace redecl { inline namespace n1 { template <class Tp> class allocator; template <> class allocator<void> { public: typedef const void* const_pointer; }; template <class Tp> class allocator { public: typedef Tp& reference; void allocate(allocator<void>::const_pointer = 0); }; } } // Normal redeclarations (not for explicit instantiations or // specializations) are distinct in an inline namespace vs. not in an // inline namespace. namespace redecl2 { inline namespace n1 { void f(int) { } struct X1 { }; template<typename T> void f(T) { } template<typename T> struct X2 { }; int i = 71; enum E { e }; } void f(int) { } struct X1 { }; template<typename T> void f(T) { } template<typename T> struct X2 { }; int i = 71; enum E { e }; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // PR8430 namespace N { class A { }; } namespace M { } using namespace M; namespace N { namespace M { } } namespace M { namespace N { } } namespace N { A *getA(); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p1.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -pedantic %s // Intentionally compiled as C++03 to test the extension warning. namespace a {} // original namespace a {} // ext inline namespace b {} // inline original expected-warning {{inline namespaces are}} inline namespace b {} // inline ext expected-warning {{inline namespaces are}} inline namespace {} // inline unnamed expected-warning {{inline namespaces are}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
// RUN: %clang_cc1 -fsyntax-only %s -verify // C++'0x [namespace.memdef] p3: // Every name first declared in a namespace is a member of that namespace. If // a friend declaration in a non-local class first declares a class or // function the friend class or function is a member of the innermost // enclosing namespace. namespace N { struct S0 { friend struct F0; friend void f0(int); struct F0 member_func(); }; struct F0 { }; F0 f0() { return S0().member_func(); } } N::F0 f0_var = N::f0(); // Ensure we can handle attaching friend declarations to an enclosing namespace // with multiple contexts. namespace N { struct S1 { struct IS1; }; } namespace N { struct S1::IS1 { friend struct F1; friend void f1(int); struct F1 member_func(); }; struct F1 { }; F1 f1() { return S1::IS1().member_func(); } } N::F1 f1_var = N::f1(); // The name of the friend is not found by unqualified lookup (3.4.1) or by // qualified lookup (3.4.3) until a matching declaration is provided in that // namespace scope (either before or after the class definition granting // friendship). If a friend function is called, its name may be found by the // name lookup that considers functions from namespaces and classes // associated with the types of the function arguments (3.4.2). If the name // in a friend declaration is neither qualified nor a template-id and the // declaration is a function or an elaborated-type-specifier, the lookup to // determine whether the entity has been previously declared shall not // consider any scopes outside the innermost enclosing namespace. template<typename T> struct X0 { }; struct X1 { }; struct Y { template<typename T> union X0; template<typename T> friend union X0; union X1; friend union X1; }; namespace N { namespace M { template<typename T> class X; } } namespace N3 { class Y { template<typename T> friend class N::M::X; }; } // FIXME: Woefully inadequate for testing // Friends declared as template-ids aren't subject to the restriction // on innermost namespaces. // rdar://problem/8552377 namespace test5 { template <class T> void f(T); namespace ns { class A { friend void f<int>(int); static void foo(); // expected-note 2 {{declared private here}} }; // Note that this happens without instantiation. template <class T> void f(T) { A::foo(); // expected-error {{'foo' is a private member of 'test5::ns::A'}} } } template <class T> void f(T) { ns::A::foo(); // expected-error {{'foo' is a private member of 'test5::ns::A'}} } template void f<int>(int); template void f<long>(long); //expected-note {{instantiation}} } // rdar://13393749 namespace test6 { class A; namespace ns { class B { static void foo(); // expected-note {{implicitly declared private here}} friend union A; }; union A { void test() { B::foo(); } }; } class A { void test() { ns::B::foo(); // expected-error {{'foo' is a private member of 'test6::ns::B'}} } }; } // We seem to be following a correct interpretation with these, but // the standard could probably be a bit clearer. namespace test7a { namespace ns { class A; } using namespace ns; class B { static void foo(); friend class A; }; class ns::A { void test() { B::foo(); } }; } namespace test7b { namespace ns { class A; } using ns::A; class B { static void foo(); friend class A; }; class ns::A { void test() { B::foo(); } }; } namespace test7c { namespace ns1 { class A; } namespace ns2 { // ns1::A appears as if declared in test7c according to [namespace.udir]p2. // I think that means we aren't supposed to find it. using namespace ns1; class B { static void foo(); // expected-note {{implicitly declared private here}} friend class A; }; } class ns1::A { void test() { ns2::B::foo(); // expected-error {{'foo' is a private member of 'test7c::ns2::B'}} } }; } namespace test7d { namespace ns1 { class A; } namespace ns2 { // Honor the lexical context of a using-declaration, though. using ns1::A; class B { static void foo(); friend class A; }; } class ns1::A { void test() { ns2::B::foo(); } }; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.unnamed/p1.cpp
// RUN: %clang_cc1 -emit-llvm-only -verify %s // This lame little test was ripped straight from the standard. namespace { int i; // expected-note {{candidate}} } void test0() { i++; } namespace A { namespace { int i; // expected-note {{candidate}} int j; } void test1() { i++; } } using namespace A; void test2() { i++; // expected-error {{reference to 'i' is ambiguous}} A::i++; j++; } // Test that all anonymous namespaces in a translation unit are // considered the same context. namespace { class Test3 {}; // expected-note {{previous definition}} } namespace { class Test3 {}; // expected-error {{redefinition of 'Test3'}} } namespace test4 { namespace { class Test4 {}; // expected-note {{previous definition}} } namespace { class Test4 {}; // expected-error {{redefinition of 'Test4'}} } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // C++0x N2914. struct A { template<class T> void f(T); template<class T> struct X { }; }; struct B : A { using A::f<double>; // expected-error{{using declaration cannot refer to a template specialization}} using A::X<int>; // expected-error{{using declaration cannot refer to a template specialization}} };
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct Opaque0 {}; struct Opaque1 {}; // Redeclarations are okay in a namespace. namespace test0 { namespace ns { void foo(Opaque0); // expected-note 2 {{candidate function}} } using ns::foo; using ns::foo; void test0() { foo(Opaque1()); // expected-error {{no matching function for call}} } namespace ns { void foo(Opaque1); } void test1() { foo(Opaque1()); // expected-error {{no matching function for call}} } using ns::foo; void test2() { foo(Opaque1()); } using ns::foo; } // Make sure we handle transparent contexts the same way. namespace test1 { namespace ns { void foo(Opaque0); // expected-note 2 {{candidate function}} } extern "C++" { using ns::foo; } void test0() { foo(Opaque1()); // expected-error {{no matching function for call}} } namespace ns { void foo(Opaque1); } void test1() { foo(Opaque1()); // expected-error {{no matching function for call}} } extern "C++" { using ns::foo; } void test2() { foo(Opaque1()); } } // Make sure we detect invalid redeclarations that can't be detected // until template instantiation. namespace test2 { template <class T> struct Base { typedef Base type; void foo(); }; template <class T> struct Derived : Base<T> { // These are invalid redeclarations, detectable only after // instantiation. using Base<T>::foo; // expected-note {{previous using decl}} using Base<T>::type::foo; //expected-error {{redeclaration of using decl}} }; template struct Derived<int>; // expected-note {{in instantiation of template class}} } // Redeclarations are okay in a function. namespace test3 { namespace N { int f(int); typedef int type; } void g() { using N::f; using N::f; using N::type; using N::type; } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics namespace test0 { namespace ns0 { class tag; int tag(); } namespace ns1 { using ns0::tag; } namespace ns2 { using ns0::tag; } using ns1::tag; using ns2::tag; } // PR 5752 namespace test1 { namespace ns { void foo(); } using ns::foo; void foo(int); namespace ns { using test1::foo; } } // PR 14768 namespace PR14768 { template<typename eT> class Mat; template<typename eT> class Col : public Mat<eT> { using Mat<eT>::operator(); using Col<eT>::operator(); void operator() (); }; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // C++03 [namespace.udecl]p4: // A using-declaration used as a member-declaration shall refer to a // member of a base class of the class being defined, shall refer to // a member of an anonymous union that is a member of a base class // of the class being defined, or shall refer to an enumerator for // an enumeration type that is a member of a base class of the class // being defined. // There is no directly analogous paragraph in C++0x, and the feature // works sufficiently differently there that it needs a separate test. namespace test0 { namespace NonClass { typedef int type; struct hiding {}; int hiding; static union { double union_member; }; enum tagname { enumerator }; } class Test0 { using NonClass::type; // expected-error {{not a class}} using NonClass::hiding; // expected-error {{not a class}} using NonClass::union_member; // expected-error {{not a class}} using NonClass::enumerator; // expected-error {{not a class}} }; } struct Opaque0 {}; namespace test1 { struct A { typedef int type; struct hiding {}; // expected-note {{previous use is here}} Opaque0 hiding; union { double union_member; }; enum tagname { enumerator }; }; struct B : A { using A::type; using A::hiding; using A::union_member; using A::enumerator; using A::tagname; void test0() { type t = 0; } void test1() { typedef struct A::hiding local; struct hiding _ = local(); } void test2() { union hiding _; // expected-error {{tag type that does not match previous}} } void test3() { char array[sizeof(union_member) == sizeof(double) ? 1 : -1]; } void test4() { enum tagname _ = enumerator; } void test5() { Opaque0 _ = hiding; } }; } namespace test2 { struct A { typedef int type; struct hiding {}; // expected-note {{previous use is here}} int hiding; union { double union_member; }; enum tagname { enumerator }; }; template <class T> struct B : A { using A::type; using A::hiding; using A::union_member; using A::enumerator; using A::tagname; void test0() { type t = 0; } void test1() { typedef struct A::hiding local; struct hiding _ = local(); } void test2() { union hiding _; // expected-error {{tag type that does not match previous}} } void test3() { char array[sizeof(union_member) == sizeof(double) ? 1 : -1]; } void test4() { enum tagname _ = enumerator; } void test5() { Opaque0 _ = hiding; } }; } namespace test3 { struct hiding {}; template <class T> struct A { typedef int type; // expected-note {{target of using declaration}} struct hiding {}; Opaque0 hiding; // expected-note {{target of using declaration}} union { double union_member; }; // expected-note {{target of using declaration}} enum tagname { enumerator }; // expected-note 2 {{target of using declaration}} }; template <class T> struct B : A<T> { using A<T>::type; // expected-error {{dependent using declaration resolved to type without 'typename'}} using A<T>::hiding; using A<T>::union_member; using A<T>::enumerator; using A<T>::tagname; // expected-error {{dependent using declaration resolved to type without 'typename'}} // FIXME: re-enable these when the various bugs involving tags are fixed #if 0 void test1() { typedef struct A<T>::hiding local; struct hiding _ = local(); } void test2() { typedef struct A<T>::hiding local; union hiding _ = local(); } #endif void test3() { char array[sizeof(union_member) == sizeof(double) ? 1 : -1]; } #if 0 void test4() { enum tagname _ = enumerator; } #endif void test5() { Opaque0 _ = hiding; } }; template struct B<int>; // expected-note {{in instantiation}} template <class T> struct C : A<T> { using typename A<T>::type; using typename A<T>::hiding; // expected-note {{declared here}} \ // expected-error {{'typename' keyword used on a non-type}} using typename A<T>::union_member; // expected-error {{'typename' keyword used on a non-type}} using typename A<T>::enumerator; // expected-error {{'typename' keyword used on a non-type}} void test6() { type t = 0; } void test7() { Opaque0 _ = hiding; // expected-error {{does not refer to a value}} } }; template struct C<int>; // expected-note {{in instantiation}} } namespace test4 { struct Base { int foo(); }; struct Unrelated { int foo(); }; struct Subclass : Base { }; namespace InnerNS { int foo(); } // We should be able to diagnose these without instantiation. template <class T> struct C : Base { using InnerNS::foo; // expected-error {{not a class}} using Base::bar; // expected-error {{no member named 'bar'}} using Unrelated::foo; // expected-error {{not a base class}} using C::foo; // legal in C++03 using Subclass::foo; // legal in C++03 int bar(); //expected-note {{target of using declaration}} using C::bar; // expected-error {{refers to its own class}} }; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p13.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // C++03 [namespace.udecl]p3: // For the purpose of overload resolution, the functions which are // introduced by a using-declaration into a derived class will be // treated as though they were members of the derived class. In // particular, the implicit this parameter shall be treated as if it // were a pointer to the derived class rather than to the base // class. This has no effect on the type of the function, and in all // other respects the function remains a member of the base class. namespace test0 { struct Opaque0 {}; struct Opaque1 {}; struct Base { Opaque0 test0(int*); Opaque0 test1(const int*); Opaque0 test2(int*); Opaque0 test3(int*) const; }; struct Derived : Base { using Base::test0; Opaque1 test0(const int*); using Base::test1; Opaque1 test1(int*); using Base::test2; Opaque1 test2(int*) const; using Base::test3; Opaque1 test3(int*); }; void test0() { Opaque0 a = Derived().test0((int*) 0); Opaque1 b = Derived().test0((const int*) 0); } void test1() { Opaque1 a = Derived().test1((int*) 0); Opaque0 b = Derived().test1((const int*) 0); } void test2() { Opaque0 a = ((Derived*) 0)->test2((int*) 0); Opaque1 b = ((const Derived*) 0)->test2((int*) 0); } void test3() { Opaque1 a = ((Derived*) 0)->test3((int*) 0); Opaque0 b = ((const Derived*) 0)->test3((int*) 0); } } // Typedef redeclaration. namespace rdar8018262 { typedef void (*fp)(); namespace N { typedef void (*fp)(); } using N::fp; fp fp_1; } // Things to test: // member operators // conversion operators // call operators // call-surrogate conversion operators // everything, but in dependent contexts
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3-cxx0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // C++0x N2914. struct B { void f(char); void g(char); enum E { e }; union { int x; }; }; class C { int g(); }; class D2 : public B { using B::f; using B::e; using B::x; using C::g; // expected-error{{using declaration refers into 'C::', which is not a base class of 'D2'}} }; namespace test1 { struct Base { int foo(); }; struct Unrelated { int foo(); }; struct Subclass : Base { }; namespace InnerNS { int foo(); } // We should be able to diagnose these without instantiation. template <class T> struct C : Base { using InnerNS::foo; // expected-error {{not a class}} using Base::bar; // expected-error {{no member named 'bar'}} using Unrelated::foo; // expected-error {{not a base class}} using C::foo; // expected-error {{refers to its own class}} using Subclass::foo; // expected-error {{not a base class}} }; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p1.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // We have to avoid ADL for this test. template <unsigned N> class test {}; class foo {}; // expected-note {{candidate}} test<0> foo(foo); // expected-note {{candidate}} namespace Test0 { class foo { int x; }; test<1> foo(class foo); namespace A { test<2> foo(class ::foo); // expected-note {{candidate}} \ // expected-note{{passing argument to parameter here}} void test0() { using ::foo; class foo a; test<0> _ = (foo)(a); } void test1() { using Test0::foo; class foo a; test<1> _ = (foo)(a); }; void test2() { class ::foo a; // Argument-dependent lookup is ambiguous between B:: and ::. test<0> _0 = foo(a); // expected-error {{call to 'foo' is ambiguous}} // But basic unqualified lookup is not. test<2> _1 = (foo)(a); class Test0::foo b; test<2> _2 = (foo)(b); // expected-error {{no viable conversion from 'class Test0::foo' to 'class ::foo'}} } } } namespace Test1 { namespace A { class a {}; } namespace B { typedef class {} b; } namespace C { int c(); // expected-note {{target of using declaration}} } namespace D { using typename A::a; using typename B::b; using typename C::c; // expected-error {{'typename' keyword used on a non-type}} a _1 = A::a(); b _2 = B::b(); } } namespace test2 { class A { protected: operator int(); operator bool(); }; class B : private A { protected: using A::operator int; // expected-note {{declared protected here}} public: using A::operator bool; }; int test() { bool b = B(); return B(); // expected-error {{'operator int' is a protected member of 'test2::B'}} } } namespace test3 { class A { public: ~A(); }; class B { friend class C; private: operator A*(); }; class C : public B { public: using B::operator A*; }; void test() { delete C(); } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p12.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // C++03 [namespace.udecl]p12: // When a using-declaration brings names from a base class into a // derived class scope, member functions in the derived class // override and/or hide member functions with the same name and // parameter types in a base class (rather than conflicting). template <unsigned n> struct Opaque {}; template <unsigned n> void expect(Opaque<n> _) {} // PR5727 // This just shouldn't crash. namespace test0 { template<typename> struct RefPtr { }; template<typename> struct PtrHash { static void f() { } }; template<typename T> struct PtrHash<RefPtr<T> > : PtrHash<T*> { using PtrHash<T*>::f; static void f() { f(); } }; } // Simple hiding. namespace test1 { struct Base { Opaque<0> foo(Opaque<0>); Opaque<0> foo(Opaque<1>); Opaque<0> foo(Opaque<2>); }; // using before decls struct Test0 : Base { using Base::foo; Opaque<1> foo(Opaque<1>); Opaque<1> foo(Opaque<3>); void test0() { Opaque<0> _ = foo(Opaque<0>()); } void test1() { Opaque<1> _ = foo(Opaque<1>()); } void test2() { Opaque<0> _ = foo(Opaque<2>()); } void test3() { Opaque<1> _ = foo(Opaque<3>()); } }; // using after decls struct Test1 : Base { Opaque<1> foo(Opaque<1>); Opaque<1> foo(Opaque<3>); using Base::foo; void test0() { Opaque<0> _ = foo(Opaque<0>()); } void test1() { Opaque<1> _ = foo(Opaque<1>()); } void test2() { Opaque<0> _ = foo(Opaque<2>()); } void test3() { Opaque<1> _ = foo(Opaque<3>()); } }; // using between decls struct Test2 : Base { Opaque<1> foo(Opaque<0>); using Base::foo; Opaque<1> foo(Opaque<2>); Opaque<1> foo(Opaque<3>); void test0() { Opaque<1> _ = foo(Opaque<0>()); } void test1() { Opaque<0> _ = foo(Opaque<1>()); } void test2() { Opaque<1> _ = foo(Opaque<2>()); } void test3() { Opaque<1> _ = foo(Opaque<3>()); } }; } // Crazy dependent hiding. namespace test2 { struct Base { void foo(int); }; template <typename T> struct Derived1 : Base { using Base::foo; void foo(T); void testUnresolved(int i) { foo(i); } }; void test0(int i) { Derived1<int> d1; d1.foo(i); d1.testUnresolved(i); } // Same thing, except with the order of members reversed. template <typename T> struct Derived2 : Base { void foo(T); using Base::foo; void testUnresolved(int i) { foo(i); } }; void test1(int i) { Derived2<int> d2; d2.foo(i); d2.testUnresolved(i); } } // Hiding of member templates. namespace test3 { struct Base { template <class T> Opaque<0> foo() { return Opaque<0>(); } template <int n> Opaque<1> foo() { return Opaque<1>(); } }; struct Derived1 : Base { using Base::foo; template <int n> Opaque<2> foo() { return Opaque<2>(); } // expected-note {{invalid explicitly-specified argument for template parameter 'n'}} }; struct Derived2 : Base { template <int n> Opaque<2> foo() { return Opaque<2>(); } // expected-note {{invalid explicitly-specified argument for template parameter 'n'}} using Base::foo; }; struct Derived3 : Base { using Base::foo; template <class T> Opaque<3> foo() { return Opaque<3>(); } // expected-note {{invalid explicitly-specified argument for template parameter 'T'}} }; struct Derived4 : Base { template <class T> Opaque<3> foo() { return Opaque<3>(); } // expected-note {{invalid explicitly-specified argument for template parameter 'T'}} using Base::foo; }; void test() { expect<0>(Base().foo<int>()); expect<1>(Base().foo<0>()); expect<0>(Derived1().foo<int>()); // expected-error {{no matching member function for call to 'foo'}} expect<2>(Derived1().foo<0>()); expect<0>(Derived2().foo<int>()); // expected-error {{no matching member function for call to 'foo'}} expect<2>(Derived2().foo<0>()); expect<3>(Derived3().foo<int>()); expect<1>(Derived3().foo<0>()); // expected-error {{no matching member function for call to 'foo'}} expect<3>(Derived4().foo<int>()); expect<1>(Derived4().foo<0>()); // expected-error {{no matching member function for call to 'foo'}} } } // PR7384: access control for member templates. namespace test4 { class Base { protected: template<typename T> void foo(T); template<typename T> void bar(T); // expected-note {{declared protected here}} }; struct Derived : Base { using Base::foo; }; void test() { Derived d; d.foo<int>(3); d.bar<int>(3); // expected-error {{'bar' is a protected member}} } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s // RUN: not %clang_cc1 -fsyntax-only -std=c++98 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck --check-prefix=CXX98 %s // RUN: not %clang_cc1 -fsyntax-only -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck --check-prefix=CXX11 %s // C++0x N2914. struct X { int i; static int a; }; using X::i; // expected-error{{using declaration cannot refer to class member}} using X::s; // expected-error{{using declaration cannot refer to class member}} void f() { using X::i; // expected-error{{using declaration cannot refer to class member}} using X::s; // expected-error{{using declaration cannot refer to class member}} } template <typename T> struct PR21933 : T { static void StaticFun() { using T::member; } // expected-error{{using declaration cannot refer to class member}} }; struct S { static int n; struct Q {}; enum E {}; typedef Q T; void f(); static void g(); }; using S::n; // expected-error{{class member}} expected-note {{use a reference instead}} #if __cplusplus < 201103L // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-2]] #else // CXX11: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:6}:"auto &n = " #endif using S::Q; // expected-error{{class member}} #if __cplusplus < 201103L // expected-note@-2 {{use a typedef declaration instead}} // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef" // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" Q" #else // expected-note@-6 {{use an alias declaration instead}} // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"Q = " #endif using S::E; // expected-error{{class member}} #if __cplusplus < 201103L // expected-note@-2 {{use a typedef declaration instead}} // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef" // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" E" #else // expected-note@-6 {{use an alias declaration instead}} // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"E = " #endif using S::T; // expected-error{{class member}} #if __cplusplus < 201103L // expected-note@-2 {{use a typedef declaration instead}} // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef" // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" T" #else // expected-note@-6 {{use an alias declaration instead}} // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"T = " #endif using S::f; // expected-error{{class member}} using S::g; // expected-error{{class member}} void h() { using S::n; // expected-error{{class member}} expected-note {{use a reference instead}} #if __cplusplus < 201103L // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-2]] #else // CXX11: fix-it:"{{.*}}":{[[@LINE-4]]:3-[[@LINE-4]]:8}:"auto &n = " #endif using S::Q; // expected-error{{class member}} #if __cplusplus < 201103L // expected-note@-2 {{use a typedef declaration instead}} // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef" // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" Q" #else // expected-note@-6 {{use an alias declaration instead}} // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"Q = " #endif using S::E; // expected-error{{class member}} #if __cplusplus < 201103L // expected-note@-2 {{use a typedef declaration instead}} // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef" // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" E" #else // expected-note@-6 {{use an alias declaration instead}} // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"E = " #endif using S::T; // expected-error{{class member}} #if __cplusplus < 201103L // expected-note@-2 {{use a typedef declaration instead}} // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef" // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" T" #else // expected-note@-6 {{use an alias declaration instead}} // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"T = " #endif using S::f; // expected-error{{class member}} using S::g; // expected-error{{class member}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p11.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // C++03 [namespace.udecl]p11: (per DR101) // If a function declaration in namespace scope or block scope has // the same name and the same parameter types as a function // introduced by a using-declaration, and the declarations do not declare the // same function, the program is ill-formed. [Note: two using-declarations may // introduce functions with the same name and the same parameter types. If, // for a call to an unqualified function name, function overload resolution // selects the functions introduced by such using-declarations, the function // call is ill-formed.] // // FIXME: DR565 introduces parallel wording here for function templates. namespace test0 { namespace ns { void foo(); } // expected-note {{target of using declaration}} int foo(void); // expected-note {{conflicting declaration}} using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} } namespace test1 { namespace ns { void foo(); } // expected-note {{target of using declaration}} using ns::foo; //expected-note {{using declaration}} int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} } namespace test2 { namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} void test0() { int foo(void); // expected-note {{conflicting declaration}} using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} } void test1() { using ns::foo; //expected-note {{using declaration}} int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} } } namespace test3 { namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} class Test0 { void test() { int foo(void); // expected-note {{conflicting declaration}} using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} } }; class Test1 { void test() { using ns::foo; //expected-note {{using declaration}} int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} } }; } namespace test4 { namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} template <typename> class Test0 { void test() { int foo(void); // expected-note {{conflicting declaration}} using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} } }; template <typename> class Test1 { void test() { using ns::foo; //expected-note {{using declaration}} int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} } }; } // FIXME: we should be able to diagnose both of these, but we can't. namespace test5 { namespace ns { void foo(int); } template <typename T> class Test0 { void test() { int foo(T); using ns::foo; } }; template <typename T> class Test1 { void test() { using ns::foo; int foo(T); } }; template class Test0<int>; template class Test1<int>; } namespace test6 { namespace ns { void foo(); } // expected-note {{target of using declaration}} using ns::foo; // expected-note {{using declaration}} namespace ns { using test6::foo; void foo() {} } void foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}} } namespace test7 { void foo(); using test7::foo; void foo() {} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // C++0x N2914. namespace A { namespace B { } } using A::B; // expected-error{{using declaration cannot refer to namespace}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p1.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // (this actually occurs before paragraph 1) namespace test0 { namespace A {} class B { using namespace A; // expected-error {{'using namespace' is not allowed in classes}} }; } struct opaque0 {}; struct opaque1 {}; // Test that names appear as if in deepest common ancestor. namespace test1 { namespace A { namespace B { opaque0 foo(); // expected-note {{candidate}} } } namespace C { opaque1 foo(); // expected-note {{candidate}} opaque1 test() { using namespace A::B; return foo(); // C::foo } } opaque1 test() { using namespace A::B; using namespace C; return foo(); // expected-error {{call to 'foo' is ambiguous}} } } // Same thing, but with the directives in namespaces. namespace test2 { namespace A { namespace B { opaque0 foo(); // expected-note {{candidate}} } } namespace C { opaque1 foo(); // expected-note {{candidate}} namespace test { using namespace A::B; opaque1 test() { return foo(); // C::foo } } } namespace test { using namespace A::B; using namespace C; opaque1 test() { return foo(); // expected-error {{call to 'foo' is ambiguous}} } } } // Transitivity. namespace test3 { namespace A { namespace B { opaque0 foo(); } } namespace C { using namespace A; } opaque0 test0() { using namespace C; using namespace B; return foo(); } namespace D { using namespace C; } namespace A { opaque1 foo(); } opaque1 test1() { using namespace D; return foo(); } } // Transitivity acts like synthetic using directives. namespace test4 { namespace A { namespace B { opaque0 foo(); // expected-note {{candidate}} } } namespace C { using namespace A::B; } opaque1 foo(); // expected-note {{candidate}} namespace A { namespace D { using namespace C; } opaque0 test() { using namespace D; return foo(); } } opaque0 test() { using namespace A::D; return foo(); // expected-error {{call to 'foo' is ambiguous}} } } // Bug: using directives should be followed when parsing default // arguments in scoped declarations. class test5 { int inc(int x); }; namespace Test5 { int default_x = 0; } using namespace Test5; int test5::inc(int x = default_x) { return x+1; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // <rdar://problem/8296180> typedef int pid_t; namespace ns { typedef int pid_t; } using namespace ns; pid_t x; struct A { }; namespace ns { typedef ::A A; } A a;
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.enum/p2.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s // expected-no-diagnostics enum class E : int const volatile { }; using T = __underlying_type(E); using T = int;
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.enum/p5.cpp
// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s template<typename T> int force_same(T, T); // C++ [dcl.enum]p5: // [...] If the underlying type is not fixed, the type of each enumerator is // the type of its initializing value: // - If an initializer is specified for an enumerator, the initializing // value has the same type as the expression. enum Bullet1 { Bullet1Val1 = 'a', Bullet1Val2 = 10u, Bullet1Val1IsChar = sizeof(force_same(Bullet1Val1, char(0))), Bullet1Val2IsUnsigned = sizeof(force_same(Bullet1Val2, unsigned(0))) }; // - If no initializer is specified for the first enumerator, the // initializing value has an unspecified integral type. enum Bullet2 { Bullet2Val, Bullet2ValIsInt = sizeof(force_same(Bullet2Val, int(0))) }; // - Otherwise the type of the initializing value is the same as the type // of the initializing value of the preceding enumerator unless the // incremented value is not representable in that type, in which case the // type is an unspecified integral type sufficient to contain the // incremented value. If no such type exists, the program is ill-formed. enum Bullet3a { Bullet3aVal1 = 17, Bullet3aVal2, Bullet3aVal2IsInt = sizeof(force_same(Bullet3aVal2, int(0))), Bullet3aVal3 = 2147483647, Bullet3aVal3IsInt = sizeof(force_same(Bullet3aVal3, int(0))), Bullet3aVal4, Bullet3aVal4IsUnsigned = sizeof(force_same(Bullet3aVal4, 0ul)) }; enum Bullet3b { Bullet3bVal1 = 17u, Bullet3bVal2, Bullet3bVal2IsInt = sizeof(force_same(Bullet3bVal2, 0u)), Bullet3bVal3 = 2147483647u, Bullet3bVal3IsInt = sizeof(force_same(Bullet3bVal3, 0u)), Bullet3bVal4, Bullet3bVal4IsUnsigned = sizeof(force_same(Bullet3bVal4, 0ul)) }; enum Bullet3c { Bullet3cVal1 = 0xFFFFFFFFFFFFFFFEull, Bullet3cVal2, Bullet3cVal3 // expected-warning{{not representable}} }; // Following the closing brace of an enum-specifier, each enumerator has the // type of its enumeration. int array0[sizeof(force_same(Bullet3bVal3, Bullet3b(0)))? 1 : -1];
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s void f0() { // expected-note {{previous definition is here}} } inline void f0(); // expected-error {{inline declaration of 'f0' follows non-inline definition}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p3.cpp
// RUN: %clang_cc1 -verify %s void f0a(void) { inline void f1(); // expected-error {{inline declaration of 'f1' not allowed in block scope}} } void f0b(void) { void f1(); } // FIXME: Add test for "If the inline specifier is used in a friend declaration, // that declaration shall be a definition or the function shall have previously // been declared inline.
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp
// RUN: %clang_cc1 -verify %s class A { public: explicit A(); explicit operator int(); // expected-warning {{explicit conversion functions are a C++11 extension}} explicit void f0(); // expected-error {{'explicit' can only be applied to a constructor or conversion function}} operator bool(); }; explicit A::A() { } // expected-error {{'explicit' can only be specified inside the class definition}} explicit A::operator bool() { return false; } // expected-warning {{explicit conversion functions are a C++11 extension}}\ // expected-error {{'explicit' can only be specified inside the class definition}} class B { friend explicit A::A(); // expected-error {{'explicit' is invalid in friend declarations}} };
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s // A constexpr specifier used in an object declaration declares the object as // const. constexpr int a = 0; extern const int a; int i; // expected-note 2{{here}} constexpr int *b = &i; extern int *const b; constexpr int &c = i; extern int &c; constexpr int (*d)(int) = 0; extern int (*const d)(int); // A variable declaration which uses the constexpr specifier shall have an // initializer and shall be initialized by a constant expression. constexpr int ni1; // expected-error {{default initialization of an object of const type 'const int'}} constexpr struct C { C(); } ni2; // expected-error {{cannot have non-literal type 'const struct C'}} expected-note 3{{has no constexpr constructors}} constexpr double &ni3; // expected-error {{declaration of reference variable 'ni3' requires an initializer}} constexpr int nc1 = i; // expected-error {{constexpr variable 'nc1' must be initialized by a constant expression}} expected-note {{read of non-const variable 'i' is not allowed in a constant expression}} constexpr C nc2 = C(); // expected-error {{cannot have non-literal type 'const C'}} int &f(); // expected-note {{declared here}} constexpr int &nc3 = f(); // expected-error {{constexpr variable 'nc3' must be initialized by a constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}} constexpr int nc4(i); // expected-error {{constexpr variable 'nc4' must be initialized by a constant expression}} expected-note {{read of non-const variable 'i' is not allowed in a constant expression}} constexpr C nc5((C())); // expected-error {{cannot have non-literal type 'const C'}} int &f(); // expected-note {{here}} constexpr int &nc6(f()); // expected-error {{constexpr variable 'nc6' must be initialized by a constant expression}} expected-note {{non-constexpr function 'f'}} struct pixel { int x, y; }; constexpr pixel ur = { 1294, 1024 }; // ok constexpr pixel origin; // expected-error {{default initialization of an object of const type 'const pixel' without a user-provided default constructor}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p8.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s using size_t = decltype(sizeof(int)); struct S { constexpr int f(); // expected-warning {{C++14}} constexpr int g() const; constexpr int h(); // expected-warning {{C++14}} int h(); static constexpr int Sf(); /*static*/ constexpr void *operator new(size_t) noexcept; template<typename T> constexpr T tm(); // expected-warning {{C++14}} template<typename T> static constexpr T ts(); }; void f(const S &s) { s.f(); s.g(); int (*Sf)() = &S::Sf; int (S::*f)() const = &S::f; int (S::*g)() const = &S::g; void *(*opNew)(size_t) = &S::operator new; int (S::*tm)() const = &S::tm; int (*ts)() = &S::ts; } constexpr int S::f() const { return 0; } constexpr int S::g() { return 1; } // expected-warning {{C++14}} constexpr int S::h() { return 0; } // expected-warning {{C++14}} int S::h() { return 0; } constexpr int S::Sf() { return 2; } constexpr void *S::operator new(size_t) noexcept { return 0; } template<typename T> constexpr T S::tm() { return T(); } // expected-warning {{C++14}} template<typename T> constexpr T S::ts() { return T(); } namespace std_example { class debug_flag { public: explicit debug_flag(bool); constexpr bool is_on() const; // ok (dr1684) private: bool flag; }; constexpr int bar(int x, int y) // expected-note {{here}} { return x + y + x*y; } int bar(int x, int y) // expected-error {{non-constexpr declaration of 'bar' follows constexpr declaration}} { return x * 2 + 3 * y; } } // The constexpr specifier is allowed for static member functions of non-literal types. class NonLiteralClass { NonLiteralClass(bool); static constexpr bool isDebugFlag(); };
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
// RUN: %clang_cc1 -verify -std=c++11 -fcxx-exceptions -Werror=c++1y-extensions %s // RUN: %clang_cc1 -verify -std=c++1y -fcxx-exceptions -DCXX1Y %s namespace N { typedef char C; } namespace M { typedef double D; } struct NonLiteral { // expected-note 2{{no constexpr constructors}} NonLiteral() {} NonLiteral(int) {} }; struct Literal { constexpr Literal() {} explicit Literal(int); // expected-note 2 {{here}} operator int() const { return 0; } }; // In the definition of a constexpr constructor, each of the parameter types // shall be a literal type. struct S { constexpr S(int, N::C) {} constexpr S(int, NonLiteral, N::C) {} // expected-error {{constexpr constructor's 2nd parameter type 'NonLiteral' is not a literal type}} constexpr S(int, NonLiteral = 42) {} // expected-error {{constexpr constructor's 2nd parameter type 'NonLiteral' is not a literal type}} // In addition, either its function-body shall be = delete or = default constexpr S() = default; constexpr S(Literal) = delete; }; // or it shall satisfy the following constraints: // - the class shall not have any virtual base classes; struct T : virtual S { // expected-note {{here}} constexpr T() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}} }; namespace IndirectVBase { struct A {}; struct B : virtual A {}; // expected-note {{here}} class C : public B { public: constexpr C() {} // expected-error {{constexpr constructor not allowed in class with virtual base class}} }; } // - its function-body shall not be a function-try-block; struct U { constexpr U() try // expected-error {{function try block not allowed in constexpr constructor}} : u() { } catch (...) { throw; } int u; }; // - the compound-statememt of its function-body shall contain only struct V { constexpr V() { // - null statements, ; // - static_assert-declarations, static_assert(true, "the impossible happened!"); // - typedef declarations and alias-declarations that do not define classes // or enumerations, typedef int I; typedef struct S T; using J = int; using K = int[sizeof(I) + sizeof(J)]; // Note, the standard requires we reject this. struct U; // - using-declarations, using N::C; // - and using-directives; using namespace N; } constexpr V(int(&)[1]) { for (int n = 0; n < 10; ++n) /**/; #ifndef CXX1Y // expected-error@-3 {{statement not allowed in constexpr constructor}} #endif } constexpr V(int(&)[2]) { constexpr int a = 0; #ifndef CXX1Y // expected-error@-2 {{variable declaration in a constexpr constructor is a C++14 extension}} #endif } constexpr V(int(&)[3]) { constexpr int ForwardDecl(int); #ifndef CXX1Y // expected-error@-2 {{use of this statement in a constexpr constructor is a C++14 extension}} #endif } constexpr V(int(&)[4]) { typedef struct { } S1; #ifndef CXX1Y // expected-error@-2 {{type definition in a constexpr constructor is a C++14 extension}} #endif } constexpr V(int(&)[5]) { using S2 = struct { }; #ifndef CXX1Y // expected-error@-2 {{type definition in a constexpr constructor is a C++14 extension}} #endif } constexpr V(int(&)[6]) { struct S3 { }; #ifndef CXX1Y // expected-error@-2 {{type definition in a constexpr constructor is a C++14 extension}} #endif } constexpr V(int(&)[7]) { return; #ifndef CXX1Y // expected-error@-2 {{use of this statement in a constexpr constructor is a C++14 extension}} #endif } }; // - every non-static data member and base class sub-object shall be initialized struct W { int n; // expected-note {{member not initialized by constructor}} constexpr W() {} // expected-error {{constexpr constructor must initialize all members}} }; struct AnonMembers { int a; // expected-note {{member not initialized by constructor}} union { // expected-note 2{{member not initialized by constructor}} char b; struct { double c; long d; // expected-note {{member not initialized by constructor}} }; union { char e; void *f; }; }; struct { // expected-note {{member not initialized by constructor}} long long g; struct { int h; // expected-note {{member not initialized by constructor}} double i; // expected-note {{member not initialized by constructor}} }; union { // expected-note 2{{member not initialized by constructor}} char *j; AnonMembers *k; }; }; constexpr AnonMembers(int(&)[1]) : a(), b(), g(), h(), i(), j() {} // ok // missing d, i, j/k union constexpr AnonMembers(int(&)[2]) : a(), c(), g(), h() {} // expected-error {{constexpr constructor must initialize all members}} constexpr AnonMembers(int(&)[3]) : a(), e(), g(), h(), i(), k() {} // ok // missing h, j/k union constexpr AnonMembers(int(&)[4]) : a(), c(), d(), g(), i() {} // expected-error {{constexpr constructor must initialize all members}} // missing b/c/d/e/f union constexpr AnonMembers(int(&)[5]) : a(), g(), h(), i(), k() {} // expected-error {{constexpr constructor must initialize all members}} // missing a, b/c/d/e/f union, g/h/i/j/k struct constexpr AnonMembers(int(&)[6]) {} // expected-error {{constexpr constructor must initialize all members}} }; union Empty { constexpr Empty() {} // ok } constexpr empty1; struct EmptyVariant { union {}; struct {}; constexpr EmptyVariant() {} // ok } constexpr empty2; template<typename T> using Int = int; template<typename T> struct TemplateInit { T a; int b; // desired-note {{not initialized}} Int<T> c; // desired-note {{not initialized}} struct { T d; int e; // desired-note {{not initialized}} Int<T> f; // desired-note {{not initialized}} }; struct { Literal l; Literal m; Literal n[3]; }; union { // desired-note {{not initialized}} T g; T h; }; // FIXME: This is ill-formed (no diagnostic required). We should diagnose it. constexpr TemplateInit() {} // desired-error {{must initialize all members}} }; template<typename T> struct TemplateInit2 { Literal l; constexpr TemplateInit2() {} // ok }; template<typename T> struct weak_ptr { constexpr weak_ptr() : p(0) {} T *p; }; template<typename T> struct enable_shared_from_this { weak_ptr<T> weak_this; constexpr enable_shared_from_this() {} // ok }; constexpr int f(enable_shared_from_this<int>); // - every constructor involved in initializing non-static data members and base // class sub-objects shall be a constexpr constructor. struct ConstexprBaseMemberCtors : Literal { Literal l; constexpr ConstexprBaseMemberCtors() : Literal(), l() {} // ok constexpr ConstexprBaseMemberCtors(char) : // expected-error {{constexpr constructor never produces a constant expression}} Literal(0), // expected-note {{non-constexpr constructor}} l() {} constexpr ConstexprBaseMemberCtors(double) : Literal(), // expected-error {{constexpr constructor never produces a constant expression}} l(0) // expected-note {{non-constexpr constructor}} {} }; // - every assignment-expression that is an initializer-clause appearing // directly or indirectly within a brace-or-equal-initializer for a non-static // data member that is not named by a mem-initializer-id shall be a constant // expression; and // // Note, we deliberately do not implement this bullet, so that we can allow the // following example. (See N3308). struct X { int a = 0; int b = 2 * a + 1; // ok, not a constant expression. constexpr X() {} constexpr X(int c) : a(c) {} // ok, b initialized by 2 * c + 1 }; union XU1 { int a; constexpr XU1() = default; }; // expected-error{{not constexpr}} union XU2 { int a = 1; constexpr XU2() = default; }; struct XU3 { union { int a; }; constexpr XU3() = default; // expected-error{{not constexpr}} }; struct XU4 { union { int a = 1; }; constexpr XU4() = default; }; static_assert(XU2().a == 1, ""); static_assert(XU4().a == 1, ""); // - every implicit conversion used in converting a constructor argument to the // corresponding parameter type and converting a full-expression to the // corresponding member type shall be one of those allowed in a constant // expression. // // We implement the proposed resolution of DR1364 and ignore this bullet. // However, we implement the intent of this wording as part of the p5 check that // the function must be able to produce a constant expression. int kGlobal; // expected-note {{here}} struct Z { constexpr Z(int a) : n(a) {} constexpr Z() : n(kGlobal) {} // expected-error {{constexpr constructor never produces a constant expression}} expected-note {{read of non-const}} int n; }; namespace StdExample { struct Length { explicit constexpr Length(int i = 0) : val(i) { } private: int val; }; } namespace CtorLookup { // Ensure that we look up which constructor will actually be used. struct A { constexpr A(const A&) {} A(A&) {} constexpr A(int = 0); }; struct B : A { B() = default; constexpr B(const B&); constexpr B(B&); }; constexpr B::B(const B&) = default; constexpr B::B(B&) = default; // expected-error {{not constexpr}} struct C { A a; C() = default; constexpr C(const C&); constexpr C(C&); }; constexpr C::C(const C&) = default; constexpr C::C(C&) = default; // expected-error {{not constexpr}} } namespace PR14503 { template<typename> struct V { union { int n; struct { int x, y; }; }; constexpr V() : x(0) {} }; // The constructor is still 'constexpr' here, but the result is not intended // to be a constant expression. The standard is not clear on how this should // work. constexpr V<int> v; // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}} constexpr int k = V<int>().x; // FIXME: ok? }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++11 -Werror=c++1y-extensions %s // RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++1y -DCXX1Y %s namespace N { typedef char C; } namespace M { typedef double D; } struct NonLiteral { // expected-note 3{{no constexpr constructors}} NonLiteral() {} NonLiteral(int) {} }; struct Literal { constexpr Literal() {} operator int() const { return 0; } }; struct S { virtual int ImplicitlyVirtual() const = 0; // expected-note {{overridden virtual function}} }; struct SS : S { int ImplicitlyVirtual() const; }; // The definition of a constexpr function shall satisfy the following // constraints: struct T : SS, NonLiteral { constexpr T(); constexpr int f() const; // - it shall not be virtual; virtual constexpr int ExplicitlyVirtual() const { return 0; } // expected-error {{virtual function cannot be constexpr}} constexpr int ImplicitlyVirtual() const { return 0; } // expected-error {{virtual function cannot be constexpr}} virtual constexpr int OutOfLineVirtual() const; // expected-error {{virtual function cannot be constexpr}} // - its return type shall be a literal type; constexpr NonLiteral NonLiteralReturn() const { return {}; } // expected-error {{constexpr function's return type 'NonLiteral' is not a literal type}} constexpr void VoidReturn() const { return; } #ifndef CXX1Y // expected-error@-2 {{constexpr function's return type 'void' is not a literal type}} #endif constexpr ~T(); // expected-error {{destructor cannot be marked constexpr}} typedef NonLiteral F() const; constexpr F NonLiteralReturn2; // ok until definition // - each of its parameter types shall be a literal type; constexpr int NonLiteralParam(NonLiteral) const { return 0; } // expected-error {{constexpr function's 1st parameter type 'NonLiteral' is not a literal type}} typedef int G(NonLiteral) const; constexpr G NonLiteralParam2; // ok until definition // - its function-body shall be = delete, = default, constexpr int Deleted() const = delete; // It's not possible for the function-body to legally be "= default" here // (that is, for a non-constructor function) in C++11. // Other than constructors, only the copy- and move-assignment operators and // destructor can be defaulted. Destructors can't be constexpr since they // don't have a literal return type. Defaulted assignment operators can't be // constexpr since they can't be const. constexpr T &operator=(const T&) = default; #ifndef CXX1Y // expected-error@-2 {{an explicitly-defaulted copy assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}} // expected-warning@-3 {{C++14}} #else // expected-error@-5 {{defaulted definition of copy assignment operator is not constexpr}} #endif }; constexpr int T::OutOfLineVirtual() const { return 0; } #ifdef CXX1Y struct T2 { int n = 0; constexpr T2 &operator=(const T2&) = default; // ok }; struct T3 { constexpr T3 &operator=(const T3&) const = default; // expected-error@-1 {{an explicitly-defaulted copy assignment operator may not have 'const' or 'volatile' qualifiers}} }; #endif struct U { constexpr U SelfReturn() const; constexpr int SelfParam(U) const; }; struct V : virtual U { // expected-note {{here}} constexpr int F() const { return 0; } // expected-error {{constexpr member function not allowed in struct with virtual base class}} }; // or a compound-statememt that contains only [CXX11] constexpr int AllowedStmtsCXX11() { // - null statements ; // - static_assert-declarations static_assert(true, "the impossible happened!"); // - typedef declarations and alias-declarations that do not define classes // or enumerations typedef int I; typedef struct S T; using J = int; using K = int[sizeof(I) + sizeof(J)]; // Note, the standard requires we reject this. struct U; // - using-declarations using N::C; // - using-directives using namespace N; // - and exactly one return statement return sizeof(K) + sizeof(C) + sizeof(K); } // or a compound-statement that does not contain [CXX1Y] constexpr int DisallowedStmtsCXX1Y_1() { // - an asm-definition asm("int3"); // expected-error {{statement not allowed in constexpr function}} return 0; } constexpr int DisallowedStmtsCXX1Y_2() { // - a goto statement goto x; // expected-error {{statement not allowed in constexpr function}} x: return 0; } constexpr int DisallowedStmtsCXX1Y_3() { // - a try-block, try {} catch (...) {} // expected-error {{statement not allowed in constexpr function}} return 0; } constexpr int DisallowedStmtsCXX1Y_4() { // - a definition of a variable of non-literal type NonLiteral nl; // expected-error {{variable of non-literal type 'NonLiteral' cannot be defined in a constexpr function}} return 0; } constexpr int DisallowedStmtsCXX1Y_5() { // - a definition of a variable of static storage duration static constexpr int n = 123; // expected-error {{static variable not permitted in a constexpr function}} return n; } constexpr int DisallowedStmtsCXX1Y_6() { // - a definition of a variable of thread storage duration thread_local constexpr int n = 123; // expected-error {{thread_local variable not permitted in a constexpr function}} return n; } constexpr int DisallowedStmtsCXX1Y_7() { // - a definition of a variable for which no initialization is performed int n; // expected-error {{variables defined in a constexpr function must be initialized}} return 0; } constexpr int ForStmt() { for (int n = 0; n < 10; ++n) #ifndef CXX1Y // expected-error@-2 {{statement not allowed in constexpr function}} #endif return 0; } constexpr int VarDecl() { int a = 0; #ifndef CXX1Y // expected-error@-2 {{variable declaration in a constexpr function is a C++14 extension}} #endif return 0; } constexpr int ConstexprVarDecl() { constexpr int a = 0; #ifndef CXX1Y // expected-error@-2 {{variable declaration in a constexpr function is a C++14 extension}} #endif return 0; } constexpr int VarWithCtorDecl() { Literal a; #ifndef CXX1Y // expected-error@-2 {{variable declaration in a constexpr function is a C++14 extension}} #endif return 0; } NonLiteral nl; constexpr NonLiteral &ExternNonLiteralVarDecl() { extern NonLiteral nl; #ifndef CXX1Y // expected-error@-2 {{variable declaration in a constexpr function is a C++14 extension}} #endif return nl; } static_assert(&ExternNonLiteralVarDecl() == &nl, ""); constexpr int FuncDecl() { constexpr int ForwardDecl(int); #ifndef CXX1Y // expected-error@-2 {{use of this statement in a constexpr function is a C++14 extension}} #endif return ForwardDecl(42); } constexpr int ClassDecl1() { typedef struct { } S1; #ifndef CXX1Y // expected-error@-2 {{type definition in a constexpr function is a C++14 extension}} #endif return 0; } constexpr int ClassDecl2() { using S2 = struct { }; #ifndef CXX1Y // expected-error@-2 {{type definition in a constexpr function is a C++14 extension}} #endif return 0; } constexpr int ClassDecl3() { struct S3 { }; #ifndef CXX1Y // expected-error@-2 {{type definition in a constexpr function is a C++14 extension}} #endif return 0; } constexpr int NoReturn() {} // expected-error {{no return statement in constexpr function}} constexpr int MultiReturn() { return 0; return 0; #ifndef CXX1Y // expected-error@-2 {{multiple return statements in constexpr function}} // expected-note@-4 {{return statement}} #endif } // - every constructor call and implicit conversion used in initializing the // return value shall be one of those allowed in a constant expression. // // We implement the proposed resolution of DR1364 and ignore this bullet. // However, we implement the spirit of the check as part of the p5 checking that // a constexpr function must be able to produce a constant expression. namespace DR1364 { constexpr int f(int k) { return k; // ok, even though lvalue-to-rvalue conversion of a function // parameter is not allowed in a constant expression. } int kGlobal; // expected-note {{here}} constexpr int f() { // expected-error {{constexpr function never produces a constant expression}} return kGlobal; // expected-note {{read of non-const}} } } namespace rdar13584715 { typedef __PTRDIFF_TYPE__ ptrdiff_t; template<typename T> struct X { static T value() {}; }; void foo(ptrdiff_t id) { switch (id) { case reinterpret_cast<ptrdiff_t>(&X<long>::value): // expected-error{{case value is not a constant expression}} \ // expected-note{{reinterpret_cast is not allowed in a constant expression}} break; } } } namespace std_example { constexpr int square(int x) { return x * x; } constexpr long long_max() { return 2147483647; } constexpr int abs(int x) { if (x < 0) #ifndef CXX1Y // expected-error@-2 {{C++14}} #endif x = -x; return x; } constexpr int first(int n) { static int value = n; // expected-error {{static variable not permitted}} return value; } constexpr int uninit() { int a; // expected-error {{must be initialized}} return a; } constexpr int prev(int x) { return --x; } #ifndef CXX1Y // expected-error@-4 {{never produces a constant expression}} // expected-note@-4 {{subexpression}} #endif constexpr int g(int x, int n) { int r = 1; while (--n > 0) r *= x; return r; } #ifndef CXX1Y // expected-error@-5 {{C++14}} // expected-error@-5 {{statement not allowed}} #endif }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p2.cpp
// RUN: %clang_cc1 -std=c++11 -emit-llvm -triple %itanium_abi_triple %s -o - | FileCheck %s // constexpr functions and constexpr constructors are implicitly inline. struct S { constexpr S(int n); constexpr int g(); int n; }; constexpr S::S(int n) : n(n) {} constexpr S f(S s) { return s.n * 2; } constexpr int S::g() { return f(*this).n; } // CHECK: define linkonce_odr {{.*}} @_Z1f1S( // CHECK: define linkonce_odr {{.*}} @_ZN1SC1Ei( // CHECK: define linkonce_odr {{.*}} @_ZNK1S1gEv( int g() { return f(42).g(); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s struct notlit { // expected-note {{not literal because}} notlit() {} }; struct notlit2 { notlit2() {} }; // valid declarations constexpr int i1 = 0; constexpr int f1() { return 0; } struct s1 { constexpr static int mi1 = 0; const static int mi2; }; constexpr int s1::mi2 = 0; // invalid declarations // not a definition of an object constexpr extern int i2; // expected-error {{constexpr variable declaration must be a definition}} // not a literal type constexpr notlit nl1; // expected-error {{constexpr variable cannot have non-literal type 'const notlit'}} // function parameters void f2(constexpr int i) {} // expected-error {{function parameter cannot be constexpr}} // non-static member struct s2 { constexpr int mi1; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} static constexpr int mi2; // expected-error {{requires an initializer}} mutable constexpr int mi3 = 3; // expected-error-re {{non-static data member cannot be constexpr{{$}}}} expected-error {{'mutable' and 'const' cannot be mixed}} }; // typedef typedef constexpr int CI; // expected-error {{typedef cannot be constexpr}} // tag constexpr class C1 {}; // expected-error {{class cannot be marked constexpr}} constexpr struct S1 {}; // expected-error {{struct cannot be marked constexpr}} constexpr union U1 {}; // expected-error {{union cannot be marked constexpr}} constexpr enum E1 {}; // expected-error {{enum cannot be marked constexpr}} template <typename T> constexpr class TC1 {}; // expected-error {{class cannot be marked constexpr}} template <typename T> constexpr struct TS1 {}; // expected-error {{struct cannot be marked constexpr}} template <typename T> constexpr union TU1 {}; // expected-error {{union cannot be marked constexpr}} class C2 {} constexpr; // expected-error {{class cannot be marked constexpr}} struct S2 {} constexpr; // expected-error {{struct cannot be marked constexpr}} union U2 {} constexpr; // expected-error {{union cannot be marked constexpr}} enum E2 {} constexpr; // expected-error {{enum cannot be marked constexpr}} constexpr class C3 {} c3 = C3(); constexpr struct S3 {} s3 = S3(); constexpr union U3 {} u3 = {}; constexpr enum E3 { V3 } e3 = V3; class C4 {} constexpr c4 = C4(); struct S4 {} constexpr s4 = S4(); union U4 {} constexpr u4 = {}; enum E4 { V4 } constexpr e4 = V4; constexpr int; // expected-error {{constexpr can only be used in variable and function declarations}} // redeclaration mismatch constexpr int f3(); // expected-note {{previous declaration is here}} int f3(); // expected-error {{non-constexpr declaration of 'f3' follows constexpr declaration}} int f4(); // expected-note {{previous declaration is here}} constexpr int f4(); // expected-error {{constexpr declaration of 'f4' follows non-constexpr declaration}} template<typename T> constexpr T f5(T); template<typename T> constexpr T f5(T); // expected-note {{previous}} template<typename T> T f5(T); // expected-error {{non-constexpr declaration of 'f5' follows constexpr declaration}} template<typename T> T f6(T); // expected-note {{here}} template<typename T> constexpr T f6(T); // expected-error {{constexpr declaration of 'f6' follows non-constexpr declaration}} // destructor struct ConstexprDtor { constexpr ~ConstexprDtor() = default; // expected-error {{destructor cannot be marked constexpr}} }; // template stuff template <typename T> constexpr T ft(T t) { return t; } template <typename T> T gt(T t) { return t; } struct S { template<typename T> constexpr T f(); // expected-warning {{C++14}} template <typename T> T g() const; // expected-note-re {{candidate template ignored: could not match 'T (){{( __attribute__\(\(thiscall\)\))?}} const' against 'char (){{( __attribute__\(\(thiscall\)\))?}}'}} }; // explicit specialization can differ in constepxr template <> notlit ft(notlit nl) { return nl; } template <> char ft(char c) { return c; } // expected-note {{previous}} template <> constexpr char ft(char nl); // expected-error {{constexpr declaration of 'ft<char>' follows non-constexpr declaration}} template <> constexpr int gt(int nl) { return nl; } template <> notlit S::f() const { return notlit(); } template <> constexpr int S::g() { return 0; } // expected-note {{previous}} expected-warning {{C++14}} template <> int S::g() const; // expected-error {{non-constexpr declaration of 'g<int>' follows constexpr declaration}} // specializations can drop the 'constexpr' but not the implied 'const'. template <> char S::g() { return 0; } // expected-error {{no function template matches}} template <> double S::g() const { return 0; } // ok constexpr int i3 = ft(1); void test() { // ignore constexpr when instantiating with non-literal notlit2 nl2; (void)ft(nl2); } // Examples from the standard: constexpr int square(int x); // expected-note {{declared here}} constexpr int bufsz = 1024; constexpr struct pixel { // expected-error {{struct cannot be marked constexpr}} int x; int y; constexpr pixel(int); }; constexpr pixel::pixel(int a) : x(square(a)), y(square(a)) // expected-note {{undefined function 'square' cannot be used in a constant expression}} { } constexpr pixel small(2); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'pixel(2)'}} constexpr int square(int x) { return x * x; } constexpr pixel large(4); int next(constexpr int x) { // expected-error {{function parameter cannot be constexpr}} return x + 1; } extern constexpr int memsz; // expected-error {{constexpr variable declaration must be a definition}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify -std=c++11 -fcxx-exceptions %s // RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -std=c++11 -fcxx-exceptions -Wno-invalid-constexpr %s -DNO_INVALID_CONSTEXPR namespace StdExample { constexpr int f(void *) { return 0; } constexpr int f(...) { return 1; } constexpr int g1() { return f(0); } constexpr int g2(int n) { return f(n); } constexpr int g3(int n) { return f(n*0); } namespace N { constexpr int c = 5; constexpr int h() { return c; } } constexpr int c = 0; constexpr int g4() { return N::h(); } static_assert(f(0) == 0, ""); static_assert(f('0') == 1, ""); static_assert(g1() == 0, ""); static_assert(g2(0) == 1, ""); static_assert(g2(1) == 1, ""); static_assert(g3(0) == 1, ""); static_assert(g3(1) == 1, ""); static_assert(N::h() == 5, ""); static_assert(g4() == 5, ""); constexpr int f(bool b) { return b ? throw 0 : 0; } // ok constexpr int f() { return throw 0, 0; } // expected-error {{constexpr function never produces a constant expression}} expected-note {{subexpression}} struct B { constexpr B(int x) : i(0) { } int i; }; int global; // expected-note {{declared here}} struct D : B { constexpr D() : B(global) { } // expected-error {{constexpr constructor never produces a constant expression}} expected-note {{read of non-const}} }; } namespace PotentialConstant { constexpr int Comma(int n) { return // expected-error {{constexpr function never produces a constant expression}} (void)(n * 2), throw 0, // expected-note {{subexpression}} 0; } int ng; // expected-note 6{{here}} constexpr int BinaryOp1(int n) { return n + ng; } // expected-error {{never produces}} expected-note {{read}} constexpr int BinaryOp2(int n) { return ng + n; } // expected-error {{never produces}} expected-note {{read}} double dg; // expected-note 2{{here}} constexpr double BinaryOp1(double d) { return d + dg; } // expected-error {{never produces}} expected-note {{read}} constexpr double BinaryOp2(double d) { return dg + d; } // expected-error {{never produces}} expected-note {{read}} constexpr int Add(int a, int b, int c) { return a + b + c; } constexpr int FunctionArgs(int a) { return Add(a, ng, a); } // expected-error {{never produces}} expected-note {{read}} struct S { int a; int b; int c[2]; }; constexpr S InitList(int a) { return { a, ng }; }; // expected-error {{never produces}} expected-note {{read}} constexpr S InitList1a(int a) { return S{ a, ng }; }; // expected-error {{never produces}} expected-note {{read}} constexpr S InitList2(int a) { return { a, a, { ng } }; }; // expected-error {{never produces}} expected-note {{read}} constexpr S InitList3(int a) { return a ? S{ a, a } : S{ a, ng }; }; // ok constexpr int LogicalAnd1(int n) { return n && (throw, 0); } // ok constexpr int LogicalAnd2(int n) { return 1 && (throw, 0); } // expected-error {{never produces}} expected-note {{subexpression}} constexpr int LogicalOr1(int n) { return n || (throw, 0); } // ok constexpr int LogicalOr2(int n) { return 0 || (throw, 0); } // expected-error {{never produces}} expected-note {{subexpression}} constexpr int Conditional1(bool b, int n) { return b ? n : ng; } // ok constexpr int Conditional2(bool b, int n) { return b ? n * ng : n + ng; } // expected-error {{never produces}} expected-note {{both arms of conditional operator are unable to produce a constant expression}} // __builtin_constant_p ? : is magical, and is always a potential constant. constexpr bool BcpCall(int n) { return __builtin_constant_p((int*)n != &n) ? (int*)n != &n : (int*)n != &n; // expected-warning 3 {{cast to 'int *' from smaller integer type 'int'}} } static_assert(BcpCall(0), ""); // DR1311: A function template which can produce a constant expression, but // for which a particular specialization cannot, is ok. template<typename T> constexpr T cmin(T a, T b) { return a < b ? a : b; } int n = cmin(3, 5); // ok struct X { constexpr X() {} bool operator<(X); // not constexpr }; X x = cmin(X(), X()); // ok, not constexpr // Same with other temploids. template<typename T> struct Y { constexpr Y() {} constexpr int get() { return T(); } // expected-warning {{C++14}} }; struct Z { operator int(); }; int y1 = Y<int>().get(); // ok int y2 = Y<Z>().get(); // ok } #ifndef NO_INVALID_CONSTEXPR namespace PR14550 { // As an "extension", we allow functions which can't produce constant // expressions to be declared constexpr in system headers (libstdc++ // marks some functions as constexpr which use builtins which we don't // support constant folding). Ensure that we don't mark those functions // as invalid after suppressing the diagnostic. # 122 "p5.cpp" 1 3 int n; struct A { static constexpr int f() { return n; } }; template<typename T> struct B { B() { g(T::f()); } // expected-error {{undeclared identifier 'g'}} }; # 130 "p5.cpp" 2 template class B<A>; // expected-note {{here}} } #endif
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp
// RUN: %clang_cc1 -verify -std=c++11 %s namespace N { typedef char C; } namespace M { typedef double D; } struct NonLiteral { NonLiteral() {} NonLiteral(int) {} // expected-note 2{{here}} operator int() const { return 0; } }; struct Literal { constexpr Literal() {} operator int() const { return 0; } }; struct S { virtual int ImplicitlyVirtual() const; }; struct T {}; template<typename T> struct ImplicitVirtualFromDependentBase : T { constexpr int ImplicitlyVirtual() const { return 0; } }; constexpr int a = ImplicitVirtualFromDependentBase<S>().ImplicitlyVirtual(); // expected-error {{constant expression}} expected-note {{cannot evaluate virtual function call}} constexpr int b = ImplicitVirtualFromDependentBase<T>().ImplicitlyVirtual(); // ok constexpr int c = ImplicitVirtualFromDependentBase<S>().ImplicitVirtualFromDependentBase<S>::ImplicitlyVirtual(); template<typename R> struct ConstexprMember { constexpr R F() const { return 0; } }; constexpr int d = ConstexprMember<int>().F(); // ok constexpr int e = ConstexprMember<NonLiteral>().F(); // expected-error {{constant expression}} expected-note {{non-literal type 'const NonLiteral' cannot be used in a constant expression}} template<typename ...P> struct ConstexprCtor { constexpr ConstexprCtor(P...) {} }; constexpr ConstexprCtor<> f1() { return {}; } // ok constexpr ConstexprCtor<int> f2() { return 0; } // ok constexpr ConstexprCtor<NonLiteral> f3() { return { 0 }; } // expected-error {{never produces a constant expression}} expected-note {{non-constexpr constructor 'NonLiteral}} constexpr ConstexprCtor<int, NonLiteral> f4() { return { 0, 0 }; } // expected-error {{never produces a constant expression}} expected-note {{non-constexpr constructor 'NonLiteral}} struct VirtBase : virtual S {}; // expected-note {{here}} namespace TemplateVBase { template<typename T> struct T1 : virtual Literal { // expected-note {{here}} constexpr T1() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}} }; template<typename T> struct T2 : virtual T { // FIXME: This is ill-formed (no diagnostic required). // We should diagnose it now rather than waiting until instantiation. constexpr T2() {} }; constexpr T2<Literal> g2() { return {}; } template<typename T> class T3 : public T { // expected-note {{class with virtual base class is not a literal type}} public: constexpr T3() {} }; constexpr T3<Literal> g3() { return {}; } // ok constexpr T3<VirtBase> g4() { return {}; } // expected-error {{not a literal type}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -fcxx-exceptions using X = struct { // ok }; template<typename T> using Y = struct { // expected-error {{cannot be defined in a type alias template}} }; class K { virtual ~K(); operator struct S {} (); // expected-error{{'K::S' cannot be defined in a type specifier}} }; struct A {}; void f() { int arr[3] = {1,2,3}; for (struct S { S(int) {} } s : arr) { // expected-error {{types may not be defined in a for range declaration}} } new struct T {}; // expected-error {{'T' cannot be defined in a type specifier}} new struct A {}; // expected-error {{'A' cannot be defined in a type specifier}} try {} catch (struct U {}) {} // expected-error {{'U' cannot be defined in a type specifier}} (void)(struct V { V(int); })0; // expected-error {{'V' cannot be defined in a type specifier}} (void)dynamic_cast<struct W {}*>((K*)0); // expected-error {{'W' cannot be defined in a type specifier}} (void)static_cast<struct X {}*>(0); // expected-error {{'X' cannot be defined in a type specifier}} (void)reinterpret_cast<struct Y {}*>(0); // expected-error {{'Y' cannot be defined in a type specifier}} (void)const_cast<struct Z {}*>((const Z*)0); // expected-error {{'Z' cannot be defined in a type specifier}} } void g() throw (struct Ex {}) { // expected-error {{'Ex' cannot be defined in a type specifier}} } alignas(struct Aa {}) int x; // expected-error {{'Aa' cannot be defined in a type specifier}} int a = sizeof(struct So {}); // expected-error {{'So' cannot be defined in a type specifier}} int b = alignof(struct Ao {}); // expected-error {{'Ao' cannot be defined in a type specifier}} namespace std { struct type_info; } const std::type_info &ti = typeid(struct Ti {}); // expected-error {{'Ti' cannot be defined in a type specifier}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s struct A { typedef int type; }; template<typename T> using X = A; // expected-note {{declared here}} struct X<int>* p2; // expected-error {{elaborated type refers to a type alias template}} template<typename T> using Id = T; // expected-note {{declared here}} template<template<typename> class F> struct Y { struct F<int> i; // expected-error {{elaborated type refers to a type alias template}} typename F<A>::type j; // ok // FIXME: don't produce the diagnostic both for the definition and the instantiation. template<typename T> using U = F<char>; // expected-note 2{{declared here}} struct Y<F>::template U<char> k; // expected-error 2{{elaborated type refers to a type alias template}} typename Y<F>::template U<char> l; // ok }; template struct Y<Id>; // expected-note {{requested here}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s class A {}; // expected-note 4 {{previous use is here}} enum E {}; void a1(struct A); void a2(class A); void a3(union A); // expected-error {{use of 'A' with tag type that does not match previous declaration}} void a4(enum A); // expected-error {{use of 'A' with tag type that does not match previous declaration}} class A1 { friend struct A; friend class A; friend union A; // expected-error {{use of 'A' with tag type that does not match previous declaration}} friend enum A; // expected-error {{use of 'A' with tag type that does not match previous declaration}} friend enum E; // expected-warning {{befriending enumeration type 'enum E' is a C++11 extension}} }; template <class T> struct B { // expected-note {{previous use is here}} class Member {}; // expected-note 2 {{previous use is here}} }; template <> class B<int> { // no type Member }; template <> struct B<A> { union Member { // expected-note 4 {{previous use is here}} void* a; }; }; void b1(struct B<float>); void b2(class B<float>); void b3(union B<float>); // expected-error {{use of 'B<float>' with tag type that does not match previous declaration}} //void b4(enum B<float>); // this just doesn't parse; you can't template an enum directly void c1(struct B<float>::Member); void c2(class B<float>::Member); void c3(union B<float>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}} void c4(enum B<float>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}} void d1(struct B<int>::Member); // expected-error {{no struct named 'Member' in 'B<int>'}} void d2(class B<int>::Member); // expected-error {{no class named 'Member' in 'B<int>'}} void d3(union B<int>::Member); // expected-error {{no union named 'Member' in 'B<int>'}} void d4(enum B<int>::Member); // expected-error {{no enum named 'Member' in 'B<int>'}} void e1(struct B<A>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}} void e2(class B<A>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}} void e3(union B<A>::Member); void e4(enum B<A>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}} template <class T> struct C { void foo(class B<T>::Member); // expected-error{{no class named 'Member' in 'B<int>'}} \ // expected-error{{use of 'Member' with tag type that does not match previous declaration}} }; C<float> f1; C<int> f2; // expected-note {{in instantiation of template class}} C<A> f3; // expected-note {{in instantiation of template class}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions void f() { auto a = 0, b = 0, c = 0; auto d = 0, e = 0.0; // expected-error {{'int' in declaration of 'd' and deduced as 'double' in declaration of 'e'}} auto v1 = 0, *p1 = &v1; auto *p2 = 0, v2 = *p2; // expected-error {{incompatible initializer}} const int k = 0; auto &f = k, &g = a; // expected-error {{'const int' in declaration of 'f' and deduced as 'int' in declaration of 'g'}} typedef int I; I x; auto xa = x, xb = 0; auto &&ra1 = a, rb1 = b; // expected-error {{'int &' in declaration of 'ra1' and deduced as 'int' in declaration of 'rb1'}} auto &&ra2 = +a, rb2 = b; } void g() { auto a = 0, #if __has_feature(cxx_trailing_return) (*b)() -> void, #endif c = 0; auto d = 0, // expected-error {{'auto' deduced as 'int' in declaration of 'd' and deduced as 'double' in declaration of 'f'}} #if __has_feature(cxx_trailing_return) (*e)() -> void, #endif f = 0.0; #if __has_feature(cxx_decltype) auto g = 0ull, h = decltype(g)(0); #endif } template<typename T> void h() { auto a = T(), *b = &a; #if __has_feature(cxx_decltype) auto c = T(), d = decltype(c)(0); #endif } template void h<int>(); template void h<unsigned long>();
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp
// RUN: %clang_cc1 -verify -std=c++1y %s namespace std { template<typename T> struct initializer_list { const T *p; unsigned long n; initializer_list(const T *p, unsigned long n); }; } int i; int &&f(); template <typename T> void overloaded_fn(T); // expected-note {{possible target}} using Int = int; using IntLRef = int&; using IntRRef = int&&; using InitListInt = std::initializer_list<int>; using IntPtr = int*; auto x3a = i; decltype(auto) x3d = i; using Int = decltype(x3a); using Int = decltype(x3d); auto x4a = (i); decltype(auto) x4d = (i); using Int = decltype(x4a); using IntLRef = decltype(x4d); auto x5a = f(); decltype(auto) x5d = f(); using Int = decltype(x5a); using IntRRef = decltype(x5d); auto x6a = { 1, 2 }; decltype(auto) x6d = { 1, 2 }; // expected-error {{cannot deduce 'decltype(auto)' from initializer list}} using InitListInt = decltype(x6a); auto *x7a = &i; decltype(auto) *x7d = &i; // expected-error {{cannot form pointer to 'decltype(auto)'}} using IntPtr = decltype(x7a); struct S {}; decltype(auto) f1(); decltype(auto) (*f2)(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{requires an initializer}} decltype(auto) *f3(); // expected-error {{cannot form pointer to 'decltype(auto)'}} const decltype(auto) f4(); // expected-error {{'decltype(auto)' cannot be combined with other type specifiers}} typedef decltype(auto) f5(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} decltype(auto) ((((((f6))))())); // ok decltype(auto) f7()(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{function cannot return function type}} decltype(auto) (S::*f8)(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{requires an initializer}} decltype(auto) &f9(); // expected-error {{cannot form reference to 'decltype(auto)'}} decltype(auto) (&f10())[10]; // expected-error {{cannot form array of 'decltype(auto)'}} decltype(auto) ((((((v1)))))) = 0; // ok decltype(auto) v2[1] = { 0 }; // expected-error {{cannot form array of 'decltype(auto)'}} decltype(auto) &v3 = { 0 }; // expected-error {{cannot form reference to 'decltype(auto)'}} decltype(auto) *v4 = { 0 }; // expected-error {{cannot form pointer to 'decltype(auto)'}} decltype(auto) v5 = &overloaded_fn; // expected-error {{could not be resolved}} auto multi1a = 0, &multi1b = multi1a; auto multi1c = multi1a, multi1d = multi1b; decltype(auto) multi1e = multi1a, multi1f = multi1b; // expected-error {{'decltype(auto)' deduced as 'int' in declaration of 'multi1e' and deduced as 'int &' in declaration of 'multi1f'}} auto f1a() { return 0; } decltype(auto) f1d() { return 0; } using Int = decltype(f1a()); using Int = decltype(f1d()); auto f2a(int n) { return n; } decltype(auto) f2d(int n) { return n; } using Int = decltype(f2a(0)); using Int = decltype(f2d(0)); auto f3a(int n) { return (n); } decltype(auto) f3d(int n) { return (n); } // expected-warning {{reference to stack memory}} using Int = decltype(f3a(0)); using IntLRef = decltype(f3d(0)); auto f4a(int n) { return f(); } decltype(auto) f4d(int n) { return f(); } using Int = decltype(f4a(0)); using IntRRef = decltype(f4d(0)); auto f5aa(int n) { auto x = f(); return x; } auto f5ad(int n) { decltype(auto) x = f(); return x; } decltype(auto) f5da(int n) { auto x = f(); return x; } decltype(auto) f5dd(int n) { decltype(auto) x = f(); return x; } // expected-error {{rvalue reference to type 'int' cannot bind to lvalue}} using Int = decltype(f5aa(0)); using Int = decltype(f5ad(0)); using Int = decltype(f5da(0)); auto init_list_1() { return { 1, 2, 3 }; } // expected-error {{cannot deduce return type from initializer list}} decltype(auto) init_list_2() { return { 1, 2, 3 }; } // expected-error {{cannot deduce return type from initializer list}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p12-1y.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s // RUN: %clang_cc1 -std=c++1y -verify %s template<typename T> struct S { typedef int type; }; template<typename T> void f() { auto x = [] { return 0; } (); // FIXME: We should be able to produce a 'missing typename' diagnostic here. S<decltype(x)>::type n; // expected-error 2{{}} } #if __cplusplus > 201103L template<typename T> void g() { auto x = [] () -> auto { return 0; } (); S<decltype(x)>::type n; // expected-error 2{{}} } #endif
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wno-c++1y-extensions // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions template<typename T> struct only { only(T); template<typename U> only(U) = delete; }; void f() { if (auto a = true) { } switch (auto a = 0) { } while (auto a = false) { } for (; auto a = false; ) { } new const auto (0); new (auto) (0.0); int arr[] = {1, 2, 3}; for (auto i : arr) { } } class X { static const auto n = 'x'; auto m = 0; // expected-error {{'auto' not allowed in non-static class member}} }; struct S { static const auto a; // expected-error {{declaration of variable 'a' with type 'const auto' requires an initializer}} static const auto b = 0; static const int c; }; const int S::b; const auto S::c = 0; namespace std { template<typename T> struct initializer_list { initializer_list(); }; } // In an initializer of the form ( expression-list ), the expression-list // shall be a single assigment-expression. auto parens1(1); auto parens2(2, 3); // expected-error {{initializer for variable 'parens2' with type 'auto' contains multiple expressions}} #if __cplusplus >= 201103L auto parens3({4, 5, 6}); // expected-error {{cannot deduce type for variable 'parens3' with type 'auto' from parenthesized initializer list}} auto parens4 = [p4(1)] {}; auto parens5 = [p5(2, 3)] {}; // expected-error {{initializer for lambda capture 'p5' contains multiple expressions}} auto parens6 = [p6({4, 5, 6})] {}; // expected-error {{cannot deduce type for lambda capture 'p6' from parenthesized initializer list}} #endif #if __cplusplus >= 201402L namespace std_example { // The other half of this example is in p3.cpp auto f() -> int; auto g() { return 0.0; } auto h(); } #endif
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-1y.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y -DCXX1Y // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wno-c++1y-extensions // FIXME: This is in p11 (?) in C++1y. void f() { decltype(auto) a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}} if (decltype(auto) b = b) {} // expected-error {{variable 'b' declared with 'auto' type cannot appear in its own initializer}} decltype(auto) c = ({ decltype(auto) d = c; 0; }); // expected-error {{variable 'c' declared with 'auto' type cannot appear in its own initializer}} } void g() { decltype(auto) a; // expected-error{{declaration of variable 'a' with type 'decltype(auto)' requires an initializer}} decltype(auto) *b; // expected-error{{cannot form pointer to 'decltype(auto)'}} expected-error{{declaration of variable 'b' with type 'decltype(auto) *' requires an initializer}} if (decltype(auto) b) {} // expected-error {{must have an initializer}} for (;decltype(auto) b;) {} // expected-error {{must have an initializer}} while (decltype(auto) b) {} // expected-error {{must have an initializer}} if (decltype(auto) b = true) { (void)b; } } decltype(auto) n(1,2,3); // expected-error{{initializer for variable 'n' with type 'decltype(auto)' contains multiple expressions}} namespace N { // All of these are references, because a string literal is an lvalue. decltype(auto) a = "const char (&)[19]", b = a, c = (a); } void h() { decltype(auto) b = 42ULL; for (decltype(auto) c = 0; c < b; ++c) { } } template<typename T, typename U> struct same; template<typename T> struct same<T, T> {}; void i() { decltype(auto) x = 5; decltype(auto) int r; // expected-error {{cannot combine with previous 'decltype(auto)' declaration specifier}} expected-error {{requires an initializer}} } namespace p3_example { template<typename T, typename U> struct is_same_impl { static const bool value = false; }; template<typename T> struct is_same_impl<T, T> { static const bool value = true; }; template<typename T, typename U> constexpr bool is_same() { return is_same_impl<T,U>::value; } auto x = 5; const auto *v = &x, u = 6; static auto y = 0.0; auto int r; // expected-warning {{storage class}} expected-error {{file-scope}} static_assert(is_same<decltype(x), int>(), ""); static_assert(is_same<decltype(v), const int*>(), ""); static_assert(is_same<decltype(u), const int>(), ""); static_assert(is_same<decltype(y), double>(), ""); #ifdef CXX1Y auto f() -> int; auto g() { return 0.0; } auto h(); static_assert(is_same<decltype(f), int()>(), ""); static_assert(is_same<decltype(g), double()>(), ""); #endif }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions -Wc++11-compat void f() { auto a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}} auto *b = b; // expected-error{{variable 'b' declared with 'auto' type cannot appear in its own initializer}} const auto c = c; // expected-error{{variable 'c' declared with 'auto' type cannot appear in its own initializer}} if (auto d = d) {} // expected-error {{variable 'd' declared with 'auto' type cannot appear in its own initializer}} auto e = ({ auto f = e; 0; }); // expected-error {{variable 'e' declared with 'auto' type cannot appear in its own initializer}} } void g() { auto a; // expected-error{{declaration of variable 'a' with type 'auto' requires an initializer}} auto *b; // expected-error{{declaration of variable 'b' with type 'auto *' requires an initializer}} if (auto b) {} // expected-error {{must have an initializer}} for (;auto b;) {} // expected-error {{must have an initializer}} while (auto b) {} // expected-error {{must have an initializer}} if (auto b = true) { (void)b; } } auto n(1,2,3); // expected-error{{initializer for variable 'n' with type 'auto' contains multiple expressions}} namespace N { auto a = "const char [16]", *p = &a; } void h() { auto b = 42ULL; for (auto c = 0; c < b; ++c) { } } template<typename T, typename U> struct same; template<typename T> struct same<T, T> {}; void p3example() { auto x = 5; const auto *v = &x, u = 6; static auto y = 0.0; // In C++98: 'auto' storage class specifier is redundant and incompatible with C++0x // In C++0x: 'auto' storage class specifier is not permitted in C++0x, and will not be supported in future releases auto int r; // expected-warning {{'auto' storage class specifier}} same<__typeof(x), int> xHasTypeInt; same<__typeof(v), const int*> vHasTypeConstIntPtr; same<__typeof(u), const int> uHasTypeConstInt; same<__typeof(y), double> yHasTypeDouble; } #if __cplusplus >= 201103L namespace PR13293 { // Ensure that dependent declarators have their deduction delayed. int f(char); double f(short); template<typename T> struct S { static constexpr auto (*p)(T) = &f; }; constexpr int (*f1)(char) = &f; constexpr double (*f2)(short) = &f; static_assert(S<char>::p == f1, ""); static_assert(S<short>::p == f2, ""); struct K { int n; }; template<typename T> struct U { static constexpr auto (T::*p) = &K::n; }; static_assert(U<K>::p == &K::n, ""); template<typename T> using X = auto(int) -> auto(*)(T) -> auto(*)(char) -> long; X<double> x; template<typename T> struct V { //static constexpr auto (*p)(int) -> auto(*)(T) -> auto(*)(char) = &x; // ill-formed static constexpr auto (*(*(*p)(int))(T))(char) = &x; // ok }; V<double> v; int *g(double); template<typename T> void h() { new (auto(*)(T)) (&g); } template void h<double>(); } #endif auto fail((unknown)); // expected-error{{use of undeclared identifier 'unknown'}} int& crash = fail;
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s -std=c++11 struct S { virtual ~S(); void g() throw (auto(*)()->int); // Note, this is not permitted: conversion-declarator cannot have a trailing return type. // FIXME: don't issue the second diagnostic for this. operator auto(*)()->int(); // expected-error{{'auto' not allowed in conversion function type}} expected-error {{C++ requires a type specifier}} }; typedef auto Fun(int a) -> decltype(a + a); typedef auto (*PFun)(int a) -> decltype(a + a); void g(auto (*f)() -> int) { try { } catch (auto (&f)() -> int) { } catch (auto (*const f[10])() -> int) { } } namespace std { class type_info; } template<typename T> struct U {}; void j() { (void)typeid(auto(*)()->void); (void)sizeof(auto(*)()->void); (void)__alignof(auto(*)()->void); U<auto(*)()->void> v; int n; (void)static_cast<auto(*)()->void>(&j); auto p = reinterpret_cast<auto(*)()->int>(&j); (void)const_cast<auto(**)()->int>(&p); (void)(auto(*)()->void)(&j); } template <auto (*f)() -> void = &j> class C { }; struct F : auto(*)()->int {}; // expected-error{{expected class name}} template<typename T = auto(*)()->int> struct G { }; int g(); auto (*h)() -> auto = &g; // expected-error{{'auto' not allowed in function return type}} auto (*i)() = &g; // ok; auto deduced as int. auto (*k)() -> int = i; // ok; no deduction.
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s -std=c++11 struct S { virtual ~S(); auto a; // expected-error{{'auto' not allowed in non-static struct member}} auto *b; // expected-error{{'auto' not allowed in non-static struct member}} const auto c; // expected-error{{'auto' not allowed in non-static struct member}} void f() throw (auto); // expected-error{{'auto' not allowed here}} friend auto; // expected-error{{'auto' not allowed in non-static struct member}} operator auto(); // expected-error{{'auto' not allowed in conversion function type}} }; // PR 9278: auto is not allowed in typedefs, except with a trailing return type. typedef auto *AutoPtr; // expected-error{{'auto' not allowed in typedef}} typedef auto (*PFun)(int a); // expected-error{{'auto' not allowed in typedef}} typedef auto Fun(int a) -> decltype(a + a); void g(auto a) { // expected-error{{'auto' not allowed in function prototype}} try { } catch (auto &a) { } // expected-error{{'auto' not allowed in exception declaration}} catch (const auto a) { } // expected-error{{'auto' not allowed in exception declaration}} try { } catch (auto a) { } // expected-error{{'auto' not allowed in exception declaration}} } void h(auto a[10]) { // expected-error{{'auto' not allowed in function prototype}} } void i(const auto a) { // expected-error{{'auto' not allowed in function prototype}} } namespace std { class type_info; } template<typename T> struct U {}; void j() { (void)typeid(auto); // expected-error{{'auto' not allowed here}} (void)sizeof(auto); // expected-error{{'auto' not allowed here}} (void)__alignof(auto); // expected-error{{'auto' not allowed here}} U<auto> v; // expected-error{{'auto' not allowed in template argument}} int n; (void)dynamic_cast<auto&>(n); // expected-error{{'auto' not allowed here}} (void)static_cast<auto*>(&n); // expected-error{{'auto' not allowed here}} (void)reinterpret_cast<auto*>(&n); // expected-error{{'auto' not allowed here}} (void)const_cast<auto>(n); // expected-error{{'auto' not allowed here}} (void)*(auto*)(&n); // expected-error{{'auto' not allowed here}} (void)auto(n); // expected-error{{expected expression}} (void)auto{n}; // expected-error{{expected expression}} } template <auto a = 10> class C { }; // expected-error{{'auto' not allowed in template parameter}} int ints[] = {1, 2, 3}; template <const auto (*a)[3] = &ints> class D { }; // expected-error{{'auto' not allowed in template parameter}} enum E : auto {}; // expected-error{{'auto' not allowed here}} struct F : auto {}; // expected-error{{expected class name}} template<typename T = auto> struct G { }; // expected-error{{'auto' not allowed in template argument}} using A = auto; // expected-error{{'auto' not allowed in type alias}} auto k() -> auto; // expected-error{{'auto' not allowed in function return type}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-generic-lambda-1y.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y -DCXX1Y //FIXME: These tests were written when return type deduction had not been implemented // for generic lambdas, hence template<class T> T id(T t); template<class ... Ts> int vfoo(Ts&& ... ts); auto GL1 = [](auto a, int i) -> int { return id(a); }; auto GL2 = [](auto ... As) -> int { return vfoo(As...); }; auto GL3 = [](int i, char c, auto* ... As) -> int { return vfoo(As...); }; auto GL4 = [](int i, char c, auto* ... As) -> int { return vfoo(As...); }; void foo() { auto GL1 = [](auto a, int i) -> int { return id(a); }; auto GL2 = [](auto ... As) -> int { return vfoo(As...); }; } int main() { auto l1 = [](auto a) -> int { return a + 5; }; auto l2 = [](auto *p) -> int { return p + 5; }; struct A { int i; char f(int) { return 'c'; } }; auto l3 = [](auto &&ur, auto &lr, auto v, int i, auto* p, auto A::*memvar, auto (A::*memfun)(int), char c, decltype (v)* pv , auto (&array)[5] ) -> int { return v + i + c + array[0]; }; int arr[5] = {0, 1, 2, 3, 4 }; int lval = 0; double d = 3.14; l3(3, lval, d, lval, &lval, &A::i, &A::f, 'c', &d, arr); auto l4 = [](decltype(auto) a) -> int { return 0; }; //expected-error{{decltype(auto)}} { struct Local { static int ifi(int i) { return i; } static char cfi(int) { return 'a'; } static double dfi(int i) { return i + 3.14; } static Local localfi(int) { return Local{}; } }; auto l4 = [](auto (*fp)(int)) -> int { return fp(3); }; //expected-error{{no viable conversion from 'Local' to 'int'}} l4(&Local::ifi); l4(&Local::cfi); l4(&Local::dfi); l4(&Local::localfi); //expected-note{{in instantiation of function template specialization}} } { auto unnamed_parameter = [](auto, auto) -> void { }; unnamed_parameter(3, '4'); } { auto l = [](auto (*)(auto)) { }; //expected-error{{'auto' not allowed}} //FIXME: These diagnostics might need some work. auto l2 = [](char auto::*pm) { }; //expected-error{{cannot combine with previous}}\ expected-error{{'pm' does not point into a class}} auto l3 = [](char (auto::*pmf)()) { }; //expected-error{{'auto' not allowed}}\ expected-error{{'pmf' does not point into a class}}\ expected-error{{function cannot return function type 'char ()'}} } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions template<typename T> struct only { only(T); template<typename U> only(U) = delete; }; namespace N { auto a = "const char [16]", *p = &a; only<const char [16]> testA = a; only<const char **> testP = p; } void h() { auto b = 42ULL; only<unsigned long long> testB = b; for (auto c = 0; c < 100; ++c) { only<int> testC = c; } } void p3example() { auto x = 5; const auto *v = &x, u = 6; static auto y = 0.0; only<int> testX = x; only<const int*> testV = v; only<const int> testU = u; only<double> testY = y; } void f() { if (auto a = true) { only<bool> testA = a; } switch (auto a = 0) { case 0: only<int> testA = a; } while (auto a = false) { only<bool> testA = a; } for (; auto a = "test"; ) { only<const char[5]> testA = a; } auto *fail1 = 0; // expected-error {{variable 'fail1' with type 'auto *' has incompatible initializer of type 'int'}} int **p; const auto **fail2(p); // expected-error {{variable 'fail2' with type 'const auto **' has incompatible initializer of type 'int **'}} } struct S { void f(); char g(int); float g(double); int m; void test() { auto p1 = &S::f; auto S::*p2 = &S::f; auto (S::*p3)() = &S::f; auto p4 = &S::g; // expected-error {{incompatible initializer of type '<overloaded function type>'}} auto S::*p5 = &S::g; // expected-error {{incompatible initializer of type '<overloaded function type>'}} auto (S::*p6)(int) = &S::g; auto p7 = &S::m; auto S::*p8 = &S::m; only<void (S::*)()> test1 = p1; only<void (S::*)()> test2 = p2; only<void (S::*)()> test3 = p3; only<char (S::*)(int)> test6 = p6; only<int (S::*)> test7 = p7; only<int (S::*)> test8 = p8; } }; namespace PR10939 { struct X { int method(int); // expected-note{{possible target for call}} int method(float); // expected-note{{possible target for call}} }; template<typename T> T g(T); void f(X *x) { auto value = x->method; // expected-error {{reference to non-static member function must be called}} if (value) { } auto funcptr = &g<int>; int (*funcptr2)(int) = funcptr; } } // if the initializer is a braced-init-list, deduce auto as std::initializer_list<T>: // see SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p5-cxx0x.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s namespace std_example { template<class T> struct A { ~A() = delete; }; // expected-note {{deleted here}} template<class T> auto h() -> A<T>; template<class T> auto i(T) -> T; template<class T> auto f(T) -> decltype(i(h<T>())); // #1 template<class T> auto f(T) -> void; // #2 auto g() -> void { f(42); // ok, calls #2, since #1 is not viable. } template<class T> auto q(T) -> decltype((h<T>())); void r() { // Deduction against q succeeds, but results in a temporary which can't be // destroyed. q(42); // expected-error {{attempt to use a deleted function}} } } class PD { friend struct A; ~PD(); // expected-note 5{{here}} public: typedef int n; }; struct DD { ~DD() = delete; // expected-note 2{{here}} typedef int n; }; PD pd(); DD dd(); struct A { decltype(pd()) s; // ok decltype(pd())::n n; // ok decltype(dd()) *p = new decltype(dd()); // ok }; A a(); // Two errors here: one for the decltype, one for the variable. decltype( pd(), // expected-error {{private destructor}} pd()) pd1; // expected-error {{private destructor}} decltype(dd(), // expected-error {{deleted function}} dd()) dd1; decltype(a(), dd()) dd2; // expected-error {{deleted function}} decltype( pd(), // expected-error {{temporary of type 'PD' has private destructor}} 0) pd2; decltype(((13, ((dd())))))::n dd_parens; // ok decltype(((((42)), pd())))::n pd_parens_comma; // ok // Ensure parens aren't stripped from a decltype node. extern decltype(pd()) pd_ref; // ok decltype((pd_ref)) pd_ref3 = pd_ref; // ok, PD & decltype(pd_ref) pd_ref2 = pd_ref; // expected-error {{private destructor}} namespace libcxx_example { struct nat { nat() = delete; nat(const nat&) = delete; nat &operator=(const nat&) = delete; ~nat() = delete; }; struct any { any(...); }; 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> T declval(); void swap(int &a, int &b); nat swap(any, any); template<typename T> struct swappable { typedef decltype(swap(declval<T&>(), declval<T&>())) type; static const bool value = !is_same<type, nat>::value; constexpr operator bool() const { return value; } }; static_assert(swappable<int>(), ""); static_assert(!swappable<const int>(), ""); } namespace RequireCompleteType { template<int N, bool OK> struct S { static_assert(OK, "boom!"); // expected-error 2{{boom!}} }; template<typename T> T make(); template<int N, bool OK> S<N, OK> make(); void consume(...); decltype(make<0, false>()) *p1; // ok decltype((make<1, false>())) *p2; // ok // A complete type is required here in order to detect an overloaded 'operator,'. decltype(123, make<2, false>()) *p3; // expected-note {{here}} decltype(consume(make<3, false>())) *p4; // expected-note {{here}} decltype(make<decltype(make<4, false>())>()) *p5; // ok } namespace Overload { DD operator+(PD &a, PD &b); decltype(pd()) *pd_ptr; decltype(*pd_ptr + *pd_ptr) *dd_ptr; // ok decltype(0, *pd_ptr) pd_ref2 = pd_ref; // ok DD operator,(int a, PD b); decltype(0, *pd_ptr) *dd_ptr2; // expected-error {{private destructor}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -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, ""); static_assert(is_same<decltype(static_cast<int&&>(i)), int&&>::value, ""); int f0(int); // expected-note{{possible target}} float f0(float); // expected-note{{possible target}} decltype(f0) f0_a; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp
// RUN: %clang_cc1 -verify -std=c++11 %s namespace RedeclAliasTypedef { typedef int T; using T = int; using T = int; typedef T T; using T = T; typedef int T; } namespace IllegalTypeIds { using A = void(int n = 0); // expected-error {{default arguments can only be specified for parameters in a function declaration}} using B = inline void(int n); // expected-error {{type name does not allow function specifier}} using C = virtual void(int n); // expected-error {{type name does not allow function specifier}} using D = explicit void(int n); // expected-error {{type name does not allow function specifier}} using E = void(int n) throw(); // expected-error {{exception specifications are not allowed in type aliases}} using F = void(*)(int n) &&; // expected-error {{pointer to function type cannot have '&&' qualifier}} using G = __thread void(int n); // expected-error {{type name does not allow storage class to be specified}} using H = constexpr int; // expected-error {{type name does not allow constexpr specifier}} using Y = void(int n); // ok using Z = void(int n) &&; // ok } namespace IllegalSyntax { using ::T = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} using operator int = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}} using typename ::V = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} using typename ::operator bool = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} } namespace VariableLengthArrays { using T = int[42]; // ok int n = 32; using T = int[n]; // expected-error {{variable length array declaration not allowed at file scope}} const int m = 42; using U = int[m]; // expected-note {{previous definition}} using U = int[42]; // ok using U = int; // expected-error {{type alias redefinition with different types ('int' vs 'int [42]')}} void f() { int n = 42; goto foo; // expected-error {{cannot jump}} using T = int[n]; // expected-note {{bypasses initialization of VLA type alias}} foo: ; } } namespace RedeclFunc { int f(int, char**); using T = int; T f(int, char **); // ok } namespace LookupFilter { namespace N { struct S; } using namespace N; using S = S*; // ok } namespace InFunctions { template<typename...T> void f0() { using U = T*; // expected-error {{declaration type contains unexpanded parameter pack 'T'}} U u; } template void f0<int, char>(); void f1() { using T = int; } void f2() { using T = int[-1]; // expected-error {{array size is negative}} } template<typename...T> void f3() { // expected-note {{template parameter is declared here}} using T = int; // expected-error {{declaration of 'T' shadows template parameter}} } } namespace ClassNameRedecl { class C0 { using C0 = int; // expected-error {{member 'C0' has the same name as its class}} }; class C1 { using C1 = C1; // expected-error {{member 'C1' has the same name as its class}} }; class C2 { using C0 = C1; // ok }; template<typename...T> class C3 { using f = T; // expected-error {{declaration type contains unexpanded parameter pack 'T'}} }; template<typename T> class C4 { // expected-note {{template parameter is declared here}} using T = int; // expected-error {{declaration of 'T' shadows template parameter}} }; class C5 { class c; // expected-note {{previous definition}} using c = int; // expected-error {{typedef redefinition with different types}} class d; using d = d; // ok }; class C6 { class c { using C6 = int; }; // ok }; } class CtorDtorName { using X = CtorDtorName; X(); // expected-error {{expected member name}} ~X(); // expected-error {{destructor cannot be declared using a type alias}} }; namespace TagName { using S = struct { int n; }; using T = class { int n; }; using U = enum { a, b, c }; using V = struct V { int n; }; } namespace CWG1044 { using T = T; // expected-error {{unknown type name 'T'}} } namespace StdExample { template<typename T, typename U> struct pair; using handler_t = void (*)(int); extern handler_t ignore; extern void (*ignore)(int); // FIXME: we know we're parsing a type here; don't recover as if we were // using operator*. using cell = pair<void*, cell*>; // expected-error {{use of undeclared identifier 'cell'}} \ expected-error {{expected expression}} } namespace Access { class C0 { using U = int; // expected-note {{declared private here}} }; C0::U v; // expected-error {{'U' is a private member}} class C1 { public: using U = int; }; C1::U w; // ok } namespace VoidArg { using V = void; V f(int); // ok V g(V); // ok (DR577) }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p4.cpp
// RUN: %clang_cc1 -verify %s struct S { typedef struct A {} A; // expected-note {{previous definition is here}} typedef struct B B; typedef A A; // expected-error {{redefinition of 'A'}} struct C { }; typedef struct C OtherC; typedef OtherC C; typedef struct D { } D2; typedef D2 D; };
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p3.cpp
// RUN: %clang_cc1 -verify %s typedef struct s { int x; } s; typedef int I; typedef int I2; typedef I2 I; // expected-note {{previous definition is here}} typedef char I; // expected-error {{typedef redefinition with different types}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p9.cpp
// RUN: %clang_cc1 -verify %s struct S; // expected-note 2{{forward declaration of 'S'}} extern S a; extern S f(); // expected-note {{'f' declared here}} extern void g(S a); void h() { g(a); // expected-error {{argument type 'S' is incomplete}} f(); // expected-error {{calling 'f' with incomplete return type 'S'}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p10.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s typedef const int T0; typedef int& T1; struct s0 { mutable const int f0; // expected-error{{'mutable' and 'const' cannot be mixed}} mutable T0 f1; // expected-error{{'mutable' and 'const' cannot be mixed}} mutable int &f2; // expected-error{{'mutable' cannot be applied to references}} mutable T1 f3; // expected-error{{'mutable' cannot be applied to references}} mutable struct s1 {}; // expected-error{{'mutable' can only be applied to member variables}} mutable void im0(); // expected-error{{'mutable' cannot be applied to functions}} };
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++0x-compat %s // The auto or register specifiers can be applied only to names of objects // declared in a block (6.3) or to function parameters (8.4). auto int ao; // expected-error {{illegal storage class on file-scoped variable}} auto void af(); // expected-error {{illegal storage class on function}} register int ro; // expected-error {{illegal storage class on file-scoped variable}} register void rf(); // expected-error {{illegal storage class on function}} struct S { auto int ao; // expected-error {{storage class specified for a member declaration}} auto void af(); // expected-error {{storage class specified for a member declaration}} register int ro; // expected-error {{storage class specified for a member declaration}} register void rf(); // expected-error {{storage class specified for a member declaration}} }; void foo(auto int ap, register int rp) { auto int abo; auto void abf(); // expected-error {{illegal storage class on function}} register int rbo; register void rbf(); // expected-error {{illegal storage class on function}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // A storage-class-specifier shall not be specified in an explicit // specialization (14.7.3) or an explicit instantiation (14.7.2) // directive. template<typename T> void f(T) {} template<typename T> static void g(T) {} template<> static void f<int>(int); // expected-error{{explicit specialization has extraneous, inconsistent storage class 'static'}} template static void f<float>(float); // expected-error{{explicit instantiation cannot have a storage class}} template<> void f<double>(double); template void f<long>(long); template<> static void g<int>(int); // expected-warning{{explicit specialization cannot have a storage class}} template static void g<float>(float); // expected-error{{explicit instantiation cannot have a storage class}} template<> void g<double>(double); template void g<long>(long); template<typename T> struct X { static int value; }; template<typename T> int X<T>::value = 17; template static int X<int>::value; // expected-error{{explicit instantiation cannot have a storage class}} template<> static int X<float>::value; // expected-error{{'static' can only be specified inside the class definition}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.link/p7.cpp
// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s struct X { }; // CHECK: @x1 = global %struct.X zeroinitializer // CHECK: @x4 = global %struct.X zeroinitializer // CHECK: @x2 = external global %struct.X // CHECK: @x3 = external global %struct.X extern "C" { X x1; } extern "C" X x2; extern X x3; X x4; X& get(int i) { if (i == 1) return x1; else if (i == 2) return x2; else if (i == 3) return x3; else return x4; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s extern "C" { extern R"(C++)" { } } #define plusplus "++" extern "C" plusplus { } extern u8"C" {} // expected-error {{string literal in language linkage specifier cannot have an encoding-prefix}} extern L"C" {} // expected-error {{string literal in language linkage specifier cannot have an encoding-prefix}} extern u"C++" {} // expected-error {{string literal in language linkage specifier cannot have an encoding-prefix}} extern U"C" {} // expected-error {{string literal in language linkage specifier cannot have an encoding-prefix}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.dcl/dcl.link/p7-2.cpp
// RUN: %clang_cc1 -ast-print -o - %s | FileCheck %s extern "C" int f(void); // CHECK: extern "C" int f() extern "C" int v; // CHECK: extern "C" int v
0
repos/DirectXShaderCompiler/tools/clang/test/CXX
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/p9.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // floating-point overloads __typeof__(0 + 0.0L) ld0; long double &ldr = ld0; __typeof__(0 + 0.0) d0; double &dr = d0; __typeof__(0 + 0.0f) f0; float &fr = f0; // integral promotions signed char c0; __typeof__(c0 + c0) c1; int &cr = c1; unsigned char uc0; __typeof__(uc0 + uc0) uc1; int &ucr = uc1; short s0; __typeof__(s0 + s0) s1; int &sr = s1; unsigned short us0; __typeof__(us0 + us0) us1; int &usr = us1; // integral overloads __typeof__(0 + 0UL) ul0; unsigned long &ulr = ul0; template<bool T> struct selector; template<> struct selector<true> { typedef long type; }; template<> struct selector<false> {typedef unsigned long type; }; __typeof__(0U + 0L) ui_l0; selector<(sizeof(long) > sizeof(unsigned int))>::type &ui_lr = ui_l0; __typeof__(0 + 0L) l0; long &lr = l0; __typeof__(0 + 0U) u0; unsigned &ur = u0; __typeof__(0 + 0) i0; int &ir = i0;
0
repos/DirectXShaderCompiler/tools/clang/test/CXX
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/p8.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics int a0; const volatile int a1 = 2; int a2[16]; int a3(); void f0(int); void f1(int *); void f2(int (*)()); int main() { f0(a0); f0(a1); f1(a2); f2(a3); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/p3.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s double operator +(double, double); // expected-error{{overloaded 'operator+' must have at least one parameter of class or enumeration type}} struct A { operator int(); }; int main() { A a, b; int i0 = a + 1; int i1 = a + b; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/p10-0x.cpp
// RUN: %clang_cc1 -emit-llvm -triple x86_64-pc-linux-gnu %s -o - -std=c++11 | FileCheck %s volatile int g1; struct S { volatile int a; } g2; volatile int& refcall(); // CHECK: define void @_Z2f1PViPV1S void f1(volatile int *x, volatile S* s) { // We should perform the load in these cases. // CHECK: load volatile i32, i32* (*x); // CHECK: load volatile i32, i32* __extension__ g1; // CHECK: load volatile i32, i32* s->a; // CHECK: load volatile i32, i32* g2.a; // CHECK: load volatile i32, i32* s->*(&S::a); // CHECK: load volatile i32, i32* // CHECK: load volatile i32, i32* x[0], 1 ? x[0] : *x; // CHECK: load volatile i32, i32* // CHECK: load volatile i32, i32* // CHECK: load volatile i32, i32* *x ?: *x; // CHECK: load volatile i32, i32* ({ *x; }); // CHECK-NOT: load volatile // CHECK: ret } // CHECK: define void @_Z2f2PVi // CHECK-NOT: load volatile // CHECK: ret void f2(volatile int *x) { // We shouldn't perform the load in these cases. refcall(); 1 ? refcall() : *x; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.ass/p9-cxx11.cpp
// RUN: %clang_cc1 -verify -std=c++11 %s template<typename T> struct complex { complex(T = T(), T = T()); void operator+=(complex); T a, b; }; void std_example() { complex<double> z; z = { 1, 2 }; z += { 1, 2 }; int a, b; a = b = { 1 }; a = { 1 } = b; // expected-error {{initializer list cannot be used on the left hand side of operator '='}} a = a + { 4 }; // expected-error {{initializer list cannot be used on the right hand side of operator '+'}} a = { 3 } * { 4 }; // expected-error {{initializer list cannot be used on the left hand side of operator '*'}} \ expected-error {{initializer list cannot be used on the right hand side of operator '*'}} } struct S { constexpr S(int a, int b) : a(a), b(b) {} int a, b; }; struct T { constexpr int operator=(S s) const { return s.a; } constexpr int operator+=(S s) const { return s.b; } }; static_assert((T() = {4, 9}) == 4, ""); static_assert((T() += {4, 9}) == 9, ""); int k1 = T() = { 1, 2 } = { 3, 4 }; // expected-error {{initializer list cannot be used on the left hand side of operator '='}} int k2 = T() = { 1, 2 } + 1; // expected-error {{initializer list cannot be used on the left hand side of operator '+'}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.cast/p4-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // expected-no-diagnostics struct X { }; struct Y : X { }; void test_lvalue_to_rvalue_drop_cvquals(const X &x, const Y &y, const int &i) { (void)(X&&)x; (void)(int&&)i; (void)(X&&)y; (void)(Y&&)x; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.cast/p4.cpp
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s struct A { int x; }; struct B { int y; }; struct C : A, B { }; // CHECK: casting_away_constness void casting_away_constness(const B &b, const C &c, const B *bp, const C *cp) { // CHECK: DerivedToBase (B) // CHECK: DeclRefExpr {{.*}} ParmVar {{.*}} 'c' (void)(B&)c; // CHECK: BaseToDerived (B) // CHECK: DeclRefExpr {{.*}} ParmVar {{.*}} 'b' (void)(C&)b; // CHECK: DerivedToBase (B) // CHECK: DeclRefExpr {{.*}} ParmVar {{.*}} 'cp' (void)(B*)cp; // CHECK: BaseToDerived (B) // CHECK: DeclRefExpr {{.*}} ParmVar {{.*}} 'bp' (void)(C*)bp; // CHECK: ReturnStmt return; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // If T is an lvalue reference type or an rvalue reference to function // type, the result is an lvalue; if T is an rvalue reference to // object type, the result is an xvalue; unsigned int f(int); template<typename T> T&& xvalue(); void test_classification(char *ptr) { int (&fr0)(int) = reinterpret_cast<int (&&)(int)>(f); int &&ir0 = reinterpret_cast<int &&>(*ptr); int &&ir1 = reinterpret_cast<int &&>(0); // expected-error {{rvalue to reference type}} int &&ir2 = reinterpret_cast<int &&>('a'); // expected-error {{rvalue to reference type}} int &&ir3 = reinterpret_cast<int &&>(xvalue<char>()); // Per DR1268, reinterpret_cast can convert between lvalues and xvalues. int &ir4 = reinterpret_cast<int &>(xvalue<char>()); int &&ir5 = reinterpret_cast<int &&>(*ptr); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post/expr.type.conv/p1-0x.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s // expected-no-diagnostics struct foo { foo(); foo(int); }; int func(foo& f) { decltype(foo())(); f = (decltype(foo()))5; return decltype(3)(5); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post/expr.call/p7-0x.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s struct X1 { X1(); }; struct X2 { X2(); ~X2(); }; struct X3 { X3(const X3&) = default; }; struct X4 { X4(const X4&) = default; X4(X4&); }; void vararg(...); void g(); void f(X1 x1, X2 x2, X3 x3, X4 x4) { vararg(x1); // OK vararg(x2); // expected-error{{cannot pass object of non-trivial type 'X2' through variadic function; call will abort at runtime}} vararg(x3); // OK vararg(x4); // expected-error{{cannot pass object of non-trivial type 'X4' through variadic function; call will abort at runtime}} vararg(g()); // expected-error{{cannot pass expression of type 'void' to variadic function}} vararg({1, 2, 3}); // expected-error{{cannot pass initializer list to variadic function}} } namespace PR11131 { struct S; S &getS(); int f(...); void g() { (void)sizeof(f(getS())); } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post/expr.dynamic.cast/p3-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s struct X { virtual ~X(); }; struct Y : public X { }; struct Z; // expected-note{{forward declaration of 'Z'}} void test(X &x, Y &y, Z &z) { // If T is an rvalue reference type, v shall be an expression having // a complete class type, and the result is an xvalue of the type // referred to by T. Y &&yr0 = dynamic_cast<Y&&>(x); Y &&yr1 = dynamic_cast<Y&&>(static_cast<X&&>(x)); Y &&yr2 = dynamic_cast<Y&&>(z); // expected-error{{'Z' is an incomplete type}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post/expr.const.cast/p1-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // The result of the expression const_cast<T>(v) is of type T. If T is // an lvalue reference to object type, the result is an lvalue; if T // is an rvalue reference to object type, the result is an xvalue;. unsigned int f(int); struct X {}; template<typename T> T& lvalue(); template<typename T> T&& xvalue(); template<typename T> T prvalue(); void test_classification(const int *ptr, X x) { int *&&ptr0 = const_cast<int *&&>(ptr); int *&&ptr1 = const_cast<int *&&>(xvalue<const int*>()); int *&&ptr2 = const_cast<int *&&>(prvalue<const int*>()); // expected-error {{const_cast from rvalue to reference type 'int *&&'}} X &&ptr3 = const_cast<X&&>(x); X &&ptr4 = const_cast<X&&>(xvalue<X>()); X &&ptr5 = const_cast<X&&>(prvalue<X>()); int *&ptr6 = const_cast<int *&>(ptr); int *&ptr7 = const_cast<int *&>(xvalue<const int*>()); // expected-error {{const_cast from rvalue to reference type 'int *&'}} int *&ptr8 = const_cast<int *&>(prvalue<const int*>()); // expected-error {{const_cast from rvalue to reference type 'int *&'}} X &ptr9 = const_cast<X&>(x); X &ptrA = const_cast<X&>(xvalue<X>()); // expected-error {{const_cast from rvalue to reference type 'X &'}} X &ptrB = const_cast<X&>(prvalue<X>()); // expected-error {{const_cast from rvalue to reference type 'X &'}} } struct A { volatile unsigned ubf : 4; volatile unsigned uv; volatile int sv; void foo(); bool pred(); }; void test(A &a) { unsigned &t0 = const_cast<unsigned&>(a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}} unsigned &t1 = const_cast<unsigned&>(a.foo(), a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}} unsigned &t2 = const_cast<unsigned&>(a.pred() ? a.ubf : a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}} unsigned &t3 = const_cast<unsigned&>(a.pred() ? a.ubf : a.uv); // expected-error {{const_cast from bit-field lvalue to reference type}} unsigned &t4 = const_cast<unsigned&>(a.pred() ? a.ubf : a.sv); // expected-error {{const_cast from rvalue to reference type}} }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post/expr.ref/p3.cpp
// RUN: %clang_cc1 -verify -fsyntax-only %s // expected-no-diagnostics template<typename T> struct Node { int lhs; void splay( ) { Node<T> n[1]; (void)n->lhs; } }; void f() { Node<int> n; return n.splay(); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post/expr.static.cast/p9-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // expected-no-diagnostics enum class EC { ec1 }; void test0(EC ec) { (void)static_cast<bool>(ec); (void)static_cast<bool>(EC::ec1); (void)static_cast<char>(ec); (void)static_cast<char>(EC::ec1); (void)static_cast<int>(ec); (void)static_cast<int>(EC::ec1); (void)static_cast<unsigned long>(ec); (void)static_cast<unsigned long>(EC::ec1); (void)static_cast<float>(ec); (void)static_cast<float>(EC::ec1); (void)static_cast<double>(ec); (void)static_cast<double>(EC::ec1); } namespace PR9107 { enum E {}; template <class _Tp> inline _Tp* addressof(_Tp& __x) { return (_Tp*)&(char&)__x; } void test() { E a; addressof(a); } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.post/expr.static.cast/p3-0x.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s // expected-no-diagnostics // A glvalue of type "cv1 T1" can be cast to type "rvalue reference to // cv2 T2" if "cv2 T2" is reference-compatible with "cv1 T1" (8.5.3). struct A { }; struct B : A { }; template<typename T> T& lvalue(); template<typename T> T&& xvalue(); void test(A &a, B &b) { A &&ar0 = static_cast<A&&>(a); A &&ar1 = static_cast<A&&>(b); A &&ar2 = static_cast<A&&>(lvalue<A>()); A &&ar3 = static_cast<A&&>(lvalue<B>()); A &&ar4 = static_cast<A&&>(xvalue<A>()); A &&ar5 = static_cast<A&&>(xvalue<B>()); const A &&ar6 = static_cast<const A&&>(a); const A &&ar7 = static_cast<const A&&>(b); const A &&ar8 = static_cast<const A&&>(lvalue<A>()); const A &&ar9 = static_cast<const A&&>(lvalue<B>()); const A &&ar10 = static_cast<const A&&>(xvalue<A>()); const A &&ar11 = static_cast<const A&&>(xvalue<B>()); }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s struct global { }; namespace PR10127 { struct outer { struct middle { struct inner { int func(); int i; }; struct inner2 { }; struct inner3 { }; int mfunc(); }; typedef int td_int; }; struct str { operator decltype(outer::middle::inner()) (); operator decltype(outer::middle())::inner2 (); operator decltype(outer())::middle::inner3 (); str(int (decltype(outer::middle::inner())::*n)(), int (decltype(outer::middle())::inner::*o)(), int (decltype(outer())::middle::inner::*p)()); }; decltype(outer::middle::inner()) a; void scope() { a.decltype(outer::middle())::mfunc(); // expected-error{{'PR10127::outer::middle::mfunc' is not a member of class 'decltype(outer::middle::inner())'}} a.decltype(outer::middle::inner())::func(); a.decltype(outer::middle())::inner::func(); a.decltype(outer())::middle::inner::func(); a.decltype(outer())::middle::inner::~inner(); decltype(outer())::middle::inner().func(); } decltype(outer::middle())::inner b; decltype(outer())::middle::inner c; decltype(outer())::fail d; // expected-error{{no type named 'fail' in 'PR10127::outer'}} decltype(outer())::fail::inner e; // expected-error{{no member named 'fail' in 'PR10127::outer'}} decltype()::fail f; // expected-error{{expected expression}} decltype()::middle::fail g; // expected-error{{expected expression}} decltype(int()) h; decltype(int())::PR10127::outer i; // expected-error{{'decltype(int())' (aka 'int') is not a class, namespace, or enumeration}} decltype(int())::global j; // expected-error{{'decltype(int())' (aka 'int') is not a class, namespace, or enumeration}} outer::middle k = decltype(outer())::middle(); outer::middle::inner l = decltype(outer())::middle::inner(); template<typename T> struct templ { typename decltype(T())::middle::inner x; // expected-error{{type 'decltype(int())' (aka 'int') cannot be used prior to '::' because it has no members}} }; template class templ<int>; // expected-note{{in instantiation of template class 'PR10127::templ<int>' requested here}} template class templ<outer>; enum class foo { bar, baz }; foo m = decltype(foo::bar)::baz; enum E { }; struct bar { enum E : decltype(outer())::td_int(4); enum F : decltype(outer())::td_int; enum G : decltype; // expected-error{{expected '(' after 'decltype'}} }; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim/expr.prim.general/p4-0x.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s struct S { S *p = this; // ok decltype(this) q; // expected-error {{invalid use of 'this' outside of a non-static member function}} int arr[sizeof(this)]; // expected-error {{invalid use of 'this' outside of a non-static member function}} int sz = sizeof(this); // ok typedef auto f() -> decltype(this); // expected-error {{invalid use of 'this' outside of a non-static member function}} }; namespace CaptureThis { struct X { int n = 10; int m = [&]{return n + 1; }(); int o = [&]{return this->m + 1; }(); int p = [&]{return [&](int x) { return this->m + x;}(o); }(); }; X x; }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim/expr.prim.general/p12-0x.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s struct S { int *j = &nonexistent; // expected-error {{use of undeclared identifier 'nonexistent'}} int *m = &n; // ok int n = f(); // ok int f(); }; int i = sizeof(S::m); // ok int j = sizeof(S::m + 42); // ok struct T { int n; static void f() { int a[n]; // expected-error {{invalid use of member 'n' in static member function}} int b[sizeof n]; // ok } }; // Make sure the rule for unevaluated operands works correctly with typeid. namespace std { class type_info; } class Poly { virtual ~Poly(); }; const std::type_info& k = typeid(S::m); const std::type_info& m = typeid(*(Poly*)S::m); // expected-error {{invalid use of non-static data member}} const std::type_info& n = typeid(*(Poly*)(0*sizeof S::m)); namespace PR11956 { struct X { char a; }; struct Y { int f() { return sizeof(X::a); } }; // ok struct A { enum E {} E; }; struct B { int f() { return sizeof(A::E); } }; // ok }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify struct A { int &f(int*); float &f(int*) const noexcept; int *ptr; auto g1() noexcept(noexcept(f(ptr))) -> decltype(f(this->ptr)); auto g2() const noexcept(noexcept(f((*this).ptr))) -> decltype(f(ptr)); }; void testA(A &a) { int &ir = a.g1(); float &fr = a.g2(); static_assert(!noexcept(a.g1()), "exception-specification failure"); static_assert(noexcept(a.g2()), "exception-specification failure"); } struct B { char g(); template<class T> auto f(T t) -> decltype(t + g()) { return t + g(); } }; template auto B::f(int t) -> decltype(t + g()); template<typename T> struct C { int &f(T*); float &f(T*) const noexcept; T* ptr; auto g1() noexcept(noexcept(f(ptr))) -> decltype(f(ptr)); auto g2() const noexcept(noexcept(f(((this))->ptr))) -> decltype(f(ptr)); auto g3() noexcept(noexcept(f(this->ptr))) -> decltype(f((*this).ptr)); auto g4() const noexcept(noexcept(f(((this))->ptr))) -> decltype(f(this->ptr)); auto g5() noexcept(noexcept(this->f(ptr))) -> decltype(this->f(ptr)); auto g6() const noexcept(noexcept(this->f(((this))->ptr))) -> decltype(this->f(ptr)); auto g7() noexcept(noexcept(this->f(this->ptr))) -> decltype(this->f((*this).ptr)); auto g8() const noexcept(noexcept(this->f(((this))->ptr))) -> decltype(this->f(this->ptr)); }; void test_C(C<int> ci) { int &ir = ci.g1(); float &fr = ci.g2(); int &ir2 = ci.g3(); float &fr2 = ci.g4(); int &ir3 = ci.g5(); float &fr3 = ci.g6(); int &ir4 = ci.g7(); float &fr4 = ci.g8(); static_assert(!noexcept(ci.g1()), "exception-specification failure"); static_assert(noexcept(ci.g2()), "exception-specification failure"); static_assert(!noexcept(ci.g3()), "exception-specification failure"); static_assert(noexcept(ci.g4()), "exception-specification failure"); static_assert(!noexcept(ci.g5()), "exception-specification failure"); static_assert(noexcept(ci.g6()), "exception-specification failure"); static_assert(!noexcept(ci.g7()), "exception-specification failure"); static_assert(noexcept(ci.g8()), "exception-specification failure"); } namespace PR14263 { template<typename T> struct X { void f(); T f() const; auto g() -> decltype(this->f()) { return f(); } auto g() const -> decltype(this->f()) { return f(); } }; template struct X<int>; } namespace PR10036 { template <class I> void iter_swap(I x, I y) noexcept; template <class T> class A { T t_; public: void swap(A& a) noexcept(noexcept(iter_swap(&t_, &a.t_))); }; void test() { A<int> i, j; i.swap(j); } } namespace PR15290 { template<typename T> class A { T v_; friend int add_to_v(A &t) noexcept(noexcept(v_ + 42)) { return t.v_ + 42; } }; void f() { A<int> t; add_to_v(t); } } namespace Static { struct X1 { int m; // FIXME: This should be accepted. static auto f() -> decltype(m); // expected-error{{'this' cannot be implicitly used in a static member function declaration}} static auto g() -> decltype(this->m); // expected-error{{'this' cannot be used in a static member function declaration}} static int h(); static int i() noexcept(noexcept(m + 2)); // expected-error{{'this' cannot be implicitly used in a static member function declaration}} }; auto X1::h() -> decltype(m) { return 0; } // expected-error{{'this' cannot be implicitly used in a static member function declaration}} template<typename T> struct X2 { int m; T f(T*); static T f(int); auto g(T x) -> decltype(f(x)) { return 0; } }; void test_X2() { X2<int>().g(0); } } namespace PR12564 { struct Base { void bar(Base&) {} }; struct Derived : Base { void foo(Derived& d) noexcept(noexcept(d.bar(d))) {} }; } namespace rdar13473493 { template <typename F> class wrap { public: template <typename... Args> auto operator()(Args&&... args) const -> decltype(wrapped(args...)) // expected-note{{candidate template ignored: substitution failure [with Args = <int>]: use of undeclared identifier 'wrapped'}} { return wrapped(args...); } private: F wrapped; }; void test(wrap<int (*)(int)> w) { w(5); // expected-error{{no matching function for call to object of type 'wrap<int (*)(int)>'}} } }
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify void defargs() { auto l1 = [](int i, int j = 17, int k = 18) { return i + j + k; }; int i1 = l1(1); int i2 = l1(1, 2); int i3 = l1(1, 2, 3); } void defargs_errors() { auto l1 = [](int i, int j = 17, int k) { }; // expected-error{{missing default argument on parameter 'k'}} auto l2 = [](int i, int j = i) {}; // expected-error{{default argument references parameter 'i'}} int foo; auto l3 = [](int i = foo) {}; // expected-error{{default argument references local variable 'foo' of enclosing function}} } struct NonPOD { NonPOD(); NonPOD(const NonPOD&); ~NonPOD(); }; struct NoDefaultCtor { NoDefaultCtor(const NoDefaultCtor&); // expected-note{{candidate constructor}} ~NoDefaultCtor(); }; template<typename T> void defargs_in_template_unused(T t) { auto l1 = [](const T& value = T()) { }; l1(t); } template void defargs_in_template_unused(NonPOD); template void defargs_in_template_unused(NoDefaultCtor); template<typename T> void defargs_in_template_used() { auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}} l1(); // expected-note{{in instantiation of default function argument expression for 'operator()<NoDefaultCtor>' required here}} } template void defargs_in_template_used<NonPOD>(); template void defargs_in_template_used<NoDefaultCtor>(); // expected-note{{in instantiation of function template specialization}}
0
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim
repos/DirectXShaderCompiler/tools/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2-generic-lambda-1y.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y -DCXX1Y // prvalue void prvalue() { auto&& x = [](auto a)->void { }; auto& y = [](auto *a)->void { }; // expected-error{{cannot bind to a temporary of type}} } namespace std { class type_info; } struct P { virtual ~P(); }; void unevaluated_operand(P &p, int i) { //expected-note{{declared here}} // FIXME: this should only emit one error. int i2 = sizeof([](auto a, auto b)->void{}(3, '4')); // expected-error{{lambda expression in an unevaluated operand}} \ // expected-error{{invalid application of 'sizeof'}} const std::type_info &ti1 = typeid([](auto &a) -> P& { static P p; return p; }(i)); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}} const std::type_info &ti2 = typeid([](auto) -> int { return i; }(i)); // expected-error{{lambda expression in an unevaluated operand}}\ // expected-error{{cannot be implicitly captured}}\ // expected-note{{begins here}} }