Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/value-initialization.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 struct A { // expected-warning {{does not declare any constructor to initialize}} const int i; // expected-note{{const member 'i' will never be initialized}} expected-note {{implicitly deleted}} virtual void f() { } }; int main () { (void)A(); // expected-error {{call to implicitly-deleted default constructor}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/local-classes.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics namespace PR6382 { int foo() { goto error; { struct BitPacker { BitPacker() {} }; BitPacker packer; } error: return -1; } } namespace PR6383 { void test (bool gross) { struct compare_and_set { void operator() (const bool inner, const bool gross = false) { // the code } } compare_and_set2; compare_and_set2 (false, gross); } } namespace Templates { template<int Value> void f() { struct Inner { static int getValue() { return Value; } }; } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-deprecated-header.cpp
// RUN: %clang_cc1 -fsyntax-only -fdeprecated-macro -verify %s // RUN: %clang_cc1 -fsyntax-only -Werror %s // expected-warning@+2 {{This file is deprecated.}} #ifdef __DEPRECATED #warning This file is deprecated. #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/constexpr-many-arguments.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s // PR13197 struct type1 { constexpr type1(int a0) : my_data{a0} {} int my_data[1]; }; struct type2 { typedef type1 T; constexpr type2(T a00, T a01, T a02, T a03, T a04, T a05, T a06, T a07, T a08, T a09, T a10, T a11, T a12, T a13, T a14, T a15, T a16, T a17, T a18, T a19, T a20, T a21, T a22) : my_data{a00, a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22} {} type1 my_data[23]; }; struct type3 { constexpr type3(type2 a0, type2 a1) : my_data{a0, a1} {} type2 my_data[2]; }; constexpr type3 g { { {0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, {0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, {0},{0},{0} }, { {0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, {0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, {0},{0},{0} } };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/borland-extensions.cpp
// RUN: %clang_cc1 %s -fsyntax-only -fborland-extensions -triple x86_64-linux-gnu -verify // RUN: %clang_cc1 %s -fsyntax-only -fborland-extensions -triple i686-linux-gnu -Werror // Borland extensions // 1. test -fborland-extensions int dummy_function() { return 0; } // 2. test __pascal // expected-warning@+1 {{calling convention '_pascal' ignored for this target}} int _pascal f2(); // expected-warning@+1 {{calling convention '__pascal' ignored for this target}} float __pascal gi2(int, int); // expected-warning@+1 {{calling convention '__pascal' ignored for this target}} template<typename T> T g2(T (__pascal * const )(int, int)) { return 0; } struct M { // expected-warning@+1 {{calling convention '__pascal' ignored for this target}} int __pascal addP(); // expected-warning@+1 {{calling convention '__pascal' ignored for this target}} float __pascal subtractP(); }; // expected-warning@+1 {{calling convention '__pascal' ignored for this target}} template<typename T> int h2(T (__pascal M::* const )()) { return 0; } void m2() { int i; float f; i = f2(); f = gi2(2, i); f = g2(gi2); i = h2<int>(&M::addP); f = h2(&M::subtractP); } // 3. test other calling conventions int _cdecl fa3(); // expected-warning@+1 {{calling convention '_fastcall' ignored for this target}} int _fastcall fc3(); // expected-warning@+1 {{calling convention '_stdcall' ignored for this target}} int _stdcall fd3(); // 4. test __uuidof() typedef struct _GUID { unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[ 8 ]; } GUID; struct __declspec(uuid("{12345678-1234-1234-1234-123456789abc}")) Foo; struct Data { GUID const* Guid; }; void t4() { unsigned long data; const GUID guid_inl = __uuidof(Foo); Data ata1 = { &guid_inl}; data = ata1.Guid->Data1; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-nodebug.cpp
// RUN: %clang_cc1 %s -std=c++11 -verify -fsyntax-only // Note: most of the 'nodebug' tests are in attr-nodebug.c. // expected-no-diagnostics class c { void t3() __attribute__((nodebug)); }; [[gnu::nodebug]] void f() {}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-undefined-bool-conversion.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-bool-conversion %s // RUN: %clang_cc1 -fsyntax-only -verify -Wno-bool-conversion -Wundefined-bool-conversion %s // RUN: %clang_cc1 -fsyntax-only -verify -Wbool-conversion %s void test1(int &x) { if (x == 1) { } if (&x) { } // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (!&x) { } // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} } class test2 { test2() : x(y) {} void foo() { if (this) { } // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; pointer may be assumed to always convert to true}} if (!this) { } // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; pointer may be assumed to always convert to true}} } void bar() { if (x == 1) { } if (&x) { } // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (!&x) { } // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} } int &x; int y; }; namespace function_return_reference { int& get_int(); // expected-note@-1 3{{'get_int' returns a reference}} class B { public: static int &stat(); // expected-note@-1 3{{'stat' returns a reference}} int &get(); // expected-note@-1 6{{'get' returns a reference}} }; void test() { if (&get_int()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (&(get_int())) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (!&get_int()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (&B::stat()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (&(B::stat())) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (!&B::stat()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} B b; if (&b.get()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (&(b.get())) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (!&b.get()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} B* b_ptr = &b; if (&b_ptr->get()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (&(b_ptr->get())) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (!&b_ptr->get()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} int& (B::*m_ptr)() = &B::get; if (&(b.*m_ptr)()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (&((b.*m_ptr)())) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (!&(b.*m_ptr)()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} int& (*f_ptr)() = &get_int; if (&(*f_ptr)()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (&((*f_ptr)())) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} if (!&(*f_ptr)()) {} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} } } namespace macros { #define assert(x) if (x) {} #define zero_on_null(x) ((x) ? *(x) : 0) void test(int &x) { // TODO: warn on assert(&x) but not on zero_on_null(&x) zero_on_null(&x); assert(zero_on_null(&x)); assert(&x); assert(&x && "Expecting valid reference"); // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}} } class S { void test() { assert(this); assert(this && "Expecting invalid reference"); // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; pointer may be assumed to always convert to true}} } }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/printf-cstr.cpp
// RUN: %clang_cc1 -fsyntax-only -Wformat -verify %s -Wno-error=non-pod-varargs #include <stdarg.h> extern "C" { extern int printf(const char *restrict, ...); extern int sprintf(char *, const char *restrict, ...); } class HasCStr { const char *str; public: HasCStr(const char *s): str(s) { } const char *c_str() {return str;} }; class HasNoCStr { const char *str; public: HasNoCStr(const char *s): str(s) { } const char *not_c_str() {return str;} }; extern const char extstr[16]; void pod_test() { char str[] = "test"; char dest[32]; char formatString[] = "non-const %s %s"; HasCStr hcs(str); HasNoCStr hncs(str); int n = 10; printf("%d: %s\n", n, hcs.c_str()); printf("%d: %s\n", n, hcs); // expected-warning{{cannot pass non-POD object of type 'HasCStr' to variadic function; expected type from format string was 'char *'}} expected-note{{did you mean to call the c_str() method?}} printf("%d: %s\n", n, hncs); // expected-warning{{cannot pass non-POD object of type 'HasNoCStr' to variadic function; expected type from format string was 'char *'}} sprintf(str, "%d: %s", n, hcs); // expected-warning{{cannot pass non-POD object of type 'HasCStr' to variadic function; expected type from format string was 'char *'}} expected-note{{did you mean to call the c_str() method?}} printf(formatString, hcs, hncs); // expected-warning{{cannot pass object of non-POD type 'HasCStr' through variadic function}} expected-warning{{cannot pass object of non-POD type 'HasNoCStr' through variadic function}} printf(extstr, hcs, n); // expected-warning{{cannot pass object of non-POD type 'HasCStr' through variadic function}} } struct Printf { Printf(); Printf(const Printf&); Printf(const char *,...) __attribute__((__format__(__printf__,2,3))); }; void constructor_test() { const char str[] = "test"; HasCStr hcs(str); Printf p("%s %d %s", str, 10, 10); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}} Printf q("%s %d", hcs, 10); // expected-warning {{cannot pass non-POD object of type 'HasCStr' to variadic constructor; expected type from format string was 'char *'}} expected-note{{did you mean to call the c_str() method?}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-enum-compare.cpp
// RUN: %clang_cc1 %s -fsyntax-only -verify enum Foo { FooA, FooB, FooC }; enum Bar { BarD, BarE, BarF }; enum { AnonAA = 42, AnonAB = 43 }; enum { AnonBA = 44, AnonBB = 45 }; namespace name1 { enum Foo {F1, F2, F3}; enum Baz {B1, B2, B3}; } namespace name2 { enum Baz {B1, B2, B3}; } using name1::Baz; using name1::B1; using name2::B2; typedef name1::Foo oneFoo; typedef name1::Foo twoFoo; Foo getFoo(); Bar getBar(); void test () { Foo x = FooA; Bar y = BarD; Baz z = name1::B3; name1::Foo a; oneFoo b; twoFoo c; while (x == FooA); while (y == BarD); while (a == name1::F1); while (z == name1::B2); while (a == b); while (a == c); while (b == c); while (B1 == name1::B2); while (B2 == name2::B1); while (x == AnonAA); // expected-warning {{comparison of constant 'AnonAA' (42) with expression of type 'Foo' is always false}} while (AnonBB == y); // expected-warning {{comparison of constant 'AnonBB' (45) with expression of type 'Bar' is always false}} while (AnonAA == AnonAB); while (AnonAB == AnonBA); while (AnonBB == AnonAA); while ((x) == FooA); while ((y) == BarD); while ((a) == name1::F1); while (z == (name1::B2)); while (a == (b)); while (a == (c)); while ((b) == (c)); while ((B1) == (name1::B2)); while ((B2) == (name2::B1)); while (((x)) == FooA); while ((y) == (BarD)); while ((a) == (name1::F1)); while (z == (name1::B2)); while ((a) == ((((b))))); while (((a)) == (c)); while ((b) == (((c)))); while ((((((B1))))) == (((name1::B2)))); while (B2 == ((((((name2::B1))))))); while (B1 == B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while (name1::B2 == name2::B3); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while (z == name2::B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while (((((B1)))) == B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while (name1::B2 == (name2::B3)); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while (z == ((((name2::B2))))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while ((((B1))) == (((B2)))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while ((name1::B2) == (((name2::B3)))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while ((((z))) == (name2::B2)); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} while (x == a); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'name1::Foo')}} while (x == b); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'oneFoo' (aka 'name1::Foo'))}} while (x == c); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'twoFoo' (aka 'name1::Foo'))}} while (x == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (getFoo() < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (FooB < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (x < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} while (y == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y < FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD <FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (y < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (BarD < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() < FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} while (getBar() < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/no-implicit-builtin-decls.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s void f() { void *p = malloc(sizeof(int) * 10); // expected-error{{use of undeclared identifier 'malloc'}} } int malloc(double);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/nested-name-spec-locations.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // Note: the formatting in this test case is intentionally funny, with // nested-name-specifiers stretched out vertically so that we can // match up diagnostics per-line and still verify that we're getting // good source-location information. namespace outer { namespace inner { template<typename T> struct X0 { }; } } template<typename T> struct add_reference { typedef T& type; }; namespace outer_alias = outer; template<typename T> struct UnresolvedUsingValueDeclTester { using outer::inner::X0< typename add_reference<T>::type * // expected-error{{declared as a pointer to a reference of type}} >::value; }; UnresolvedUsingValueDeclTester<int> UnresolvedUsingValueDeclCheck; // expected-note{{in instantiation of template class}} template<typename T> struct UnresolvedUsingTypenameDeclTester { using outer::inner::X0< typename add_reference<T>::type * // expected-error{{declared as a pointer to a reference of type}} >::value; }; UnresolvedUsingTypenameDeclTester<int> UnresolvedUsingTypenameDeclCheck; // expected-note{{in instantiation of template class}} template<typename T, typename U> struct PseudoDestructorExprTester { void f(T *t) { t->T::template Inner<typename add_reference<U>::type * // expected-error{{as a pointer to a reference of type}} >::Blarg::~Blarg(); } }; struct HasInnerTemplate { template<typename T> struct Inner; typedef HasInnerTemplate T; }; void PseudoDestructorExprCheck( PseudoDestructorExprTester<HasInnerTemplate, float> tester) { tester.f(0); // expected-note{{in instantiation of member function}} } template<typename T> struct DependentScopedDeclRefExpr { void f() { outer_alias::inner::X0<typename add_reference<T>::type * // expected-error{{as a pointer to a reference of type}} >::value = 17; } }; void DependentScopedDeclRefExprCheck(DependentScopedDeclRefExpr<int> t) { t.f(); // expected-note{{in instantiation of member function}} } template<typename T> struct TypenameTypeTester { typedef typename outer::inner::X0< typename add_reference<T>::type * // expected-error{{declared as a pointer to a reference of type}} >::type type; }; TypenameTypeTester<int> TypenameTypeCheck; // expected-note{{in instantiation of template class}} template<typename T, typename U> struct DependentTemplateSpecializationTypeTester { typedef typename T::template apply<typename add_reference<U>::type * // expected-error{{declared as a pointer to a reference of type}} >::type type; }; struct HasApply { template<typename T> struct apply { typedef T type; }; }; DependentTemplateSpecializationTypeTester<HasApply, int> DTSTCheck; // expected-note{{in instantiation of template class}} template<typename T, typename U> struct DependentTemplateSpecializationTypeTester2 { typedef typename T::template apply<typename add_reference<U>::type * // expected-error{{declared as a pointer to a reference of type}} > type; }; DependentTemplateSpecializationTypeTester2<HasApply, int> DTSTCheck2; // expected-note{{in instantiation of template class}} template<typename T, typename U> struct DependentTemplateSpecializationTypeTester3 : T::template apply<typename add_reference<U>::type * // expected-error{{declared as a pointer to a reference of type}} > {}; DependentTemplateSpecializationTypeTester3<HasApply, int> DTSTCheck3; // expected-note{{in instantiation of template class}} template<typename T, typename U> struct DependentTemplateSpecializationTypeTester4 { typedef class T::template apply<typename add_reference<U>::type * // expected-error{{declared as a pointer to a reference of type}} > type; }; DependentTemplateSpecializationTypeTester4<HasApply, int> DTSTCheck4; // expected-note{{in instantiation of template class}} template<template<class T> class TTP> struct AcceptedTemplateTemplateParameter { }; template<typename T, typename U> struct DependentTemplateTemplateArgumentTester { typedef AcceptedTemplateTemplateParameter< T:: template apply< typename add_reference<U>::type * // expected-error{{declared as a pointer to a reference of type}} >:: template X> type; }; DependentTemplateTemplateArgumentTester<HasApply, int> DTTACheck; // expected-note{{in instantiation of template class}} namespace PR9388 { namespace std { template<typename T> class vector { }; } template<typename T> static void foo(std::vector<T*> &V) { __PRETTY_FUNCTION__; // expected-warning{{expression result unused}} } void bar(std::vector<int*> &Blocks) { foo(Blocks); // expected-note{{in instantiation of}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/type-dependent-exprs.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s class X { public: virtual int f(); }; void g(int); // expected-note{{candidate function}} template<typename T> T f(T x) { (void)(x + 0); (void)T(0); (void)(x += 0); (void)(x? x : x); (void)static_cast<int>(x); (void)reinterpret_cast<int>(x); (void)dynamic_cast<X*>(&x); (void)const_cast<int>(x); return g(x); h(x); // h is a dependent name g(1, 1); // expected-error{{no matching function for call}} h(1); // expected-error{{use of undeclared identifier 'h'}} return 0; } // This one entered into an infinite loop. template <unsigned long N> void rdar8520617() { if (N > 1) { } } int f2() { rdar8520617<0>(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/member-pointer-ms.cpp
// RUN: %clang_cc1 -std=c++11 -fms-compatibility -fsyntax-only -triple=i386-pc-win32 -verify -DVMB %s // RUN: %clang_cc1 -std=c++11 -fms-compatibility -fsyntax-only -triple=x86_64-pc-win32 -verify -DVMB %s // RUN: %clang_cc1 -std=c++11 -fms-compatibility -fsyntax-only -triple=x86_64-pc-win32 -verify -DVMV -fms-memptr-rep=virtual %s // // This file should also give no diagnostics when run through cl.exe from MSVS // 2012, which supports C++11 and static_assert. It should pass for both 64-bit // and 32-bit x86. // // Test the size of various member pointer combinations: // - complete and incomplete // - single, multiple, and virtual inheritance (and unspecified for incomplete) // - data and function pointers // - templated with declared specializations with annotations // - template that can be instantiated // http://llvm.org/PR12070 struct Foo { typedef int Foo::*FooInt; int f; }; #ifdef VMB enum { kSingleDataAlign = 1 * sizeof(int), kSingleFunctionAlign = 1 * sizeof(void *), kMultipleDataAlign = 1 * sizeof(int), // Everything with more than 1 field is 8 byte aligned, except virtual data // member pointers on x64 (ugh). kMultipleFunctionAlign = 8, #ifdef _M_X64 kVirtualDataAlign = 4, #else kVirtualDataAlign = 8, #endif kVirtualFunctionAlign = 8, kUnspecifiedDataAlign = 8, kUnspecifiedFunctionAlign = 8, kSingleDataSize = 1 * sizeof(int), kSingleFunctionSize = 1 * sizeof(void *), kMultipleDataSize = 1 * sizeof(int), kMultipleFunctionSize = 2 * sizeof(void *), kVirtualDataSize = 2 * sizeof(int), kVirtualFunctionSize = 2 * sizeof(int) + 1 * sizeof(void *), kUnspecifiedDataSize = 3 * sizeof(int), kUnspecifiedFunctionSize = 2 * sizeof(int) + 2 * sizeof(void *), }; #elif VMV enum { // Everything with more than 1 field is 8 byte aligned, except virtual data // member pointers on x64 (ugh). #ifdef _M_X64 kVirtualDataAlign = 4, #else kVirtualDataAlign = 8, #endif kMultipleDataAlign = kVirtualDataAlign, kSingleDataAlign = kVirtualDataAlign, kUnspecifiedFunctionAlign = 8, kVirtualFunctionAlign = kUnspecifiedFunctionAlign, kMultipleFunctionAlign = kUnspecifiedFunctionAlign, kSingleFunctionAlign = kUnspecifiedFunctionAlign, kUnspecifiedDataSize = 3 * sizeof(int), kVirtualDataSize = kUnspecifiedDataSize, kMultipleDataSize = kUnspecifiedDataSize, kSingleDataSize = kUnspecifiedDataSize, kUnspecifiedFunctionSize = 2 * sizeof(int) + 2 * sizeof(void *), kVirtualFunctionSize = kUnspecifiedFunctionSize, kMultipleFunctionSize = kUnspecifiedFunctionSize, kSingleFunctionSize = kUnspecifiedFunctionSize, }; #else #error "test doesn't yet support this mode!" #endif // incomplete types #ifdef VMB class __single_inheritance IncSingle; class __multiple_inheritance IncMultiple; class __virtual_inheritance IncVirtual; #else class IncSingle; class IncMultiple; class IncVirtual; #endif static_assert(sizeof(int IncSingle::*) == kSingleDataSize, ""); static_assert(sizeof(int IncMultiple::*) == kMultipleDataSize, ""); static_assert(sizeof(int IncVirtual::*) == kVirtualDataSize, ""); static_assert(sizeof(void (IncSingle::*)()) == kSingleFunctionSize, ""); static_assert(sizeof(void (IncMultiple::*)()) == kMultipleFunctionSize, ""); static_assert(sizeof(void (IncVirtual::*)()) == kVirtualFunctionSize, ""); static_assert(__alignof(int IncSingle::*) == __alignof(void *), ""); static_assert(__alignof(int IncMultiple::*) == __alignof(void *), ""); static_assert(__alignof(int IncVirtual::*) == __alignof(void *), ""); static_assert(__alignof(void (IncSingle::*)()) == __alignof(void *), ""); static_assert(__alignof(void (IncMultiple::*)()) == __alignof(void *), ""); static_assert(__alignof(void (IncVirtual::*)()) == __alignof(void *), ""); // An incomplete type with an unspecified inheritance model seems to take one // more slot than virtual. class IncUnspecified; static_assert(sizeof(int IncUnspecified::*) == kUnspecifiedDataSize, ""); static_assert(sizeof(void (IncUnspecified::*)()) == kUnspecifiedFunctionSize, ""); // complete types struct B1 { }; struct B2 { }; struct Single { }; struct Multiple : B1, B2 { }; struct Virtual : virtual B1 { }; static_assert(sizeof(int Single::*) == kSingleDataSize, ""); static_assert(sizeof(int Multiple::*) == kMultipleDataSize, ""); static_assert(sizeof(int Virtual::*) == kVirtualDataSize, ""); static_assert(sizeof(void (Single::*)()) == kSingleFunctionSize, ""); static_assert(sizeof(void (Multiple::*)()) == kMultipleFunctionSize, ""); static_assert(sizeof(void (Virtual::*)()) == kVirtualFunctionSize, ""); // Test both declared and defined templates. template <typename T> class X; #ifdef VMB template <> class __single_inheritance X<IncSingle>; template <> class __multiple_inheritance X<IncMultiple>; template <> class __virtual_inheritance X<IncVirtual>; #else template <> class X<IncSingle>; template <> class X<IncMultiple>; template <> class X<IncVirtual>; #endif // Don't declare X<IncUnspecified>. static_assert(sizeof(int X<IncSingle>::*) == kSingleDataSize, ""); static_assert(sizeof(int X<IncMultiple>::*) == kMultipleDataSize, ""); static_assert(sizeof(int X<IncVirtual>::*) == kVirtualDataSize, ""); static_assert(sizeof(int X<IncUnspecified>::*) == kUnspecifiedDataSize, ""); static_assert(sizeof(void (X<IncSingle>::*)()) == kSingleFunctionSize, ""); static_assert(sizeof(void (X<IncMultiple>::*)()) == kMultipleFunctionSize, ""); static_assert(sizeof(void (X<IncVirtual>::*)()) == kVirtualFunctionSize, ""); static_assert(sizeof(void (X<IncUnspecified>::*)()) == kUnspecifiedFunctionSize, ""); template <typename T> struct Y : T { }; static_assert(sizeof(int Y<Single>::*) == kSingleDataSize, ""); static_assert(sizeof(int Y<Multiple>::*) == kMultipleDataSize, ""); static_assert(sizeof(int Y<Virtual>::*) == kVirtualDataSize, ""); static_assert(sizeof(void (Y<Single>::*)()) == kSingleFunctionSize, ""); static_assert(sizeof(void (Y<Multiple>::*)()) == kMultipleFunctionSize, ""); static_assert(sizeof(void (Y<Virtual>::*)()) == kVirtualFunctionSize, ""); struct A { int x; void bar(); }; struct B : A { virtual void foo(); }; static_assert(sizeof(int B::*) == kSingleDataSize, ""); // A non-primary base class uses the multiple inheritance model for member // pointers. static_assert(sizeof(void (B::*)()) == kMultipleFunctionSize, ""); struct AA { int x; virtual void foo(); }; struct BB : AA { void bar(); }; struct CC : BB { virtual void baz(); }; static_assert(sizeof(void (CC::*)()) == kSingleFunctionSize, ""); // We start out unspecified. struct ForwardDecl1; struct ForwardDecl2; // Re-declare to force us to iterate decls when adding attributes. struct ForwardDecl1; struct ForwardDecl2; typedef int ForwardDecl1::*MemPtr1; typedef int ForwardDecl2::*MemPtr2; MemPtr1 variable_forces_sizing; struct ForwardDecl1 : B { virtual void foo(); }; struct ForwardDecl2 : B { virtual void foo(); }; static_assert(sizeof(variable_forces_sizing) == kUnspecifiedDataSize, ""); static_assert(sizeof(MemPtr1) == kUnspecifiedDataSize, ""); static_assert(sizeof(MemPtr2) == kSingleDataSize, ""); struct MemPtrInBody { typedef int MemPtrInBody::*MemPtr; int a; operator MemPtr() const { return a ? &MemPtrInBody::a : 0; } }; static_assert(sizeof(MemPtrInBody::MemPtr) == kSingleDataSize, ""); // Passing a member pointer through a template should get the right size. template<typename T> struct SingleTemplate; template<typename T> struct SingleTemplate<void (T::*)(void)> { static_assert(sizeof(int T::*) == kSingleDataSize, ""); static_assert(sizeof(void (T::*)()) == kSingleFunctionSize, ""); }; template<typename T> struct UnspecTemplate; template<typename T> struct UnspecTemplate<void (T::*)(void)> { static_assert(sizeof(int T::*) == kUnspecifiedDataSize, ""); static_assert(sizeof(void (T::*)()) == kUnspecifiedFunctionSize, ""); }; struct NewUnspecified; SingleTemplate<void (IncSingle::*)()> tmpl_single; UnspecTemplate<void (NewUnspecified::*)()> tmpl_unspec; struct NewUnspecified { }; static_assert(sizeof(void (NewUnspecified::*)()) == kUnspecifiedFunctionSize, ""); template <typename T> struct MemPtrInTemplate { // We can't require that the template arg be complete until we're // instantiated. int T::*data_ptr; void (T::*func_ptr)(); }; #ifdef VMB int Virtual::*CastTest = reinterpret_cast<int Virtual::*>(&AA::x); // expected-error@-1 {{cannot reinterpret_cast from member pointer type}} #endif namespace ErrorTest { template <typename T, typename U> struct __single_inheritance A; // expected-warning@-1 {{inheritance model ignored on primary template}} template <typename T> struct __multiple_inheritance A<T, T>; // expected-warning@-1 {{inheritance model ignored on partial specialization}} template <> struct __single_inheritance A<int, float>; struct B {}; // expected-note {{B defined here}} struct __multiple_inheritance B; // expected-error{{inheritance model does not match definition}} struct __multiple_inheritance C {}; // expected-error{{inheritance model does not match definition}} // expected-note@-1 {{C defined here}} struct __virtual_inheritance D; struct D : virtual B {}; } #ifdef VMB namespace PR20017 { template <typename T> struct A { int T::*f(); }; struct B; auto a = &A<B>::f; struct B {}; void q() { A<B> b; (b.*a)(); } } #pragma pointers_to_members(full_generality, multiple_inheritance) struct TrulySingleInheritance; static_assert(sizeof(int TrulySingleInheritance::*) == kMultipleDataSize, ""); #pragma pointers_to_members(best_case) // This definition shouldn't conflict with the increased generality that the // multiple_inheritance model gave to TrulySingleInheritance. struct TrulySingleInheritance {}; // Even if a definition proceeds the first mention of a pointer to member, we // still give the record the fully general representation. #pragma pointers_to_members(full_generality, virtual_inheritance) struct SingleInheritanceAsVirtualAfterPragma {}; static_assert(sizeof(int SingleInheritanceAsVirtualAfterPragma::*) == 12, ""); #pragma pointers_to_members(best_case) // The above holds even if the pragma comes after the definition. struct SingleInheritanceAsVirtualBeforePragma {}; #pragma pointers_to_members(virtual_inheritance) static_assert(sizeof(int SingleInheritanceAsVirtualBeforePragma::*) == 12, ""); #pragma pointers_to_members(single) // expected-error{{unexpected 'single'}} #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/user-defined-conversions.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct X { operator bool(); }; int& f(bool); float& f(int); void f_test(X x) { int& i1 = f(x); } struct Y { operator short(); operator float(); }; void g(int); void g_test(Y y) { g(y); short s; s = y; } struct A { }; struct B : A { }; struct C { operator B&(); }; // Test reference binding via an lvalue conversion function. void h(volatile A&); void h_test(C c) { h(c); } // Test conversion followed by copy-construction struct FunkyDerived; struct Base { Base(const FunkyDerived&); }; struct Derived : Base { }; struct FunkyDerived : Base { }; struct ConvertibleToBase { operator Base(); }; struct ConvertibleToDerived { operator Derived(); }; struct ConvertibleToFunkyDerived { operator FunkyDerived(); }; void test_conversion(ConvertibleToBase ctb, ConvertibleToDerived ctd, ConvertibleToFunkyDerived ctfd) { Base b1 = ctb; Base b2(ctb); Base b3 = ctd; Base b4(ctd); Base b5 = ctfd; } struct X1 { X1(X1&); // expected-note{{candidate constructor not viable: expects an l-value for 1st argument}} }; struct X2 { operator X1(); }; int &f(X1); float &f(...); void g(X2 b) { int &ir = f(b); // expected-error{{no viable constructor copying parameter of type 'X1'}} } namespace rdar10202900 { class A { public: A(); private: A(int i); // expected-note{{declared private here}} }; void testA(A a) { int b = 10; a = b; // expected-error{{calling a private constructor of class 'rdar10202900::A'}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/rval-references-examples.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s template<typename T> class unique_ptr { T *ptr; unique_ptr(const unique_ptr&) = delete; // expected-note 3{{'unique_ptr' has been explicitly marked deleted here}} unique_ptr &operator=(const unique_ptr&) = delete; // expected-note{{candidate function has been explicitly deleted}} public: unique_ptr() : ptr(0) { } unique_ptr(unique_ptr &&other) : ptr(other.ptr) { other.ptr = 0; } explicit unique_ptr(T *ptr) : ptr(ptr) { } ~unique_ptr() { delete ptr; } unique_ptr &operator=(unique_ptr &&other) { // expected-note{{candidate function not viable: no known conversion from 'unique_ptr<int>' to 'unique_ptr<int> &&' for 1st argument}} if (this == &other) return *this; delete ptr; ptr = other.ptr; other.ptr = 0; return *this; } }; template<typename T> struct remove_reference { typedef T type; }; template<typename T> struct remove_reference<T&> { typedef T type; }; template<typename T> struct remove_reference<T&&> { typedef T type; }; template <class T> typename remove_reference<T>::type&& move(T&& t) { return static_cast<typename remove_reference<T>::type&&>(t); } template <class T> T&& forward(typename remove_reference<T>::type& t) { return static_cast<T&&>(t); } template <class T> T&& forward(typename remove_reference<T>::type&& t) { return static_cast<T&&>(t); } template<typename T, typename ...Args> unique_ptr<T> make_unique_ptr(Args &&...args) { return unique_ptr<T>(new T(forward<Args>(args)...)); } template<typename T> void accept_unique_ptr(unique_ptr<T>); // expected-note{{passing argument to parameter here}} unique_ptr<int> test_unique_ptr() { // Simple construction unique_ptr<int> p; unique_ptr<int> p1(new int); // Move construction unique_ptr<int> p2(make_unique_ptr<int>(17)); unique_ptr<int> p3 = make_unique_ptr<int>(17); // Copy construction (failures) unique_ptr<int> p4(p); // expected-error{{call to deleted constructor of 'unique_ptr<int>'}} unique_ptr<int> p5 = p; // expected-error{{call to deleted constructor of 'unique_ptr<int>'}} // Move assignment p2 = move(p); p2 = make_unique_ptr<int>(0); // Copy assignment (failures); p2 = p3; // expected-error{{overload resolution selected deleted operator '='}} // Implicit copies accept_unique_ptr(make_unique_ptr<double>(0.0)); accept_unique_ptr(move(p2)); // Implicit copies (failures); accept_unique_ptr(p); // expected-error{{call to deleted constructor of 'unique_ptr<int>'}} return p; } namespace perfect_forwarding { struct A { }; struct F0 { void operator()(A&, const A&, A&&, const A&&, A&&, const A&&); // expected-note{{candidate function not viable: 5th argument ('const perfect_forwarding::A') would lose const qualifier}} }; template<typename F, typename ...Args> void forward(F f, Args &&...args) { f(static_cast<Args&&>(args)...); // expected-error{{no matching function for call to object of type 'perfect_forwarding::F0'}} } template<typename T> T get(); void test_forward() { forward(F0(), get<A&>(), get<A const&>(), get<A>(), get<const A>(), get<A&&>(), get<const A&&>()); forward(F0(), get<A&>(), get<A const&>(), get<A>(), get<const A>(), // expected-note{{in instantiation of function template specialization 'perfect_forwarding::forward<perfect_forwarding::F0, perfect_forwarding::A &, const perfect_forwarding::A &, perfect_forwarding::A, const perfect_forwarding::A, const perfect_forwarding::A, const perfect_forwarding::A>' requested here}} get<const A&&>(), get<const A&&>()); } };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/operator-arrow-depth.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -DMAX=128 -foperator-arrow-depth 128 // RUN: %clang_cc1 -fsyntax-only -verify %s -DMAX=2 -foperator-arrow-depth 2 // RUN: %clang -fsyntax-only -Xclang -verify %s -DMAX=10 -foperator-arrow-depth=10 template<int N> struct B; template<int N> struct A { B<N> operator->(); // expected-note +{{'operator->' declared here produces an object of type 'B<}} }; template<int N> struct B { A<N-1> operator->(); // expected-note +{{'operator->' declared here produces an object of type 'A<}} #if MAX != 2 // expected-note-re@-2 {{(skipping {{120|2}} 'operator->'s in backtrace)}} #endif }; struct X { int n; }; template<> struct B<1> { X *operator->(); }; A<MAX/2> good; int n = good->n; B<MAX/2 + 1> bad; int m = bad->n; // expected-error-re {{use of 'operator->' on type 'B<{{2|10|128}} / 2 + 1>' would invoke a sequence of more than {{2|10|128}} 'operator->' calls}} // expected-note@-1 {{use -foperator-arrow-depth=N to increase 'operator->' limit}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/dynamic-cast.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct A {}; struct B : A {}; struct C : B {}; struct D : private A {}; struct E : A {}; struct F : B, E {}; struct Incomplete; // expected-note 2 {{forward declaration of 'Incomplete'}} struct Poly { virtual void f(); }; struct PolyDerived : Poly { }; void basic_bad() { // ptr -> nonptr (void)dynamic_cast<A>((A*)0); // expected-error {{'A' is not a reference or pointer}} // nonptr -> ptr (void)dynamic_cast<A*>(0); // expected-error {{'int' is not a pointer}} // ptr -> noncls (void)dynamic_cast<int*>((A*)0); // expected-error {{'int' is not a class}} // noncls -> ptr (void)dynamic_cast<A*>((int*)0); // expected-error {{'int' is not a class}} // ref -> noncls (void)dynamic_cast<int&>(*((A*)0)); // expected-error {{'int' is not a class}} // noncls -> ref (void)dynamic_cast<A&>(*((int*)0)); // expected-error {{'int' is not a class}} // ptr -> incomplete (void)dynamic_cast<Incomplete*>((A*)0); // expected-error {{'Incomplete' is an incomplete type}} // incomplete -> ptr (void)dynamic_cast<A*>((Incomplete*)0); // expected-error {{'Incomplete' is an incomplete type}} // rvalue -> lvalue (void)dynamic_cast<A&>(A()); // expected-error {{dynamic_cast from rvalue to reference type 'A &'}} } void same() { (void)dynamic_cast<A*>((A*)0); (void)dynamic_cast<A&>(*((A*)0)); } void up() { (void)dynamic_cast<A*>((B*)0); (void)dynamic_cast<A&>(*((B*)0)); (void)dynamic_cast<A*>((C*)0); (void)dynamic_cast<A&>(*((C*)0)); // Inaccessible //(void)dynamic_cast<A*>((D*)0); //(void)dynamic_cast<A&>(*((D*)0)); // Ambiguous (void)dynamic_cast<A*>((F*)0); // expected-error {{ambiguous conversion from derived class 'F' to base class 'A':\n struct F -> struct B -> struct A\n struct F -> struct E -> struct A}} (void)dynamic_cast<A&>(*((F*)0)); // expected-error {{ambiguous conversion from derived class 'F' to base class 'A':\n struct F -> struct B -> struct A\n struct F -> struct E -> struct A}} } void poly() { (void)dynamic_cast<A*>((Poly*)0); (void)dynamic_cast<A&>(*((Poly*)0)); (void)dynamic_cast<A*>((PolyDerived*)0); (void)dynamic_cast<A&>(*((PolyDerived*)0)); // Not polymorphic source (void)dynamic_cast<Poly*>((A*)0); // expected-error {{'A' is not polymorphic}} (void)dynamic_cast<PolyDerived&>(*((A*)0)); // expected-error {{'A' is not polymorphic}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/static-array-member.cpp
// RUN: %clang_cc1 -fsyntax-only %s struct X0 { static int array[]; int x; int y; }; int X0::array[sizeof(X0) * 2]; template<typename T, int N> struct X1 { static T array[]; }; template<typename T, int N> T X1<T, N>::array[N];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-cxx0x-fixit.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -std=c++11 %s 2>&1 | FileCheck %s [[noreturn()]] void f(); // expected-error {{attribute 'noreturn' cannot have an argument list}} \ // CHECK: fix-it:"{{.*}}":{4:11-4:13}:""
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR20705.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s template <typename T> struct X {}; auto b = []() { struct S { static typename X<decltype(int)>::type Run(){}; // expected-error@-1 4{{}} }; return 5; }(); template <typename T1, typename T2> class PC { }; template <typename T> class P { static typename PC<T, Invalid>::Type Foo(); // expected-error@-1 4{{}} };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-new-overaligned-3.cpp
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -Wover-aligned %s -isystem %S/Inputs -verify // This test ensures that we still get the warning even if we #include <new> // where the header here simulates <new>. #include <warn-new-overaligned-3.h> namespace test1 { struct Test { template <typename T> struct SeparateCacheLines { T data; } __attribute__((aligned(256))); SeparateCacheLines<int> high_contention_data[10]; }; void helper() { Test t; new Test; // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}} new Test[10]; // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}} } } namespace test2 { struct helper { int i __attribute__((aligned(256))); }; struct Placement { Placement() { new (d) helper(); } helper *d; }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/condition.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s void test() { int x; if (x) ++x; if (int x=0) ++x; typedef int arr[10]; while (arr x={0}) ; // expected-error {{an array type is not allowed here}} while (int f()=0) ; // expected-error {{a function type is not allowed here}} struct S {} s; if (s) ++x; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} while (struct S x=s) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} do ; while (s); // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} for (;s;) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}} while (struct NewS *x=0) ; while (struct S {} *x=0) ; // expected-error {{types may not be defined in conditions}} while (struct {} *x=0) ; // expected-error {{types may not be defined in conditions}} switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} if (int x=0) { // expected-note 2 {{previous definition is here}} int x; // expected-error {{redefinition of 'x'}} } else int x; // expected-error {{redefinition of 'x'}} while (int x=0) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} while (int x=0) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} for (int x; int x=0; ) ; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} for (int x; ; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} for (; int x=0; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} for (; int x=0; ) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} switch (int x=0) { default: int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} } int* get_int_ptr(); void test2() { float *ip; if (int *ip = ip) { } } // Make sure we do function/array decay. void test3() { if ("help") (void) 0; if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}} \ expected-note {{prefix with the address-of operator to silence this warning}} (void) 0; } void test4(bool (&x)(void)) { while (x); } template <class> void test5() { if (struct S {}* p = 0) // expected-error {{types may not be defined in conditions}} ; } void test5_inst() { test5<int>(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/pascal-strings.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -fpascal-strings const wchar_t *pascalString = L"\pThis is a Pascal string"; unsigned char a[3] = "\pa"; unsigned char b[3] = "\pab"; unsigned char c[3] = "\pabc"; // expected-error {{initializer-string for char array is too long}} unsigned char d[3] = ("\pab"); unsigned char e[3] = ("\pabc"); // expected-error {{initializer-string for char array is too long}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/ambiguous-conversion-show-overload.cpp
// RUN: not %clang_cc1 -fsyntax-only -fshow-overloads=best -fno-caret-diagnostics %s 2>&1 | FileCheck %s struct S { S(void*); S(char*); S(unsigned char*); S(signed char*); S(unsigned short*); S(signed short*); S(unsigned int*); S(signed int*); }; void f(const S& s); void g() { f(0); } // CHECK: {{conversion from 'int' to 'const S' is ambiguous}} // CHECK-NEXT: {{candidate constructor}} // CHECK-NEXT: {{candidate constructor}} // CHECK-NEXT: {{candidate constructor}} // CHECK-NEXT: {{candidate constructor}} // CHECK-NEXT: {{remaining 4 candidates omitted; pass -fshow-overloads=all to show them}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/constructor.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s typedef int INT; class Foo { Foo(); (Foo)(float) { } explicit Foo(int); // expected-note {{previous declaration is here}} Foo(const Foo&); ((Foo))(INT); // expected-error{{cannot be redeclared}} Foo(Foo foo, int i = 17, int j = 42); // expected-error{{copy constructor must pass its first argument by reference}} static Foo(short, short); // expected-error{{constructor cannot be declared 'static'}} virtual Foo(double); // expected-error{{constructor cannot be declared 'virtual'}} Foo(long) const; // expected-error{{'const' qualifier is not allowed on a constructor}} int Foo(int, int); // expected-error{{constructor cannot have a return type}} volatile Foo(float); // expected-error{{constructor cannot have a return type}} }; Foo::Foo(const Foo&) { } typedef struct { int version; } Anon; extern const Anon anon; extern "C" const Anon anon2; // PR3188: The extern declaration complained about not having an appropriate // constructor. struct x; extern x a; // A similar case. struct y { y(int); }; extern y b; struct Length { Length l() const { return *this; } }; // <rdar://problem/6815988> struct mmst_reg{ char mmst_reg[10]; }; // PR3948 namespace PR3948 { // PR3948 class a { public: int b(int a()); }; int x(); void y() { a z; z.b(x); } } namespace A { struct S { S(); S(int); void f1(); void f2(); operator int (); ~S(); }; } A::S::S() {} void A::S::f1() {} struct S {}; A::S::S(int) {} void A::S::f2() {} A::S::operator int() { return 1; } A::S::~S() {}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/constexpr-nqueens.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s typedef unsigned long uint64_t; struct Board { uint64_t State; bool Failed; constexpr Board() : State(0), Failed(false) {} constexpr Board(const Board &O) : State(O.State), Failed(O.Failed) {} constexpr Board(uint64_t State, bool Failed = false) : State(State), Failed(Failed) {} constexpr Board addQueen(int Row, int Col) { return Board(State | ((uint64_t)Row << (Col * 4))); } constexpr int getQueenRow(int Col) { return (State >> (Col * 4)) & 0xf; } constexpr bool ok(int Row, int Col) { return okRecurse(Row, Col, 0); } constexpr bool okRecurse(int Row, int Col, int CheckCol) { return Col == CheckCol ? true : getQueenRow(CheckCol) == Row ? false : getQueenRow(CheckCol) == Row + (Col - CheckCol) ? false : getQueenRow(CheckCol) == Row + (CheckCol - Col) ? false : okRecurse(Row, Col, CheckCol + 1); } constexpr bool at(int Row, int Col) { return getQueenRow(Col) == Row; } constexpr bool check(const char *, int=0, int=0); }; constexpr Board buildBoardRecurse(int N, int Col, const Board &B); constexpr Board buildBoardScan(int N, int Col, int Row, const Board &B); constexpr Board tryBoard(const Board &Try, int N, int Col, int Row, const Board &B) { return Try.Failed ? buildBoardScan(N, Col, Row, B) : Try; } constexpr Board buildBoardScan(int N, int Col, int Row, const Board &B) { return Row == N ? Board(0, true) : B.ok(Row, Col) ? tryBoard(buildBoardRecurse(N, Col + 1, B.addQueen(Row, Col)), N, Col, Row+1, B) : buildBoardScan(N, Col, Row + 1, B); } constexpr Board buildBoardRecurse(int N, int Col, const Board &B) { return Col == N ? B : buildBoardScan(N, Col, 0, B); } constexpr Board buildBoard(int N) { return buildBoardRecurse(N, 0, Board()); } constexpr Board q8 = buildBoard(8); constexpr bool Board::check(const char *p, int Row, int Col) { return *p == '\n' ? check(p+1, Row+1, 0) : *p == 'o' ? at(Row, Col) && check(p+1, Row, Col+1) : *p == '-' ? !at(Row, Col) && check(p+1, Row, Col+1) : *p == 0 ? true : false; } static_assert(q8.check( "o-------\n" "------o-\n" "----o---\n" "-------o\n" "-o------\n" "---o----\n" "-----o--\n" "--o-----\n"), "");
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/constexpr-strlen.cpp
// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify -pedantic # 1 "/usr/include/string.h" 1 3 4 extern "C" { typedef decltype(sizeof(int)) size_t; extern size_t strlen(const char *p); } # 10 "SemaCXX/constexpr-strlen.cpp" 2 constexpr int n = __builtin_strlen("hello"); // ok constexpr int m = strlen("hello"); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strlen' cannot be used in a constant expression}} // Make sure we can evaluate a call to strlen. int arr[3]; // expected-note {{here}} int k = arr[strlen("hello")]; // expected-warning {{array index 5}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-no-split-stack.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s int i __attribute__((no_split_stack)); // expected-error {{'no_split_stack' attribute only applies to functions}} void f1() __attribute__((no_split_stack)); void f2() __attribute__((no_split_stack(1))); // expected-error {{'no_split_stack' attribute takes no arguments}} template <typename T> void tf1() __attribute__((no_split_stack)); int f3(int __attribute__((no_split_stack)), int); // expected-error{{'no_split_stack' attribute only applies to functions}} struct A { int f __attribute__((no_split_stack)); // expected-error{{'no_split_stack' attribute only applies to functions}} void mf1() __attribute__((no_split_stack)); static void mf2() __attribute__((no_split_stack)); }; int ci [[gnu::no_split_stack]]; // expected-error {{'no_split_stack' attribute only applies to functions}} [[gnu::no_split_stack]] void cf1(); [[gnu::no_split_stack(1)]] void cf2(); // expected-error {{'no_split_stack' attribute takes no arguments}} template <typename T> [[gnu::no_split_stack]] void ctf1(); int cf3(int c[[gnu::no_split_stack]], int); // expected-error{{'no_split_stack' attribute only applies to functions}} struct CA { int f [[gnu::no_split_stack]]; // expected-error{{'no_split_stack' attribute only applies to functions}} [[gnu::no_split_stack]] void mf1(); [[gnu::no_split_stack]] static void mf2(); };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-unused-local-typedef.cpp
// RUN: %clang_cc1 -fsyntax-only -Wunused-local-typedef -verify -std=c++1y %s struct S { typedef int Foo; // no diag }; namespace N { typedef int Foo; // no diag typedef int Foo2; // no diag } template <class T> class Vec {}; typedef int global_foo; // no diag void f() { typedef int foo0; // expected-warning {{unused typedef 'foo0'}} using foo0alias = int ; // expected-warning {{unused type alias 'foo0alias'}} typedef int foo1 __attribute__((unused)); // no diag typedef int foo2; { typedef int foo2; // expected-warning {{unused typedef 'foo2'}} } typedef foo2 foo3; // expected-warning {{unused typedef 'foo3'}} typedef int foo2_2; // expected-warning {{unused typedef 'foo2_2'}} { typedef int foo2_2; typedef foo2_2 foo3_2; // expected-warning {{unused typedef 'foo3_2'}} } typedef int foo4; foo4 the_thing; typedef int* foo5; typedef foo5* foo6; // no diag foo6 *myptr; struct S2 { typedef int Foo; // no diag typedef int Foo2; // expected-warning {{unused typedef 'Foo2'}} struct Deeper { typedef int DeepFoo; // expected-warning {{unused typedef 'DeepFoo'}} }; }; S2::Foo s2foo; typedef struct {} foostruct; // expected-warning {{unused typedef 'foostruct'}} typedef struct {} foostruct2; // no diag foostruct2 fs2; typedef int vecint; // no diag Vec<vecint> v; N::Foo nfoo; typedef int ConstExprInt; static constexpr int a = (ConstExprInt)4; } int printf(char const *, ...); void test() { typedef signed long int superint; // no diag printf("%f", (superint) 42); typedef signed long int superint2; // no diag printf("%f", static_cast<superint2>(42)); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-local-typedef" typedef int trungl_bot_was_here; // no diag #pragma clang diagnostic pop typedef int foo; // expected-warning {{unused typedef 'foo'}} } template <class T> void template_fun(T t) { typedef int foo; // expected-warning {{unused typedef 'foo'}} typedef int bar; // no-diag bar asdf; struct S2 { typedef int Foo; // no diag typedef int Foo2; // expected-warning {{unused typedef 'Foo2'}} typedef int Foo3; // no diag }; typename S2::Foo s2foo; typename T::Foo s3foo; typedef typename S2::Foo3 TTSF; // expected-warning {{unused typedef 'TTSF'}} } void template_fun_user() { struct Local { typedef int Foo; // no-diag typedef int Bar; // expected-warning {{unused typedef 'Bar'}} } p; template_fun(p); } void typedef_in_nested_name() { typedef struct { typedef int Foo; } A; A::Foo adsf; using A2 = struct { typedef int Foo; }; A2::Foo adsf2; } auto sneaky() { struct S { // Local typedefs can be used after the scope they were in has closed: typedef int t; // Even if they aren't, this could be an inline function that could be used // in another TU, so this shouldn't warn either: typedef int s; private: typedef int p; // expected-warning{{unused typedef 'p'}} }; return S(); } auto x = sneaky(); decltype(x)::t y; static auto static_sneaky() { struct S { typedef int t; // This function has internal linkage, so we can warn: typedef int s; // expected-warning {{unused typedef 's'}} }; return S(); } auto sx = static_sneaky(); decltype(sx)::t sy; auto sneaky_with_friends() { struct S { private: friend class G; // Can't warn if we have friends: typedef int p; }; return S(); } namespace { auto nstatic_sneaky() { struct S { typedef int t; // This function has internal linkage, so we can warn: typedef int s; // expected-warning {{unused typedef 's'}} }; return S(); } auto nsx = nstatic_sneaky(); decltype(nsx)::t nsy; } // Like sneaky(), but returning pointer to local type template<typename T> struct remove_reference { typedef T type; }; template<typename T> struct remove_reference<T&> { typedef T type; }; auto pointer_sneaky() { struct S { typedef int t; typedef int s; }; return (S*)nullptr; } remove_reference<decltype(*pointer_sneaky())>::type::t py; // Like sneaky(), but returning templated struct referencing local type. template <class T> struct container { int a; T t; }; auto template_sneaky() { struct S { typedef int t; typedef int s; }; return container<S>(); } auto tx = template_sneaky(); decltype(tx.t)::t ty; // Like sneaky(), but doing its sneakiness by returning a member function // pointer. auto sneaky_memfun() { struct S { typedef int type; int n; }; return &S::n; } template <class T> void sneaky_memfun_g(int T::*p) { typename T::type X; } void sneaky_memfun_h() { sneaky_memfun_g(sneaky_memfun()); } void typedefs_in_constructors() { struct A {}; struct B : public A { // Neither of these two should warn: typedef A INHERITED; B() : INHERITED() {} typedef B SELF; B(int) : SELF() {} }; } void *operator new(__SIZE_TYPE__, void *p) throw() { return p; } void placement_new_and_delete() { struct MyStruct { }; char memory[sizeof(MyStruct)]; void *p = memory; typedef MyStruct A_t1; MyStruct *a = new (p) A_t1(); typedef MyStruct A_t2; a->~A_t2(); } // This should not disable any warnings: #pragma clang diagnostic ignored "-Wunused-local-typedef"
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/instantiate-blocks.cpp
// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s // rdar: // 6182276 template <typename T, typename T1> void foo(T t, T1 r) { T block_arg; __block T1 byref_block_arg; T1 (^block)(T) = ^ T1 (T arg) { byref_block_arg = arg; block_arg = arg; // expected-error {{variable is not assignable (missing __block type specifier)}} return block_arg+arg; }; } // rdar://10466373 template <typename T, typename T1> void noret(T t, T1 r) { (void) ^{ if (1) return t; else if (2) return r; // expected-error {{return type 'double' must match previous return type 'float' when block literal has unspecified explicit return type}} }; } int main(void) { foo(100, 'a'); // expected-note {{in instantiation of function template specialization 'foo<int, char>' requested here}} noret((float)0.0, double(0.0)); // expected-note {{in instantiation of function template specialization 'noret<float, double>' requested here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx1y-constexpr-not-const.cpp
// RUN: %clang_cc1 -std=c++11 %s -verify // RUN: %clang_cc1 -std=c++1y %s -verify -DCXX1Y struct X { constexpr int f(); // @5 int f(); // @6 }; #ifdef CXX1Y // FIXME: Detect this situation and provide a better recovery. // expected-error@6 {{class member cannot be redeclared}} // expected-note@5 {{previous}} #else // expected-warning@5 {{'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior}} #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-member-not-needed.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -Wunneeded-member-function %s namespace { class A { void g() {} // expected-warning {{is not needed and will not be emitted}} template <typename T> void foo() { g(); } }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/nullptr.cpp
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -ffreestanding -Wno-null-conversion %s #include <stdint.h> typedef decltype(nullptr) nullptr_t; struct A {}; int o1(char*); void o1(uintptr_t); void o2(char*); // expected-note {{candidate}} void o2(int A::*); // expected-note {{candidate}} nullptr_t f(nullptr_t null) { // Implicit conversions. null = nullptr; void *p = nullptr; p = null; int *pi = nullptr; pi = null; null = 0; int A::*pm = nullptr; pm = null; void (*pf)() = nullptr; pf = null; void (A::*pmf)() = nullptr; pmf = null; bool b = nullptr; // Can't convert nullptr to integral implicitly. uintptr_t i = nullptr; // expected-error {{cannot initialize}} // Operators (void)(null == nullptr); (void)(null <= nullptr); (void)(null == 0); (void)(null == (void*)0); (void)((void*)0 == nullptr); (void)(null <= 0); (void)(null <= (void*)0); (void)((void*)0 <= nullptr); (void)(0 == nullptr); (void)(nullptr == 0); (void)(nullptr <= 0); (void)(0 <= nullptr); (void)(1 > nullptr); // expected-error {{invalid operands to binary expression}} (void)(1 != nullptr); // expected-error {{invalid operands to binary expression}} (void)(1 + nullptr); // expected-error {{invalid operands to binary expression}} (void)(0 ? nullptr : 0); (void)(0 ? nullptr : (void*)0); (void)(0 ? nullptr : A()); // expected-error {{non-pointer operand type 'A' incompatible with nullptr}} (void)(0 ? A() : nullptr); // expected-error {{non-pointer operand type 'A' incompatible with nullptr}} // Overloading int t = o1(nullptr); t = o1(null); o2(nullptr); // expected-error {{ambiguous}} // nullptr is an rvalue, null is an lvalue (void)&nullptr; // expected-error {{cannot take the address of an rvalue of type 'nullptr_t'}} nullptr_t *pn = &null; // You can reinterpret_cast nullptr to an integer. (void)reinterpret_cast<uintptr_t>(nullptr); (void)reinterpret_cast<uintptr_t>(*pn); // You can't reinterpret_cast nullptr to any integer (void)reinterpret_cast<char>(nullptr); // expected-error {{cast from pointer to smaller type 'char' loses information}} int *ip = *pn; if (*pn) { } // You can throw nullptr. throw nullptr; } // Template arguments can be nullptr. template <int *PI, void (*PF)(), int A::*PM, void (A::*PMF)()> struct T {}; typedef T<nullptr, nullptr, nullptr, nullptr> NT; namespace test1 { 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; }; void *g(void*); bool g(bool); // Test that we prefer g(void*) over g(bool). static_assert(is_same<decltype(g(nullptr)), void*>::value, ""); } namespace test2 { void f(int, ...) __attribute__((sentinel)); void g() { // nullptr can be used as the sentinel value. f(10, nullptr); } } namespace test3 { void f(const char*, ...) __attribute__((format(printf, 1, 2))); void g() { // Don't warn when using nullptr with %p. f("%p", nullptr); } } static_assert(__is_scalar(nullptr_t), ""); static_assert(__is_pod(nullptr_t), ""); static_assert(sizeof(nullptr_t) == sizeof(void*), ""); static_assert(!(nullptr < nullptr), ""); static_assert(!(nullptr > nullptr), ""); static_assert( nullptr <= nullptr, ""); static_assert( nullptr >= nullptr, ""); static_assert( nullptr == nullptr, ""); static_assert(!(nullptr != nullptr), ""); static_assert(!(0 < nullptr), ""); static_assert(!(0 > nullptr), ""); static_assert( 0 <= nullptr, ""); static_assert( 0 >= nullptr, ""); static_assert( 0 == nullptr, ""); static_assert(!(0 != nullptr), ""); static_assert(!(nullptr < 0), ""); static_assert(!(nullptr > 0), ""); static_assert( nullptr <= 0, ""); static_assert( nullptr >= 0, ""); static_assert( nullptr == 0, ""); static_assert(!(nullptr != 0), ""); namespace overloading { int &f1(int*); float &f1(bool); void test_f1() { int &ir = (f1)(nullptr); } struct ConvertsToNullPtr { operator nullptr_t() const; }; void test_conversion(ConvertsToNullPtr ctn) { (void)(ctn == ctn); (void)(ctn != ctn); (void)(ctn <= ctn); (void)(ctn >= ctn); (void)(ctn < ctn); (void)(ctn > ctn); } } namespace templates { template<typename T, nullptr_t Value> struct X { X() { ptr = Value; } T *ptr; }; X<int, nullptr> x; template<int (*fp)(int), int* p, int A::* pmd, int (A::*pmf)(int)> struct X2 {}; X2<nullptr, nullptr, nullptr, nullptr> x2; } namespace null_pointer_constant { // Pending implementation of core issue 903, ensure we don't allow any of the // C++11 constant evaluation semantics in null pointer constants. struct S { int n; }; constexpr int null() { return 0; } void *p = S().n; // expected-error {{cannot initialize}} void *q = null(); // expected-error {{cannot initialize}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attributed-auto-deduction.cpp
// RUN: %clang_cc1 -triple armv7 -std=c++14 -x c++ %s -fsyntax-only // expected-no-diagnostics void deduce() { auto single_int = [](int i) __attribute__ (( pcs("aapcs") )) { return i; }; auto multiple_int = [](int i) __attribute__ (( pcs("aapcs") )) __attribute__ (( pcs("aapcs") )) { return i; }; auto single_void = []() __attribute__ (( pcs("aapcs") )) { }; auto multiple_void = []() __attribute__ (( pcs("aapcs") )) __attribute__ (( pcs("aapcs") )) { }; } auto ( __attribute__ (( pcs("aapcs") )) single_attribute() ) { } auto ( ( __attribute__ (( pcs("aapcs") )) ( ( __attribute__ (( pcs("aapcs") )) multiple_attributes() ) ) ) ) { }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/missing-namespace-qualifier-typo-corrections.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions %s namespace fizbin { class Foobar {}; } // expected-note 2 {{'fizbin::Foobar' declared here}} \ // expected-note {{'Foobar' declared here}} Foobar *my_bar // expected-error{{unknown type name 'Foobar'; did you mean 'fizbin::Foobar'?}} = new Foobar; // expected-error{{unknown type name 'Foobar'; did you mean 'fizbin::Foobar'?}} fizbin::Foobar *my_foo = new fizbin::FooBar; // expected-error{{no type named 'FooBar' in namespace 'fizbin'; did you mean 'Foobar'?}} namespace barstool { int toFoobar() { return 1; } } // expected-note 3 {{'barstool::toFoobar' declared here}} int Double(int x) { return x + x; } void empty() { Double(toFoobar()); // expected-error{{use of undeclared identifier 'toFoobar'; did you mean 'barstool::toFoobar'?}} } namespace fizbin { namespace baztool { bool toFoobar() { return true; } } // expected-note{{'fizbin::baztool' declared here}} namespace nested { bool moreFoobar() { return true; } } // expected-note{{'fizbin::nested::moreFoobar' declared here}} namespace nested { bool lessFoobar() { return true; } } // expected-note{{'fizbin::nested' declared here}} \ // expected-note{{'fizbin::nested::lessFoobar' declared here}} class dummy { // expected-note 2 {{'fizbin::dummy' declared here}} public: static bool morebar() { return false; } // expected-note{{'morebar' declared here}} }; } void Check() { // expected-note{{'Check' declared here}} if (toFoobar()) Double(7); // expected-error{{use of undeclared identifier 'toFoobar'; did you mean 'barstool::toFoobar'?}} if (noFoobar()) Double(7); // expected-error{{use of undeclared identifier 'noFoobar'; did you mean 'barstool::toFoobar'?}} if (moreFoobar()) Double(7); // expected-error{{use of undeclared identifier 'moreFoobar'; did you mean 'fizbin::nested::moreFoobar'}} if (lessFoobar()) Double(7); // expected-error{{use of undeclared identifier 'lessFoobar'; did you mean 'fizbin::nested::lessFoobar'?}} if (baztool::toFoobar()) Double(7); // expected-error{{use of undeclared identifier 'baztool'; did you mean 'fizbin::baztool'?}} if (nested::moreFoobar()) Double(7); // expected-error{{use of undeclared identifier 'nested'; did you mean 'fizbin::nested'?}} if (dummy::morebar()) Double(7); // expected-error{{use of undeclared identifier 'dummy'; did you mean 'fizbin::dummy'?}} if (dummy::mrebar()) Double(7); // expected-error{{use of undeclared identifier 'dummy'; did you mean 'fizbin::dummy'?}} \ // expected-error{{no member named 'mrebar' in 'fizbin::dummy'; did you mean 'morebar'?}} if (moFoobin()) Double(7); // expected-error{{use of undeclared identifier 'moFoobin'}} } void Alt() { Cleck(); // expected-error{{use of undeclared identifier 'Cleck'; did you mean 'Check'?}} } namespace N { namespace inner { class myvector { /* ... */ }; // expected-note{{'inner::myvector' declared here}} } void f() { myvector v; // expected-error{{unknown type name 'myvector'; did you mean 'inner::myvector'?}} } } namespace realstd { inline namespace __1 { class mylinkedlist { /* ... */ }; // expected-note 2 {{'realstd::mylinkedlist' declared here}} } class linkedlist { /* ... */ }; } void f() { mylinkedlist v; // expected-error{{unknown type name 'mylinkedlist'; did you mean 'realstd::mylinkedlist'?}} nylinkedlist w; // expected-error{{unknown type name 'nylinkedlist'; did you mean 'realstd::mylinkedlist'?}} } // Test case from http://llvm.org/bugs/show_bug.cgi?id=10318 namespace llvm { template <typename T> class GraphWriter {}; // expected-note 3{{declared here}} } struct S {}; void bar() { GraphWriter<S> x; //expected-error{{no template named 'GraphWriter'; did you mean 'llvm::GraphWriter'?}} (void)new llvm::GraphWriter; // expected-error {{use of class template 'llvm::GraphWriter' requires template arguments}} (void)new llvm::Graphwriter<S>; // expected-error {{no template named 'Graphwriter' in namespace 'llvm'; did you mean 'GraphWriter'?}} } // If namespace prefixes and character edits have the same weight, correcting // "fimish" to "N::famish" would have the same edit distance as correcting // "fimish" to "Finish". The result would be no correction being suggested // unless one of the corrections is given precedence (e.g. by filtering out // suggestions with added namespace qualifiers). namespace N { void famish(int); } void Finish(int); // expected-note {{'Finish' declared here}} void Start() { fimish(7); // expected-error {{use of undeclared identifier 'fimish'; did you mean 'Finish'?}} } // But just eliminating the corrections containing added namespace qualifiers // won't work if both of the tied corrections have namespace qualifiers added. namespace N { void someCheck(int); // expected-note {{'N::someCheck' declared here}} namespace O { void somechock(int); } } void confusing() { somechick(7); // expected-error {{use of undeclared identifier 'somechick'; did you mean 'N::someCheck'?}} } class Message {}; namespace extra { namespace util { namespace MessageUtils { bool Equivalent(const Message&, const Message&); // expected-note {{'extra::util::MessageUtils::Equivalent' declared here}} \ // expected-note {{'::extra::util::MessageUtils::Equivalent' declared here}} } } } namespace util { namespace MessageUtils {} } bool nstest () { Message a, b; return util::MessageUtils::Equivalent(a, b); // expected-error {{no member named 'Equivalent' in namespace 'util::MessageUtils'; did you mean 'extra::util::MessageUtils::Equivalent'?}} } namespace util { namespace extra { bool nstest () { Message a, b; return MessageUtils::Equivalent(a, b); // expected-error {{no member named 'Equivalent' in namespace 'util::MessageUtils'; did you mean '::extra::util::MessageUtils::Equivalent'?}} } } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/parentheses.cpp
// RUN: %clang_cc1 -verify %s // PR16930, PR16727: template<class Foo> bool test(Foo f, int *array) { return false && false || array[f.get()]; // expected-warning {{'&&' within '||'}} expected-note {{parentheses}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/vtable-instantiation.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace PR8640 { template<class T1> struct C1 { virtual void c1() { T1 t1 = 3; // expected-error {{cannot initialize a variable}} } }; template<class T2> struct C2 { void c2() { new C1<T2>(); // expected-note {{in instantiation of member function}} } }; void f() { C2<int*> c2; c2.c2(); // expected-note {{in instantiation of member function}} } } namespace PR9325 { template<typename T> class Target { public: virtual T Value() const { return 1; // expected-error{{cannot initialize return object of type 'int *' with an rvalue of type 'int'}} } }; template<typename T> struct Provider { static Target<T> Instance; }; template<typename T> Target<T> Provider<T>::Instance; // expected-note{{in instantiation of}} void f() { Target<int*>* traits = &Provider<int*>::Instance; // expected-note{{requested here}} } } namespace PR10020 { struct MG { virtual void Accept(int) = 0; }; template <typename Type> struct GMG : MG { void Accept(int i) { static_cast<Type *>(0)->Accept(i); // expected-error{{member reference base}} } static GMG* Method() { return &singleton; } // expected-note{{in instantiation of}} static GMG singleton; }; template <typename Type> GMG<Type> GMG<Type>::singleton; // expected-note{{requested here}} void test(void) { GMG<int>::Method(); // expected-note{{in instantiation of}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
// RUN: %clang_cc1 -verify -fsyntax-only -Wno-c++11-extensions -Wno-c++1y-extensions %s -DPRECXX11 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -Wno-c++1y-extensions %s // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s #ifdef PRECXX11 #define CONST const #else #define CONST constexpr #endif template<typename T> T pi = T(3.1415926535897932385); // expected-note {{template is declared here}} template<typename T> CONST T cpi = T(3.1415926535897932385); // expected-note {{template is declared here}} template<typename T> extern CONST T vc; #ifndef PRECXX11 // expected-error@-2 {{constexpr variable declaration must be a definition}} #endif namespace use_in_top_level_funcs { void good() { int ipi = pi<int>; int icpi = cpi<int>; double dpi = pi<double>; double dcpi = cpi<double>; } void no_deduce() { // template arguments are not deduced for uses of variable templates. int ipi = pi; // expected-error {{cannot refer to variable template 'pi' without a template argument list}} int icpi = cpi; // expected-error {{cannot refer to variable template 'cpi' without a template argument list}} } template<typename T> T circular_area(T r) { return pi<T> * r * r; } template<typename T> CONST T const_circular_area(T r) { return cpi<T> * r * r; } double use_circular_area(double r) { CONST float t = const_circular_area(2.0) - 12; #ifndef PRECXX11 static_assert(const_circular_area(2) == 12, ""); CONST int test = (t > 0) && (t < 1); static_assert(test, ""); #endif return circular_area(r); } } namespace shadow { void foo() { int ipi0 = pi<int>; int pi; int a = pi; int ipi = pi<int>; // expected-error {{expected '(' for function-style cast or type construction}} \ // expected-error {{expected expression}} } } namespace odr_tmpl { namespace pv_cvt { int v; // expected-note {{previous definition is here}} template<typename T> T v; // expected-error {{redefinition of 'v' as different kind of symbol}} } namespace pvt_cv { template<typename T> T v; // expected-note {{previous definition is here}} int v; // expected-error {{redefinition of 'v' as different kind of symbol}} } namespace pvt_cvt { template<typename T> T v0; // expected-note {{previous definition is here}} template<typename T> T v0; // expected-error {{redefinition of 'v0'}} template<typename T> T v; // expected-note {{previous definition is here}} template<typename T> int v; // expected-error {{redefinition of 'v'}} template<typename T> extern int v1; // expected-note {{previous template declaration is here}} template<int I> int v1; // expected-error {{template parameter has a different kind in template redeclaration}} } namespace pvt_use { template<typename T> T v; v = 10; // expected-error {{C++ requires a type specifier for all declarations}} } namespace pvt_diff_params { template<typename T, typename> T v; // expected-note {{previous template declaration is here}} template<typename T> T v; // expected-error {{too few template parameters in template redeclaration}} expected-note {{previous template declaration is here}} template<typename T, typename, typename> T v; // expected-error {{too many template parameters in template redeclaration}} } namespace pvt_extern { template<typename T> T v = T(); template<typename T> extern T v; // redeclaration is allowed \ // expected-note {{previous declaration is here}} template<typename T> extern int v; // expected-error {{redeclaration of 'v' with a different type: 'int' vs 'T'}} #ifndef PRECXX11 template<typename T> extern auto v; // expected-error {{declaration of variable 'v' with type 'auto' requires an initializer}} #endif template<typename T> T var = T(); // expected-note {{previous definition is here}} extern int var; // expected-error {{redefinition of 'var' as different kind of symbol}} } #ifndef PRECXX11 namespace pvt_auto { template<typename T> auto v0; // expected-error {{declaration of variable 'v0' with type 'auto' requires an initializer}} template<typename T> auto v1 = T(); // expected-note {{previous definition is here}} template<typename T> int v1; // expected-error {{redefinition of 'v1' with a different type: 'int' vs 'auto'}} template<typename T> auto v2 = T(); // expected-note {{previous definition is here}} template<typename T> T v2; // expected-error {{redefinition of 'v2'}} template<typename T> auto v3 = T(); // expected-note {{previous definition is here}} template<typename T> extern T v3; // expected-error {{redeclaration of 'v3' with a different type: 'T' vs 'auto'}} template<typename T> auto v4 = T(); template<typename T> extern auto v4; // expected-error {{declaration of variable 'v4' with type 'auto' requires an initializer}} } #endif } namespace explicit_instantiation { template<typename T> T pi0a = T(3.1415926535897932385); // expected-note {{variable template 'pi0a' declared here}} template float pi0a<int>; // expected-error {{type 'float' of explicit instantiation of 'pi0a' does not match expected type 'int'}} template<typename T> T pi0b = T(3.1415926535897932385); // expected-note {{variable template 'pi0b' declared here}} template CONST int pi0b<int>; // expected-error {{type 'const int' of explicit instantiation of 'pi0b' does not match expected type 'int'}} template<typename T> T pi0c = T(3.1415926535897932385); // expected-note {{variable template 'pi0c' declared here}} template int pi0c<const int>; // expected-error {{type 'int' of explicit instantiation of 'pi0c' does not match expected type 'const int'}} template<typename T> T pi0 = T(3.1415926535897932385); template int pi0<int>; // expected-note {{previous explicit instantiation is here}} template int pi0<int>; // expected-error {{duplicate explicit instantiation of 'pi0<int>'}} template<typename T> CONST T pi1a = T(3.1415926535897932385); // expected-note {{variable template 'pi1a' declared here}} template int pi1a<int>; // expected-error {{type 'int' of explicit instantiation of 'pi1a' does not match expected type 'const int'}} template<typename T> CONST T pi1b = T(3.1415926535897932385); // expected-note {{variable template 'pi1b' declared here}} template int pi1b<const int>; // expected-error {{type 'int' of explicit instantiation of 'pi1b' does not match expected type 'const const int'}} template<typename T> CONST T pi1 = T(3.1415926535897932385); template CONST int pi1<int>; // expected-note {{previous explicit instantiation is here}} template CONST int pi1<int>; // expected-error {{duplicate explicit instantiation of 'pi1<int>'}} #ifndef PRECXX11 namespace auto_var { template<typename T> auto var0 = T(); template auto var0<int>; // expected-error {{'auto' variable template instantiation is not allowed}} template<typename T> auto var = T(); template int var<int>; } #endif template<typename=int> int missing_args; // expected-note {{here}} template int missing_args; // expected-error {{must specify a template argument list}} namespace extern_var { // TODO: } } namespace explicit_specialization { namespace good { template<typename T1, typename T2> CONST int pi2 = 1; template<typename T> CONST int pi2<T,int> = 2; template<typename T> CONST int pi2<int,T> = 3; template<> CONST int pi2<int,int> = 4; #ifndef PRECXX11 void foo() { static_assert(pi2<int,int> == 4, ""); static_assert(pi2<float,int> == 2, ""); static_assert(pi2<int,float> == 3, ""); static_assert(pi2<int,float> == pi2<int,double>, ""); static_assert(pi2<float,float> == 1, ""); static_assert(pi2<float,float> == pi2<float,double>, ""); } #endif } namespace ambiguous { template<typename T1, typename T2> CONST int pi2 = 1; template<typename T> CONST int pi2<T,int> = 2; // expected-note {{partial specialization matches [with T = int]}} template<typename T> CONST int pi2<int,T> = 3; // expected-note {{partial specialization matches [with T = int]}} void foo() { int a = pi2<int,int>; // expected-error {{ambiguous partial specializations of 'pi2<int, int>'}} } } namespace type_changes { template<typename T> T pi0 = T(3.1415926535897932385); template<> float pi0<int> = 10; template<> int pi0<const int> = 10; template<typename T> T pi1 = T(3.1415926535897932385); template<> CONST int pi1<int> = 10; template<typename T> T pi2 = T(3.1415926535897932385); template<> int pi2<const int> = 10; template<typename T> CONST T pi4 = T(3.1415926535897932385); template<> int pi4<int> = 10; } namespace redefinition { template<typename T> T pi0 = T(3.1415926535897932385); template<> int pi0<int> = 10; // expected-note 3{{previous definition is here}} #ifndef PRECXX11 // expected-note@-2 {{previous definition is here}} #endif template<> int pi0<int> = 10; // expected-error {{redefinition of 'pi0<int>'}} template<> CONST int pi0<int> = 10; // expected-error {{redefinition of 'pi0' with a different type: 'const int' vs 'int'}} template<> float pi0<int> = 10; // expected-error {{redefinition of 'pi0' with a different type: 'float' vs 'int'}} #ifndef PRECXX11 template<> auto pi0<int> = 10; // expected-error {{redefinition of 'pi0<int>'}} #endif template<typename T> CONST T pi1 = T(3.1415926535897932385); template<> CONST int pi1<int> = 10; // expected-note {{previous definition is here}} template<> CONST int pi1<int> = 10; // expected-error {{redefinition of 'pi1<int>'}} } namespace before_instantiation { template<typename T> T pi0 = T(3.1415926535897932385); // expected-note {{variable template 'pi0' declared here}} template<> int pi0<int> = 10; template int pi0<int>; template float pi0<int>; // expected-error {{type 'float' of explicit instantiation of 'pi0' does not match expected type}} template<typename T1, typename T2> CONST int pi2 = 1; template<typename T> CONST int pi2<T,int> = 2; template CONST int pi2<int,int>; } namespace after_instantiation { template<typename T> T pi0 = T(3.1415926535897932385); template int pi0<int>; // expected-note 2{{explicit instantiation first required here}} template<> int pi0<int> = 10; // expected-error {{explicit specialization of 'pi0' after instantiation}} template<> float pi0<int>; // expected-error {{explicit specialization of 'pi0' after instantiation}} template<typename T1, typename T2> CONST int pi2 = 1; template CONST int pi2<int,int>; template<typename T> CONST int pi2<T,int> = 2; } #ifndef PRECXX11 namespace auto_var { template<typename T, typename> auto var0 = T(); template<typename T> auto var0<T,int> = T(); template<> auto var0<int,int> = 7; template<typename T, typename> auto var = T(); template<typename T> T var<T,int> = T(5); template<> int var<int,int> = 7; void foo() { int i0 = var0<int,int>; int b = var<int,int>; } } #endif namespace extern_var { // TODO: } namespace diff_type { // TODO: template<typename T> T* var = new T(); #ifndef PRECXX11 template<typename T> auto var<T*> = T(); // expected-note {{previous definition is here}} template<typename T> T var<T*> = T(); // expected-error {{redefinition of 'var' with a different type: 'T' vs 'auto'}} #endif } } namespace narrowing { template<typename T> T v = {1234}; // expected-warning {{implicit conversion from 'int' to 'char' changes value from 1234 to}} #ifndef PRECXX11 // expected-error@-2 {{constant expression evaluates to 1234 which cannot be narrowed to type 'char'}}\ // expected-note@-2 {{insert an explicit cast to silence this issue}} #endif int k = v<char>; // expected-note {{in instantiation of variable template specialization 'narrowing::v<char>' requested here}} } namespace use_in_structs { // TODO: } namespace attributes { // TODO: } #ifndef PRECXX11 namespace arrays { template<typename T> T* arr = new T[10]{T(10), T(23)}; float f = 10.5; template<> float* arr<float> = &f; void bar() { int *iarr = arr<int>; iarr[0] = 1; iarr[2] = 3; iarr[6] = -2; float ff = *arr<float>; float nof = arr<float>[3]; // No bounds-check in C++ } } #endif namespace nested { namespace n0a { template<typename T> T pi0a = T(3.1415926535897932385); } using namespace n0a; int i0a = pi0a<int>; template float pi0a<float>; float f0a = pi0a<float>; template<> double pi0a<double> = 5.2; double d0a = pi0a<double>; namespace n0b { template<typename T> T pi0b = T(3.1415926535897932385); } int i0b = n0b::pi0b<int>; template float n0b::pi0b<float>; float f0b = n0b::pi0b<float>; template<> double n0b::pi0b<double> = 5.2; double d0b = n0b::pi0b<double>; namespace n1 { template<typename T> T pi1a = T(3.1415926535897932385); // expected-note {{explicitly specialized declaration is here}} #ifndef PRECXX11 // expected-note@-2 {{explicit instantiation refers here}} #endif template<typename T> T pi1b = T(3.1415926535897932385); // expected-note {{explicitly specialized declaration is here}} #ifndef PRECXX11 // expected-note@-2 {{explicit instantiation refers here}} #endif } namespace use_n1a { using namespace n1; int i1 = pi1a<int>; template float pi1a<float>; #ifndef PRECXX11 // expected-error@-2 {{explicit instantiation of 'pi1a<float>' not in a namespace enclosing 'n1'}} #endif float f1 = pi1a<float>; template<> double pi1a<double> = 5.2; // expected-error {{variable template specialization of 'pi1a' must originally be declared in namespace 'n1'}} double d1 = pi1a<double>; } namespace use_n1b { int i1 = n1::pi1b<int>; template float n1::pi1b<float>; #ifndef PRECXX11 // expected-error@-2 {{explicit instantiation of 'pi1b<float>' not in a namespace enclosing 'n1'}} #endif float f1 = n1::pi1b<float>; template<> double n1::pi1b<double> = 5.2; // expected-error {{cannot define or redeclare 'pi1b' here because namespace 'use_n1b' does not enclose namespace 'n1'}} \ // expected-error {{variable template specialization of 'pi1b' must originally be declared in namespace 'n1'}} double d1 = n1::pi1b<double>; } } namespace nested_name { template<typename T> int a; // expected-note {{variable template 'a' declared here}} a<int>::b c; // expected-error {{qualified name refers into a specialization of variable template 'a'}} class a<int> {}; // expected-error {{identifier followed by '<' indicates a class template specialization but 'a' refers to a variable template}} enum a<int> {}; // expected-error {{expected identifier or '{'}} expected-warning {{does not declare anything}} } namespace PR18530 { template<typename T> int a; int a<int>; // expected-error {{requires 'template<>'}} } namespace PR19152 { #ifndef PRECXX11 template<typename T> const auto x = 1; static_assert(x<int> == 1, ""); #endif } namespace PR19169 { template <typename T> int* f(); template <typename T> void f(); template<> int f<double>; // expected-error {{no variable template matches specialization; did you mean to use 'f' as function template instead?}} template <typename T> void g(); template<> int g<double>; // expected-error {{no variable template matches specialization; did you mean to use 'g' as function template instead?}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-thread-safety-verbose.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-beta -Wthread-safety-verbose -Wno-thread-safety-negative -fcxx-exceptions %s #define LOCKABLE __attribute__ ((lockable)) #define SCOPED_LOCKABLE __attribute__ ((scoped_lockable)) #define GUARDED_BY(x) __attribute__ ((guarded_by(x))) #define GUARDED_VAR __attribute__ ((guarded_var)) #define PT_GUARDED_BY(x) __attribute__ ((pt_guarded_by(x))) #define PT_GUARDED_VAR __attribute__ ((pt_guarded_var)) #define ACQUIRED_AFTER(...) __attribute__ ((acquired_after(__VA_ARGS__))) #define ACQUIRED_BEFORE(...) __attribute__ ((acquired_before(__VA_ARGS__))) #define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__ ((exclusive_lock_function(__VA_ARGS__))) #define SHARED_LOCK_FUNCTION(...) __attribute__ ((shared_lock_function(__VA_ARGS__))) #define ASSERT_EXCLUSIVE_LOCK(...) __attribute__ ((assert_exclusive_lock(__VA_ARGS__))) #define ASSERT_SHARED_LOCK(...) __attribute__ ((assert_shared_lock(__VA_ARGS__))) #define EXCLUSIVE_TRYLOCK_FUNCTION(...) __attribute__ ((exclusive_trylock_function(__VA_ARGS__))) #define SHARED_TRYLOCK_FUNCTION(...) __attribute__ ((shared_trylock_function(__VA_ARGS__))) #define UNLOCK_FUNCTION(...) __attribute__ ((unlock_function(__VA_ARGS__))) #define LOCK_RETURNED(x) __attribute__ ((lock_returned(x))) #define LOCKS_EXCLUDED(...) __attribute__ ((locks_excluded(__VA_ARGS__))) #define EXCLUSIVE_LOCKS_REQUIRED(...) \ __attribute__ ((exclusive_locks_required(__VA_ARGS__))) #define SHARED_LOCKS_REQUIRED(...) \ __attribute__ ((shared_locks_required(__VA_ARGS__))) #define NO_THREAD_SAFETY_ANALYSIS __attribute__ ((no_thread_safety_analysis)) class __attribute__((lockable)) Mutex { public: void Lock() __attribute__((exclusive_lock_function)); void ReaderLock() __attribute__((shared_lock_function)); void Unlock() __attribute__((unlock_function)); bool TryLock() __attribute__((exclusive_trylock_function(true))); bool ReaderTryLock() __attribute__((shared_trylock_function(true))); void LockWhen(const int &cond) __attribute__((exclusive_lock_function)); // for negative capabilities const Mutex& operator!() const { return *this; } void AssertHeld() ASSERT_EXCLUSIVE_LOCK(); void AssertReaderHeld() ASSERT_SHARED_LOCK(); }; class Test { Mutex mu; int a GUARDED_BY(mu); // expected-note3 {{Guarded_by declared here.}} void foo1() EXCLUSIVE_LOCKS_REQUIRED(mu); void foo2() SHARED_LOCKS_REQUIRED(mu); void foo3() LOCKS_EXCLUDED(mu); void test1() { // expected-note {{Thread warning in function 'test1'}} a = 0; // expected-warning {{writing variable 'a' requires holding mutex 'mu' exclusively}} } void test2() { // expected-note {{Thread warning in function 'test2'}} int b = a; // expected-warning {{reading variable 'a' requires holding mutex 'mu'}} } void test3() { // expected-note {{Thread warning in function 'test3'}} foo1(); // expected-warning {{calling function 'foo1' requires holding mutex 'mu' exclusively}} } void test4() { // expected-note {{Thread warning in function 'test4'}} foo2(); // expected-warning {{calling function 'foo2' requires holding mutex 'mu'}} } void test5() { // expected-note {{Thread warning in function 'test5'}} mu.ReaderLock(); foo1(); // expected-warning {{calling function 'foo1' requires holding mutex 'mu' exclusively}} mu.Unlock(); } void test6() { // expected-note {{Thread warning in function 'test6'}} mu.ReaderLock(); a = 0; // expected-warning {{writing variable 'a' requires holding mutex 'mu' exclusively}} mu.Unlock(); } void test7() { // expected-note {{Thread warning in function 'test7'}} mu.Lock(); foo3(); // expected-warning {{cannot call function 'foo3' while mutex 'mu' is held}} mu.Unlock(); } };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/type-definition-in-specifier.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct S0; struct S1; struct S2; struct S3; struct S4; struct S5; struct S6; struct S0 { int x; }; void f0() { typedef struct S1 { int x; } S1_typedef; (void)((struct S2 { int x; }*)0); // expected-error{{cannot be defined}} struct S3 { int x; } s3; (void)static_cast<struct S4 { int x; } *>(0); // expected-error{{cannot be defined}} } struct S5 { int x; } f1() { return S5(); } // expected-error{{result type}} void f2(struct S6 { int x; } p); // expected-error{{parameter type}} struct pr19018 { short foo6 (enum bar0 {qq} bar3); // expected-error{{cannot be defined in a parameter type}} }; void pr19018_1 (enum e19018_1 {qq} x); // expected-error{{cannot be defined in a parameter type}} void pr19018_1a (enum e19018_1 {qq} x); // expected-error{{cannot be defined in a parameter type}} e19018_1 x2; // expected-error{{unknown type name 'e19018_1'}} void pr19018_2 (enum {qq} x); // expected-error{{cannot be defined in a parameter type}} void pr19018_3 (struct s19018_2 {int qq;} x); // expected-error{{cannot be defined in a parameter type}} void pr19018_4 (struct {int qq;} x); // expected-error{{cannot be defined in a parameter type}} void pr19018_5 (struct { void qq(); } x); // expected-error{{cannot be defined in a parameter type}} void pr19018_5 (struct s19018_2 { void qq(); } x); // expected-error{{cannot be defined in a parameter type}} struct pr19018a { static int xx; void func1(enum t19018 {qq} x); // expected-error{{cannot be defined in a parameter type}} void func2(enum t19018 {qq} x); // expected-error{{cannot be defined in a parameter type}} void func3(enum {qq} x); // expected-error{{cannot be defined in a parameter type}} void func4(struct t19018 {int qq;} x); // expected-error{{cannot be defined in a parameter type}} void func5(struct {int qq;} x); // expected-error{{cannot be defined in a parameter type}} void func6(struct { void qq(); } x); // expected-error{{cannot be defined in a parameter type}} void func7(struct t19018 { void qq(); } x); // expected-error{{cannot be defined in a parameter type}} void func8(struct { int qq() { return xx; }; } x); // expected-error{{cannot be defined in a parameter type}} void func9(struct t19018 { int qq() { return xx; }; } x); // expected-error{{cannot be defined in a parameter type}} }; struct s19018b { void func1 (enum en_2 {qq} x); // expected-error{{cannot be defined in a parameter type}} en_2 x1; // expected-error{{unknown type name 'en_2'}} void func2 (enum en_3 {qq} x); // expected-error{{cannot be defined in a parameter type}} enum en_3 x2; // expected-error{{ISO C++ forbids forward references to 'enum' types}} \ // expected-error{{field has incomplete type 'enum en_3'}} \ // expected-note{{forward declaration of 'en_3'}} }; struct pr18963 { short bar5 (struct foo4 {} bar2); // expected-error{{'foo4' cannot be defined in a parameter type}} long foo5 (float foo6 = foo4); // expected-error{{use of undeclared identifier 'foo4'}} };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/libstdcxx_common_type_hack.cpp
// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify // This is a test for an egregious hack in Clang that works around // an issue with GCC's <type_traits> implementation. std::common_type // relies on pre-standard rules for decltype(), in which it doesn't // produce reference types so frequently. #ifdef BE_THE_HEADER #pragma GCC system_header namespace std { template<typename T> T &&declval(); template<typename...Ts> struct common_type {}; template<typename A, typename B> struct common_type<A, B> { // Under the rules in the standard, this always produces a // reference type. typedef decltype(true ? declval<A>() : declval<B>()) type; }; } #else #define BE_THE_HEADER #include "libstdcxx_common_type_hack.cpp" using T = int; using T = std::common_type<int, int>::type; using U = int; // expected-note {{here}} using U = decltype(true ? std::declval<int>() : std::declval<int>()); // expected-error {{different types}} #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/overloaded-operator.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s class X { }; X operator+(X, X); void f(X x) { x = x + x; } struct Y; struct Z; struct Y { Y(const Z&); }; struct Z { Z(const Y&); }; Y operator+(Y, Y); bool operator-(Y, Y); // expected-note{{candidate function}} bool operator-(Z, Z); // expected-note{{candidate function}} void g(Y y, Z z) { y = y + z; bool b = y - z; // expected-error{{use of overloaded operator '-' is ambiguous}} } struct A { bool operator==(Z&); // expected-note 2{{candidate function}} }; A make_A(); bool operator==(A&, Z&); // expected-note 3{{candidate function}} void h(A a, const A ac, Z z) { make_A() == z; // expected-warning{{equality comparison result unused}} a == z; // expected-error{{use of overloaded operator '==' is ambiguous}} ac == z; // expected-error{{invalid operands to binary expression ('const A' and 'Z')}} } struct B { bool operator==(const B&) const; void test(Z z) { make_A() == z; // expected-warning{{equality comparison result unused}} } }; // we shouldn't see warnings about self-comparison, // this is a member function, we dunno what it'll do bool i(B b) { return b == b; } enum Enum1 { }; enum Enum2 { }; struct E1 { E1(Enum1) { } }; struct E2 { E2(Enum2); }; // C++ [over.match.oper]p3 - enum restriction. float& operator==(E1, E2); // expected-note{{candidate function}} void enum_test(Enum1 enum1, Enum2 enum2, E1 e1, E2 e2, Enum1 next_enum1) { float &f1 = (e1 == e2); float &f2 = (enum1 == e2); float &f3 = (e1 == enum2); float &f4 = (enum1 == next_enum1); // expected-error{{non-const lvalue reference to type 'float' cannot bind to a temporary of type 'bool'}} } // PR5244 - Argument-dependent lookup would include the two operators below, // which would break later assumptions and lead to a crash. class pr5244_foo { pr5244_foo(int); pr5244_foo(char); }; bool operator==(const pr5244_foo& s1, const pr5244_foo& s2); // expected-note{{candidate function}} bool operator==(char c, const pr5244_foo& s); // expected-note{{candidate function}} enum pr5244_bar { pr5244_BAR }; class pr5244_baz { public: pr5244_bar quux; }; void pr5244_barbaz() { pr5244_baz quuux; (void)(pr5244_BAR == quuux.quux); } struct PostInc { PostInc operator++(int); PostInc& operator++(); }; struct PostDec { PostDec operator--(int); PostDec& operator--(); }; void incdec_test(PostInc pi, PostDec pd) { const PostInc& pi1 = pi++; const PostDec& pd1 = pd--; PostInc &pi2 = ++pi; PostDec &pd2 = --pd; } struct SmartPtr { int& operator*(); long& operator*() const volatile; }; void test_smartptr(SmartPtr ptr, const SmartPtr cptr, const volatile SmartPtr cvptr) { int &ir = *ptr; long &lr = *cptr; long &lr2 = *cvptr; } struct ArrayLike { int& operator[](int); }; void test_arraylike(ArrayLike a) { int& ir = a[17]; } struct SmartRef { int* operator&(); }; void test_smartref(SmartRef r) { int* ip = &r; } bool& operator,(X, Y); void test_comma(X x, Y y) { bool& b1 = (x, y); X& xr = (x, x); // expected-warning {{expression result unused}} } struct Callable { int& operator()(int, double = 2.71828); // expected-note{{candidate function}} float& operator()(int, double, long, ...); // expected-note{{candidate function}} double& operator()(float); // expected-note{{candidate function}} }; struct Callable2 { int& operator()(int i = 0); double& operator()(...) const; }; struct DerivesCallable : public Callable { }; void test_callable(Callable c, Callable2 c2, const Callable2& c2c, DerivesCallable dc) { int &ir = c(1); float &fr = c(1, 3.14159, 17, 42); c(); // expected-error{{no matching function for call to object of type 'Callable'}} double &dr = c(1.0f); int &ir2 = c2(); int &ir3 = c2(1); double &fr2 = c2c(); int &ir4 = dc(17); double &fr3 = dc(3.14159f); } typedef float FLOAT; typedef int& INTREF; typedef INTREF Func1(FLOAT, double); typedef float& Func2(int, double); struct ConvertToFunc { operator Func1*(); // expected-note 2{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}} operator Func2&(); // expected-note 2{{conversion candidate of type 'float &(&)(int, double)'}} void operator()(); }; struct ConvertToFuncDerived : ConvertToFunc { }; void test_funcptr_call(ConvertToFunc ctf, ConvertToFuncDerived ctfd) { int &i1 = ctf(1.0f, 2.0); float &f1 = ctf((short int)1, 1.0f); ctf((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFunc' is ambiguous}} ctf(); int &i2 = ctfd(1.0f, 2.0); float &f2 = ctfd((short int)1, 1.0f); ctfd((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFuncDerived' is ambiguous}} ctfd(); } struct HasMember { int m; }; struct Arrow1 { HasMember* operator->(); }; struct Arrow2 { Arrow1 operator->(); // expected-note{{candidate function}} }; void test_arrow(Arrow1 a1, Arrow2 a2, const Arrow2 a3) { int &i1 = a1->m; int &i2 = a2->m; a3->m; // expected-error{{no viable overloaded 'operator->'}} } struct CopyConBase { }; struct CopyCon : public CopyConBase { CopyCon(const CopyConBase &Base); CopyCon(const CopyConBase *Base) { *this = *Base; } }; namespace N { struct X { }; } namespace M { N::X operator+(N::X, N::X); } namespace M { void test_X(N::X x) { (void)(x + x); } } struct AA { bool operator!=(AA&); }; struct BB : AA {}; bool x(BB y, BB z) { return y != z; } struct AX { AX& operator ->(); // expected-note {{declared here}} int b; }; void m() { AX a; a->b = 0; // expected-error {{circular pointer delegation detected}} } struct CircA { struct CircB& operator->(); // expected-note {{declared here}} int val; }; struct CircB { struct CircC& operator->(); // expected-note {{declared here}} }; struct CircC { struct CircA& operator->(); // expected-note {{declared here}} }; void circ() { CircA a; a->val = 0; // expected-error {{circular pointer delegation detected}} } // PR5360: Arrays should lead to built-in candidates for subscript. typedef enum { LastReg = 23, } Register; class RegAlloc { int getPriority(Register r) { return usepri[r]; } int usepri[LastReg + 1]; }; // PR5546: Don't generate incorrect and ambiguous overloads for multi-level // arrays. namespace pr5546 { enum { X }; extern const char *const sMoveCommands[][2][2]; const char* a() { return sMoveCommands[X][0][0]; } const char* b() { return (*(sMoveCommands+X))[0][0]; } } // PR5512 and its discussion namespace pr5512 { struct Y { operator short(); operator float(); }; void g_test(Y y) { short s = 0; // DR507, this should be ambiguous, but we special-case assignment s = y; // Note: DR507, this is ambiguous as specified //s += y; } struct S {}; void operator +=(int&, S); void f(S s) { int i = 0; i += s; } struct A {operator int();}; int a; void b(A x) { a += x; } } // PR5900 namespace pr5900 { struct NotAnArray {}; void test0() { NotAnArray x; x[0] = 0; // expected-error {{does not provide a subscript operator}} } struct NonConstArray { int operator[](unsigned); // expected-note {{candidate}} }; int test1() { const NonConstArray x = NonConstArray(); return x[0]; // expected-error {{no viable overloaded operator[] for type}} } // Not really part of this PR, but implemented at the same time. struct NotAFunction {}; void test2() { NotAFunction x; x(); // expected-error {{does not provide a call operator}} } } // Operator lookup through using declarations. namespace N { struct X2 { }; } namespace N2 { namespace M { namespace Inner { template<typename T> N::X2 &operator<<(N::X2&, const T&); } using Inner::operator<<; } } void test_lookup_through_using() { using namespace N2::M; N::X2 x; x << 17; } namespace rdar9136502 { struct X { int i(); // expected-note{{possible target for call}} int i(int); // expected-note{{possible target for call}} }; struct Y { Y &operator<<(int); }; void f(X x, Y y) { y << x .i; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} } } namespace rdar9222009 { class StringRef { inline bool operator==(StringRef LHS, StringRef RHS) { // expected-error{{overloaded 'operator==' must be a binary operator (has 3 parameters)}} return !(LHS == RHS); // expected-error{{invalid operands to binary expression ('rdar9222009::StringRef' and 'rdar9222009::StringRef')}} } }; } namespace PR11784 { struct A { A& operator=(void (*x)()); }; void f(); void f(int); void g() { A x; x = f; } } namespace test10 { struct A { void operator[](float (*fn)(int)); // expected-note 2 {{not viable: no overload of 'bar' matching 'float (*)(int)'}} }; float foo(int); float foo(float); template <class T> T bar(T); template <class T, class U> T bar(U); void test(A &a) { a[&foo]; a[foo]; a[&bar<int>]; // expected-error {{no viable overloaded operator[]}} a[bar<int>]; // expected-error {{no viable overloaded operator[]}} // If these fail, it's because we're not letting the overload // resolution for operator| resolve the overload of 'bar'. a[&bar<float>]; a[bar<float>]; } } struct InvalidOperatorEquals { InvalidOperatorEquals operator=() = delete; // expected-error {{overloaded 'operator=' must be a binary operator}} }; namespace PR7681 { template <typename PT1, typename PT2> class PointerUnion; void foo(PointerUnion<int*, float*> &Result) { Result = 1; // expected-error {{no viable overloaded '='}} // expected-note {{type 'PointerUnion<int *, float *>' is incomplete}} } } namespace PR14995 { struct B {}; template<typename ...T> void operator++(B, T...) {} void f() { B b; b++; // ok ++b; // ok } template<typename... T> struct C { void operator-- (T...) {} }; void g() { C<int> postfix; C<> prefix; postfix--; // ok --prefix; // ok } struct D {}; template<typename T> void operator++(D, T) {} void h() { D d; d++; // ok ++d; // expected-error{{cannot increment value of type 'PR14995::D'}} } template<typename...T> struct E { void operator++(T...) {} // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'char')}} }; E<char> e; // expected-note {{in instantiation of template class 'PR14995::E<char>' requested here}} struct F { template<typename... T> int operator++ (T...) {} }; int k1 = F().operator++(0, 0); int k2 = F().operator++('0'); // expected-error@-5 {{overloaded 'operator++' must be a unary or binary operator}} // expected-note@-3 {{in instantiation of function template specialization 'PR14995::F::operator++<int, int>' requested here}} // expected-error@-4 {{no matching member function for call to 'operator++'}} // expected-note@-8 {{candidate template ignored: substitution failure}} // expected-error@-9 {{parameter of overloaded post-increment operator must have type 'int' (not 'char')}} // expected-note@-6 {{in instantiation of function template specialization 'PR14995::F::operator++<char>' requested here}} // expected-error@-7 {{no matching member function for call to 'operator++'}} // expected-note@-12 {{candidate template ignored: substitution failure}} } // namespace PR14995 namespace ConversionVersusTemplateOrdering { struct A { operator short() = delete; template <typename T> operator T(); } a; struct B { template <typename T> operator T(); operator short() = delete; } b; int x = a; int y = b; } namespace NoADLForMemberOnlyOperators { template<typename T> struct A { typename T::error e; }; // expected-error {{type 'char' cannot be used prior to '::'}} template<typename T> struct B { int n; }; void f(B<A<void> > b1, B<A<int> > b2, B<A<char> > b3) { b1 = b1; // ok, does not instantiate A<void>. (void)b1->n; // expected-error {{is not a pointer}} b2[3]; // expected-error {{does not provide a subscript}} b3 / 0; // expected-note {{in instantiation of}} expected-error {{invalid operands to}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/call-with-static-chain.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s int &f(); struct A { void f(); }; typedef int I; void g() { __builtin_call_with_static_chain(f(), f) = 42; __builtin_call_with_static_chain(A().f(), f); // expected-error {{first argument to __builtin_call_with_static_chain must be a non-member call expression}} __builtin_call_with_static_chain((42).~I(), f); // expected-error {{first argument to __builtin_call_with_static_chain must not be a pseudo-destructor call}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/new-array-size-conv.cpp
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s struct ValueInt { ValueInt(int v = 0) : ValueLength(v) {} operator int () const { return ValueLength; } // expected-note 3{{conversion to integral type 'int' declared here}} private: int ValueLength; }; enum E { e }; struct ValueEnum { operator E() const; // expected-note{{conversion to enumeration type 'E' declared here}} }; struct ValueBoth : ValueInt, ValueEnum { }; struct IndirectValueInt : ValueInt { }; struct TwoValueInts : ValueInt, IndirectValueInt { }; // expected-warning{{direct base 'ValueInt' is inaccessible due to ambiguity:\n struct TwoValueInts -> struct ValueInt\n struct TwoValueInts -> struct IndirectValueInt -> struct ValueInt}} void test() { (void)new int[ValueInt(10)]; // expected-warning{{implicit conversion from array size expression of type 'ValueInt' to integral type 'int' is a C++11 extension}} (void)new int[ValueEnum()]; // expected-warning{{implicit conversion from array size expression of type 'ValueEnum' to enumeration type 'E' is a C++11 extension}} (void)new int[ValueBoth()]; // expected-error{{ambiguous conversion of array size expression of type 'ValueBoth' to an integral or enumeration type}} (void)new int[TwoValueInts()]; // expected-error{{ambiguous conversion of array size expression of type 'TwoValueInts' to an integral or enumeration type}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/gnu-case-ranges.cpp
// RUN: %clang_cc1 -verify -Wno-covered-switch-default %s // expected-no-diagnostics enum E { one, two, three, four }; int test(enum E e) { switch (e) { case one: return 7; case two ... two + 1: return 42; case four: return 25; default: return 0; } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/access-member-pointer.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // PR7694 class A { }; class B : private A { public: void foo(); }; // expected-note {{declared private here}} void B::foo() { (void)static_cast<void(A::*)()>(&B::foo); } void bar() { (void)static_cast<void(A::*)()>(&B::foo); // expected-error {{cannot cast 'B' to its private base class 'A'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx0x-compat.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat -verify %s // RUN: %clang_cc1 -fsyntax-only -std=c++1z -Wc++11-compat -verify %s #if __cplusplus < 201103L namespace N { template<typename T> void f(T) {} // expected-note 2{{here}} namespace M { template void ::N::f<int>(int); // expected-warning {{explicit instantiation of 'f' not in a namespace enclosing 'N'}} } } using namespace N; template void f<char>(char); // expected-warning {{explicit instantiation of 'N::f' must occur in namespace 'N'}} template<typename T> void g(T) {} // expected-note 2{{here}} namespace M { template void g<int>(int); // expected-warning {{explicit instantiation of 'g' must occur at global scope}} template void ::g<char>(char); // expected-warning {{explicit instantiation of 'g' must occur at global scope}} } template inline void g<double>(double); // expected-warning {{explicit instantiation cannot be 'inline'}} void g() { auto int n = 0; // expected-warning {{'auto' storage class specifier is redundant and incompatible with C++11}} } int n; struct S { char c; } s = { n }, // expected-warning {{non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list in C++11}} expected-note {{explicit cast}} t = { 1234 }; // expected-warning {{constant expression evaluates to 1234 which cannot be narrowed to type 'char' in C++11}} expected-warning {{changes value}} expected-note {{explicit cast}} #define PRIuS "uS" int printf(const char *, ...); typedef __typeof(sizeof(int)) size_t; void h(size_t foo, size_t bar) { printf("foo is %"PRIuS", bar is %"PRIuS, foo, bar); // expected-warning 2{{identifier after literal will be treated as a reserved user-defined literal suffix in C++11}} } #define _x + 1 char c = 'x'_x; // expected-warning {{will be treated as a user-defined literal suffix}} template<int ...N> int f() { // expected-warning {{C++11 extension}} return (N + ...); // expected-warning {{C++1z extension}} } #else auto init_capture = [a(0)] {}; // expected-warning {{initialized lambda captures are incompatible with C++ standards before C++14}} static_assert(true); // expected-warning {{incompatible with C++ standards before C++1z}} template<int ...N> int f() { return (N + ...); } // expected-warning {{incompatible with C++ standards before C++1z}} #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/implicit-member-functions.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s struct A { }; A::A() { } // expected-error {{definition of implicitly declared default constructor}} struct B { }; B::B(const B&) { } // expected-error {{definition of implicitly declared copy constructor}} struct C { }; C& C::operator=(const C&) { return *this; } // expected-error {{definition of implicitly declared copy assignment operator}} struct D { }; D::~D() { } // expected-error {{definition of implicitly declared destructor}} // Make sure that the special member functions are introduced for // name-lookup purposes and overload with user-declared // constructors and assignment operators. namespace PR6570 { class A { }; class B { public: B() {} B(const A& a) { operator = (CONST); operator = (a); } B& operator = (const A& a) { return *this; } void f(const A &a) { B b(a); }; static const B CONST; }; } namespace PR7594 { // If the lazy declaration of special member functions is triggered // in an out-of-line initializer, make sure the functions aren't in // the initializer scope. This used to crash Clang: struct C { C(); static C *c; }; C *C::c = new C(); } namespace Recursion { template<typename T> struct InvokeCopyConstructor { static const T &get(); typedef decltype(T(get())) type; // expected-error {{no matching conver}} }; struct B; struct A { // expected-note@-1 {{while substituting deduced template arguments}} typedef B type; template<typename T, typename = typename InvokeCopyConstructor<typename T::type>::type> // expected-note@-1 {{in instantiation of template class}} A(const T &); // expected-note@-1 {{in instantiation of default argument}} }; struct B { // expected-note {{candidate constructor (the implicit move }} B(); // expected-note {{candidate constructor not viable}} A a; }; // Triggering the declaration of B's copy constructor causes overload // resolution to occur for A's copying constructor, which instantiates // InvokeCopyConstructor<B>, which triggers the declaration of B's copy // constructor. Notionally, this happens when we get to the end of the // definition of 'struct B', so there is no declared copy constructor yet. // // This behavior is g++-compatible, but isn't exactly right; the class is // supposed to be incomplete when we implicitly declare its special members. B b = B(); // Another case, which isn't ill-formed under our rules. This is inspired by // a problem which occurs when combining CGAL with libstdc++-4.7. template<typename T> T &&declval(); template<typename T, typename U> struct pair { pair(); template<typename V, typename W, typename = decltype(T(declval<const V&>())), typename = decltype(U(declval<const W&>()))> pair(const pair<V,W> &); }; template<typename K> struct Line; template<typename K> struct Vector { Vector(const Line<K> &l); }; template<typename K> struct Point { Vector<K> v; }; template<typename K> struct Line { pair<Point<K>, Vector<K>> x; }; // Trigger declaration of Line copy ctor, which causes substitution into // pair's templated constructor, which triggers instantiation of the // definition of Point's copy constructor, which performs overload resolution // on Vector's constructors, which requires declaring all of Line's // constructors. That should not find a copy constructor (because we've not // declared it yet), but by the time we get all the way back here, we should // find the copy constructor. Line<void> L1; Line<void> L2(L1); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-declspec-ignored.cpp
// RUN: %clang_cc1 %s -verify -fsyntax-only namespace test1 { __attribute__((visibility("hidden"))) __attribute__((aligned)) class A; // expected-warning{{attribute 'visibility' is ignored, place it after "class" to apply attribute to type declaration}} \ // expected-warning{{attribute 'aligned' is ignored, place it after "class" to apply attribute to type declaration}} __attribute__((visibility("hidden"))) __attribute__((aligned)) struct B; // expected-warning{{attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration}} \ // expected-warning{{attribute 'aligned' is ignored, place it after "struct" to apply attribute to type declaration}} __attribute__((visibility("hidden"))) __attribute__((aligned)) union C; // expected-warning{{attribute 'visibility' is ignored, place it after "union" to apply attribute to type declaration}} \ // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}} __attribute__((visibility("hidden"))) __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \ // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}} } namespace test2 { __attribute__((visibility("hidden"))) __attribute__((aligned)) class A {} a; __attribute__((visibility("hidden"))) __attribute__((aligned)) struct B {} b; __attribute__((visibility("hidden"))) __attribute__((aligned)) union C {} c; __attribute__((visibility("hidden"))) __attribute__((aligned)) enum D {D} d; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/vtordisp-mode.cpp
// RUN: %clang_cc1 -triple i686-pc-win32 -std=c++11 -vtordisp-mode=0 -DVTORDISP_MODE=0 %s -verify // RUN: %clang_cc1 -triple i686-pc-win32 -std=c++11 -vtordisp-mode=1 -DVTORDISP_MODE=1 %s -verify // RUN: %clang_cc1 -triple i686-pc-win32 -std=c++11 -vtordisp-mode=2 -DVTORDISP_MODE=2 %s -verify // expected-no-diagnostics struct A { A(); virtual void foo(); }; // At /vd1, there is a vtordisp before A. struct B : virtual A { B(); virtual void foo(); virtual void bar(); }; // At /vd2, there is a vtordisp before B, but only because it has its own // vftable. struct C : virtual B { C(); }; // There are two vfptrs, two vbptrs, and some number of vtordisps. static_assert(sizeof(C) == 2 * 4 + 2 * 4 + 4 * VTORDISP_MODE, "size mismatch");
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/lookup-member.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace A { class String; // expected-note {{target of using declaration}} }; using A::String; // expected-note {{using declaration}} class String; // expected-error {{conflicts with target of using declaration}} // rdar://8603569 union value { char *String; };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/qual-id-test.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace A { namespace B { struct base // expected-note{{object type}} { void x() {} void y() {} }; } struct member { void foo(); }; struct middleman { member * operator->() { return 0; } }; struct sub : B::base { void x() {} middleman operator->() { return middleman(); } }; } struct bad { int x(); }; namespace C { void fun() { A::sub a; a.x(); a.sub::x(); a.base::x(); a.B::base::x(); // expected-error{{use of undeclared identifier 'B'}} a.A::sub::x(); a.A::B::base::x(); a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}} a->foo(); a->member::foo(); a->A::member::foo(); } void fun2() { A::sub *a; a->x(); a->sub::x(); a->base::x(); a->B::base::x(); // expected-error{{use of undeclared identifier 'B'}} a->A::sub::x(); a->A::B::base::x(); a->bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}} (*a)->foo(); (*a)->member::foo(); (*a)->A::member::foo(); } void fun3() { int i; i.foo(); // expected-error{{member reference base type 'int' is not a structure or union}} } void fun4a() { A::sub *a; typedef A::member base; // expected-note{{current scope}} a->base::x(); // expected-error{{ambiguous}} } void fun4b() { A::sub *a; typedef A::B::base base; a->base::x(); } template<typename T> void fun5() { T a; a.x(); a->foo(); a.A::sub::x(); a.A::B::base::x(); a->A::member::foo(); a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}} } void test_fun5() { fun5<A::sub>(); // expected-note{{instantiation}} } template<typename T> void fun6() { T a; a.sub::x(); a.base::x(); a->member::foo(); a.B::base::x(); // expected-error{{use of undeclared identifier 'B'}} } void test_fun6() { fun6<A::sub>(); // expected-note{{instantiation}} } } // PR4703 struct a { int a; static int sa; }; a a; int a::sa = a.a; // expected-error {{invalid use of non-static data member 'a'}} namespace PR6645 { typedef int foo; namespace Inner { typedef int PR6645::foo; // expected-error{{typedef declarator cannot be qualified}} \ // expected-error{{cannot define or redeclare 'foo' here because namespace 'Inner' does not enclose namespace 'PR6645'}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/out-of-line-def-mismatch.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s namespace N2 { struct S1; namespace N1 { class C1 {}; struct S2 { void func(S1*); // expected-note {{type of 1st parameter of member declaration does not match definition ('N2::S1 *' vs 'N2::N1::S1 *')}} void func(C1&, unsigned, const S1*); // expected-note {{type of 3rd parameter of member declaration does not match definition ('const N2::S1 *' vs 'const N2::N1::S1 *')}} void func(const S1*, unsigned); //expected-note {{type of 1st parameter of member declaration does not match definition ('const N2::S1 *' vs 'N2::N1::S1')}} void func(unsigned, const S1*); // expected-note {{type of 1st parameter of member declaration does not match definition ('unsigned int' vs 'unsigned int *')}} }; struct S1 {}; } } void N2::N1::S2::func(S1*) {} // expected-error {{out-of-line definition of 'func' does not match any declaration in 'N2::N1::S2'}} void N2::N1::S2::func(C1&, unsigned, const S1*) {} // expected-error {{out-of-line definition of 'func' does not match any declaration in 'N2::N1::S2'}} void N2::N1::S2::func(S1*, double) {} // expected-error {{out-of-line definition of 'func' does not match any declaration in 'N2::N1::S2'}} void N2::N1::S2::func(S1, unsigned) {} // expected-error {{out-of-line definition of 'func' does not match any declaration in 'N2::N1::S2'}} void N2::N1::S2::func(unsigned*, S1*) {} // expected-error {{out-of-line definition of 'func' does not match any declaration in 'N2::N1::S2'}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-no-sanitize-thread.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s #define NO_SANITIZE_THREAD __attribute__((no_sanitize_thread)) #if !__has_attribute(no_sanitize_thread) #error "Should support no_sanitize_thread" #endif void noanal_fun() NO_SANITIZE_THREAD; void noanal_fun_args() __attribute__((no_sanitize_thread(1))); // \ // expected-error {{'no_sanitize_thread' attribute takes no arguments}} int noanal_testfn(int y) NO_SANITIZE_THREAD; int noanal_testfn(int y) { int x NO_SANITIZE_THREAD = y; // \ // expected-error {{'no_sanitize_thread' attribute only applies to functions}} return x; } int noanal_test_var NO_SANITIZE_THREAD; // \ // expected-error {{'no_sanitize_thread' attribute only applies to functions}} class NoanalFoo { private: int test_field NO_SANITIZE_THREAD; // \ // expected-error {{'no_sanitize_thread' attribute only applies to functions}} void test_method() NO_SANITIZE_THREAD; }; class NO_SANITIZE_THREAD NoanalTestClass { // \ // expected-error {{'no_sanitize_thread' attribute only applies to functions}} }; void noanal_fun_params(int lvar NO_SANITIZE_THREAD); // \ // expected-error {{'no_sanitize_thread' attribute only applies to functions}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR8012.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 void foo(int operator+); // expected-error{{'operator+' cannot be the name of a parameter}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR8755.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s template <typename T> struct A { typedef int iterator; // expected-note{{declared here}} }; template <typename T> void f() { class A <T> ::iterator foo; // expected-error{{elaborated type refers to a typedef}} } void g() { f<int>(); // expected-note{{in instantiation of function template}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/copy-initialization.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s class X { public: explicit X(const X&); // expected-note {{candidate constructor}} X(int*); // expected-note 3{{candidate constructor}} explicit X(float*); // expected-note {{candidate constructor}} }; class Y : public X { }; void f(Y y, int *ip, float *fp) { X x1 = y; // expected-error{{no matching constructor for initialization of 'X'}} X x2 = 0; X x3 = ip; X x4 = fp; // expected-error{{no viable conversion}} X x2a(0); // expected-error{{call to constructor of 'X' is ambiguous}} X x3a(ip); X x4a(fp); } struct foo { void bar(); // expected-note{{declared here}} }; // PR3600 void test(const foo *P) { P->bar(); } // expected-error{{'bar' not viable: 'this' argument has type 'const foo', but function is not marked const}} namespace PR6757 { struct Foo { Foo(); Foo(Foo&); // expected-note{{candidate constructor not viable}} }; struct Bar { operator const Foo&() const; }; void f(Foo); void g(Foo foo) { f(Bar()); // expected-error{{no viable constructor copying parameter of type 'const PR6757::Foo'}} f(foo); } } namespace DR5 { // Core issue 5: if a temporary is created in copy-initialization, it is of // the cv-unqualified version of the destination type. namespace Ex1 { struct C { }; C c; struct A { A(const A&); A(const C&); }; const volatile A a = c; // ok } namespace Ex2 { struct S { S(S&&); // expected-warning {{C++11}} S(int); }; const S a(0); const S b = 0; } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/unknown-type-name.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // PR3990 namespace N { struct Wibble { }; typedef Wibble foo; int zeppelin; // expected-note{{declared here}} } using namespace N; foo::bar x; // expected-error{{no type named 'bar' in 'N::Wibble'}} void f() { foo::bar = 4; // expected-error{{no member named 'bar' in 'N::Wibble'}} } int f(foo::bar); // expected-error{{no type named 'bar' in 'N::Wibble'}} int f(doulbe); // expected-error{{did you mean 'double'?}} int fun(zapotron); // expected-error{{unknown type name 'zapotron'}} int var(zepelin); // expected-error{{did you mean 'zeppelin'?}} template<typename T> struct A { typedef T type; type f(); type g(); static int n; static type m; static int h(T::type, int); // expected-error{{missing 'typename'}} static int h(T::type x, char); // expected-error{{missing 'typename'}} }; template<typename T> A<T>::type g(T t) { return t; } // expected-error{{missing 'typename'}} template<typename T> A<T>::type A<T>::f() { return type(); } // expected-error{{missing 'typename'}} template<typename T> void f(T::type) { } // expected-error{{missing 'typename'}} template<typename T> void g(T::type x) { } // expected-error{{missing 'typename'}} template<typename T> void f(T::type, int) { } // expected-error{{missing 'typename'}} template<typename T> void f(T::type x, char) { } // expected-error{{missing 'typename'}} template<typename T> void f(int, T::type) { } // expected-error{{missing 'typename'}} template<typename T> void f(char, T::type x) { } // expected-error{{missing 'typename'}} template<typename T> void f(int, T::type, int) { } // expected-error{{missing 'typename'}} template<typename T> void f(int, T::type x, char) { } // expected-error{{missing 'typename'}} int *p; // FIXME: We should assume that 'undeclared' is a type, not a parameter name // here, and produce an 'unknown type name' diagnostic instead. int f1(undeclared, int); // expected-error{{requires a type specifier}} int f2(undeclared, 0); // expected-error{{undeclared identifier}} int f3(undeclared *p, int); // expected-error{{unknown type name 'undeclared'}} int f4(undeclared *p, 0); // expected-error{{undeclared identifier}} int *test(UnknownType *fool) { return 0; } // expected-error{{unknown type name 'UnknownType'}} template<typename T> int A<T>::n(T::value); // ok template<typename T> A<T>::type // expected-error{{missing 'typename'}} A<T>::m(T::value, 0); // ok template<typename T> int A<T>::h(T::type, int) {} // expected-error{{missing 'typename'}} template<typename T> int A<T>::h(T::type x, char) {} // expected-error{{missing 'typename'}} template<typename T> int h(T::type, int); // expected-error{{missing 'typename'}} template<typename T> int h(T::type x, char); // expected-error{{missing 'typename'}} template<typename T> int junk1(T::junk); // expected-warning{{variable templates are a C++14 extension}} template<typename T> int junk2(T::junk) throw(); // expected-error{{missing 'typename'}} template<typename T> int junk3(T::junk) = delete; // expected-error{{missing 'typename'}} expected-warning{{C++11}} template<typename T> int junk4(T::junk j); // expected-error{{missing 'typename'}} // FIXME: We can tell this was intended to be a function because it does not // have a dependent nested name specifier. template<typename T> int i(T::type, int()); // expected-warning{{variable templates are a C++14 extension}} // FIXME: We know which type specifier should have been specified here. Provide // a fix-it to add 'typename A<T>::type' template<typename T> A<T>::g() { } // expected-error{{requires a type specifier}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/alias-template.cpp
// RUN: %clang_cc1 -verify -std=c++11 %s namespace RedeclAliasTypedef { template<typename U> using T = int; template<typename U> using T = int; template<typename U> using T = T<U>; } namespace IllegalTypeIds { template<typename U> using A = void(int n = 0); // expected-error {{default arguments can only be specified for parameters in a function declaration}} template<typename U> using B = inline void(int n); // expected-error {{type name does not allow function specifier}} template<typename U> using C = virtual void(int n); // expected-error {{type name does not allow function specifier}} template<typename U> using D = explicit void(int n); // expected-error {{type name does not allow function specifier}} template<typename U> using E = void(int n) throw(); // expected-error {{exception specifications are not allowed in type aliases}} template<typename U> using F = void(*)(int n) &&; // expected-error {{pointer to function type cannot have '&&' qualifier}} template<typename U> using G = __thread void(int n); // expected-error {{type name does not allow storage class to be specified}} template<typename U> using H = constexpr int; // expected-error {{type name does not allow constexpr specifier}} template<typename U> using Y = void(int n); // ok template<typename U> using Z = void(int n) &&; // ok } namespace IllegalSyntax { template<typename Z> using ::T = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} template<typename Z> using operator int = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} template<typename Z> using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}} template<typename Z> using typename ::V = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} template<typename Z> using typename ::operator bool = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} } namespace VariableLengthArrays { template<typename Z> using T = int[42]; // ok int n = 32; template<typename Z> using T = int[n]; // expected-error {{variable length array declaration not allowed at file scope}} const int m = 42; template<typename Z> using U = int[m]; // expected-note {{previous definition}} template<typename Z> using U = int[42]; // ok template<typename Z> using U = int; // expected-error {{type alias template redefinition with different types ('int' vs 'int [42]')}} } namespace RedeclFunc { int f(int, char**); template<typename Z> using T = int; T<char> f(int, char **); // ok } namespace LookupFilter { namespace N { template<typename U> using S = int; } using namespace N; template<typename U> using S = S<U>*; // ok } namespace InFunctions { template<typename...T> struct S0 { template<typename Z> using U = T*; // expected-error {{declaration type contains unexpanded parameter pack 'T'}} U<char> u; }; template<typename Z> using T1 = int; template<typename Z> using T2 = int[-1]; // expected-error {{array size is negative}} template<typename...T> struct S3 { // expected-note {{template parameter is declared here}} template<typename Z> using T = int; // expected-error {{declaration of 'T' shadows template parameter}} }; template<typename Z> using Z = Z; } namespace ClassNameRedecl { class C0 { template<typename U> using C0 = int; // expected-error {{member 'C0' has the same name as its class}} }; class C1 { template<typename U> using C1 = C1; // expected-error {{member 'C1' has the same name as its class}} }; class C2 { template<typename U> using C0 = C1; // ok }; template<typename...T> class C3 { template<typename U> using f = T; // expected-error {{declaration type contains unexpanded parameter pack 'T'}} }; template<typename T> class C4 { // expected-note {{template parameter is declared here}} template<typename U> using T = int; // expected-error {{declaration of 'T' shadows template parameter}} }; class C5 { class c; // expected-note {{previous definition}} template<typename U> using c = int; // expected-error {{redefinition of 'c' as different kind of symbol}} class d; // expected-note {{previous definition}} template<typename U> using d = d; // expected-error {{redefinition of 'd' as different kind of symbol}} }; class C6 { class c { template<typename U> using C6 = int; }; // ok }; } class CtorDtorName { template<typename T> using X = CtorDtorName; X<int>(); // expected-error {{expected member name}} ~X<int>(); // expected-error {{destructor cannot be declared using a type alias}} }; namespace TagName { template<typename Z> using S = struct { int n; }; // expected-error {{cannot be defined}} template<typename Z> using T = class { int n; }; // expected-error {{cannot be defined}} template<typename Z> using U = enum { a, b, c }; // expected-error {{cannot be defined}} template<typename Z> using V = struct V { int n; }; // expected-error {{'TagName::V' cannot be defined in a type alias template}} } namespace StdExample { template<typename T, typename U> struct pair; template<typename T> using handler_t = void (*)(T); extern handler_t<int> ignore; extern void (*ignore)(int); // FIXME: we recover as if cell is an undeclared variable. the diagnostics are terrible! template<typename T> using cell = pair<T*, cell<T>*>; // expected-error {{use of undeclared identifier 'cell'}} \ expected-error {{'T' does not refer to a value}} \ expected-note {{declared here}} \ expected-error {{expected ';' after alias declaration}} } namespace Access { class C0 { template<typename Z> using U = int; // expected-note {{declared private here}} }; C0::U<int> v; // expected-error {{'U' is a private member}} class C1 { public: template<typename Z> using U = int; }; C1::U<int> w; // ok } namespace VoidArg { template<typename Z> using V = void; V<int> f(int); // ok V<char> g(V<double>); // ok (DR577) } namespace Curried { template<typename T, typename U> struct S; template<typename T> template<typename U> using SS = S<T, U>; // expected-error {{extraneous template parameter list in alias template declaration}} } // PR12647 namespace SFINAE { template<bool> struct enable_if; // expected-note 2{{here}} template<> struct enable_if<true> { using type = void; }; template<typename T> struct is_enum { static constexpr bool value = __is_enum(T); }; template<typename T> using EnableIf = typename enable_if<T::value>::type; // expected-error {{undefined template}} template<typename T> using DisableIf = typename enable_if<!T::value>::type; // expected-error {{undefined template}} template<typename T> EnableIf<is_enum<T>> f(); template<typename T> DisableIf<is_enum<T>> f(); enum E { e }; int main() { f<int>(); f<E>(); } template<typename T, typename U = EnableIf<is_enum<T>>> struct fail1 {}; // expected-note {{here}} template<typename T> struct fail2 : DisableIf<is_enum<T>> {}; // expected-note {{here}} fail1<int> f1; // expected-note {{here}} fail2<E> f2; // expected-note {{here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/namespace-alias.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace N { struct X { }; }; namespace A = N; int B; // expected-note {{previous definition is here}} namespace B = N; // expected-error {{redefinition of 'B' as different kind of symbol}} namespace C { } // expected-note {{previous definition is here}} namespace C = N; // expected-error {{redefinition of 'C'}} int i; namespace D = i; // expected-error {{expected namespace name}} namespace E1 = N:: Foo; // expected-error {{expected namespace name}} namespace E2 = N:: X; // expected-error {{expected namespace name}} namespace F { namespace A { namespace B { } } // expected-note {{candidate found by name lookup is 'F::A::B'}} namespace B { } // expected-note {{candidate found by name lookup is 'F::B'}} using namespace A; namespace D = B; // expected-error {{reference to 'B' is ambiguous}} } namespace G { namespace B = N; } namespace H { namespace A1 { } namespace A2 { } // These all point to A1. namespace B = A1; namespace B = A1; namespace C = B; namespace B = C; // expected-note {{previously defined as an alias for 'A1'}} namespace B = A2; // expected-error {{redefinition of 'B' as an alias for a different namespace}} } namespace I { namespace A1 { int i; } namespace A2 = A1; } int f() { return I::A2::i; } namespace J { namespace A { namespace B { void func (); } } namespace C = A; using namespace C::B; void g() { func(); } } namespace K { namespace KA { void func(); } void f() { namespace KB = KA; KB::func(); } template <class T> void g() { namespace KC = KA; KC::func(); } template void g<int>(); template void g<long>(); void h() { KB::func(); // expected-error {{undeclared identifier 'KB'}} KC::func(); // expected-error {{undeclared identifier 'KC'}} } } namespace { class C1; } namespace { class C1; } C1 *pc1 = 0; namespace N { namespace { class C2; } } namespace N { namespace { class C2; } } N::C2 *pc2 = 0; // PR6341 namespace A = N; namespace N { } namespace A = N; A::X nx; namespace PR7014 { namespace X { namespace Y {} } using namespace X; namespace Y = X::Y; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/member-pointer.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct A {}; enum B { Dummy }; namespace C {} struct D : A {}; struct E : A {}; struct F : D, E {}; struct G : virtual D {}; class H : A {}; // expected-note 2{{implicitly declared private here}} int A::*pdi1; int (::A::*pdi2); int (A::*pfi)(int); void (*A::*ppfie)() throw(); // expected-error {{exception specifications are not allowed beyond a single level of indirection}} int B::*pbi; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}} \ // expected-error {{'pbi' does not point into a class}} int C::*pci; // expected-error {{'pci' does not point into a class}} void A::*pdv; // expected-error {{'pdv' declared as a member pointer to void}} int& A::*pdr; // expected-error {{'pdr' declared as a member pointer to a reference}} void f() { // This requires tentative parsing. int (A::*pf)(int, int); // Implicit conversion to bool. bool b = pdi1; b = pfi; // Conversion from null pointer constant. pf = 0; pf = __null; // Conversion to member of derived. int D::*pdid = pdi1; pdid = pdi2; // Fail conversion due to ambiguity and virtuality. int F::*pdif = pdi1; // expected-error {{ambiguous conversion from pointer to member of base class 'A' to pointer to member of derived class 'F':}} int G::*pdig = pdi1; // expected-error {{conversion from pointer to member of class 'A' to pointer to member of class 'G' via virtual base 'D' is not allowed}} // Conversion to member of base. pdi1 = pdid; // expected-error {{assigning to 'int A::*' from incompatible type 'int D::*'}} // Comparisons int (A::*pf2)(int, int); int (D::*pf3)(int, int) = 0; bool b1 = (pf == pf2); (void)b1; bool b2 = (pf != pf2); (void)b2; bool b3 = (pf == pf3); (void)b3; bool b4 = (pf != 0); (void)b4; } struct TheBase { void d(); }; struct HasMembers : TheBase { int i; void f(); void g(); void g(int); static void g(double); }; namespace Fake { int i; void f(); } void g() { HasMembers hm; int HasMembers::*pmi = &HasMembers::i; int *pni = &Fake::i; int *pmii = &hm.i; void (HasMembers::*pmf)() = &HasMembers::f; void (*pnf)() = &Fake::f; &hm.f; // expected-error {{cannot create a non-constant pointer to member function}} void (HasMembers::*pmgv)() = &HasMembers::g; void (HasMembers::*pmgi)(int) = &HasMembers::g; void (*pmgd)(double) = &HasMembers::g; void (HasMembers::*pmd)() = &HasMembers::d; } struct Incomplete; void h() { HasMembers hm, *phm = &hm; int HasMembers::*pi = &HasMembers::i; hm.*pi = 0; int i = phm->*pi; (void)&(hm.*pi); (void)&(phm->*pi); (void)&((&hm)->*pi); void (HasMembers::*pf)() = &HasMembers::f; (hm.*pf)(); (phm->*pf)(); (void)(hm->*pi); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'HasMembers'}} (void)(phm.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'HasMembers *'}} (void)(i.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'int'}} int *ptr; (void)(ptr->*pi); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'int *'}} int A::*pai = 0; D d, *pd = &d; (void)(d.*pai); (void)(pd->*pai); F f, *ptrf = &f; (void)(f.*pai); // expected-error {{ambiguous conversion from derived class 'F' to base class 'A'}} (void)(ptrf->*pai); // expected-error {{ambiguous conversion from derived class 'F' to base class 'A'}} H h, *ptrh = &h; (void)(h.*pai); // expected-error {{cannot cast 'H' to its private base class 'A'}} (void)(ptrh->*pai); // expected-error {{cannot cast 'H' to its private base class 'A'}} (void)(hm.*i); // expected-error {{pointer-to-member}} (void)(phm->*i); // expected-error {{pointer-to-member}} // Okay Incomplete *inc; int Incomplete::*pii = 0; (void)(inc->*pii); } struct OverloadsPtrMem { int operator ->*(const char *); }; void i() { OverloadsPtrMem m; int foo = m->*"Awesome!"; } namespace pr5985 { struct c { void h(); void f() { void (c::*p)(); p = &h; // expected-error {{must explicitly qualify}} p = &this->h; // expected-error {{cannot create a non-constant pointer to member function}} p = &(*this).h; // expected-error {{cannot create a non-constant pointer to member function}} } }; } namespace pr6783 { struct Base {}; struct X; // expected-note {{forward declaration}} int test1(int Base::* p2m, X* object) { return object->*p2m; // expected-error {{left hand operand to ->*}} } } namespace PR7176 { namespace base { struct Process { }; struct Continuous : Process { bool cond(); }; } typedef bool( base::Process::*Condition )(); void m() { (void)(Condition) &base::Continuous::cond; } } namespace rdar8358512 { // We can't call this with an overload set because we're not allowed // to look into overload sets unless the parameter has some kind of // function type. template <class F> void bind(F f); // expected-note 12 {{candidate template ignored}} template <class F, class T> void bindmem(F (T::*f)()); // expected-note 4 {{candidate template ignored}} template <class F> void bindfn(F (*f)()); // expected-note 4 {{candidate template ignored}} struct A { void nonstat(); void nonstat(int); void mixed(); static void mixed(int); static void stat(); static void stat(int); template <typename T> struct Test0 { void test() { bind(&nonstat); // expected-error {{no matching function for call}} bind(&A::nonstat); // expected-error {{no matching function for call}} bind(&mixed); // expected-error {{no matching function for call}} bind(&A::mixed); // expected-error {{no matching function for call}} bind(&stat); // expected-error {{no matching function for call}} bind(&A::stat); // expected-error {{no matching function for call}} } }; template <typename T> struct Test1 { void test() { bindmem(&nonstat); // expected-error {{no matching function for call}} bindmem(&A::nonstat); bindmem(&mixed); // expected-error {{no matching function for call}} bindmem(&A::mixed); bindmem(&stat); // expected-error {{no matching function for call}} bindmem(&A::stat); // expected-error {{no matching function for call}} } }; template <typename T> struct Test2 { void test() { bindfn(&nonstat); // expected-error {{no matching function for call}} bindfn(&A::nonstat); // expected-error {{no matching function for call}} bindfn(&mixed); // expected-error {{no matching function for call}} bindfn(&A::mixed); // expected-error {{no matching function for call}} bindfn(&stat); bindfn(&A::stat); } }; }; template <class T> class B { void nonstat(); void nonstat(int); void mixed(); static void mixed(int); static void stat(); static void stat(int); // None of these can be diagnosed yet, because the arguments are // still dependent. void test0a() { bind(&nonstat); bind(&B::nonstat); bind(&mixed); bind(&B::mixed); bind(&stat); bind(&B::stat); } void test0b() { bind(&nonstat); // expected-error {{no matching function for call}} bind(&B::nonstat); // expected-error {{no matching function for call}} bind(&mixed); // expected-error {{no matching function for call}} bind(&B::mixed); // expected-error {{no matching function for call}} bind(&stat); // expected-error {{no matching function for call}} bind(&B::stat); // expected-error {{no matching function for call}} } }; template void B<int>::test0b(); // expected-note {{in instantiation}} } namespace PR9973 { template<class R, class T> struct dm { typedef R T::*F; F f_; template<class U> int & call(U u) { return u->*f_; } // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}} template<class U> int operator()(U u) { call(u); } // expected-note{{in instantiation of}} }; template<class R, class T> dm<R, T> mem_fn(R T::*) ; struct test { int nullary_v(); }; void f() { test* t; mem_fn(&test::nullary_v)(t); // expected-note{{in instantiation of}} } } namespace test8 { struct A { int foo; }; int test1() { // Verify that we perform (and check) an lvalue conversion on the operands here. return (*((A**) 0)) // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} ->**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} } int test2() { // Verify that we perform (and check) an lvalue conversion on the operands here. // TODO: the .* should itself warn about being a dereference of null. return (*((A*) 0)) .**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/atomic-type.cpp
// RUN: %clang_cc1 -verify -pedantic %s -std=c++98 // RUN: %clang_cc1 -verify -pedantic %s -std=c++11 template<typename T> struct atomic { _Atomic(T) value; void f() _Atomic; // expected-error {{expected ';' at end of declaration list}} }; template<typename T> struct user { struct inner { char n[sizeof(T)]; }; atomic<inner> i; }; user<int> u; // Test overloading behavior of atomics. struct A { }; int &ovl1(_Atomic(int)); int &ovl1(_Atomic int); // ok, redeclaration long &ovl1(_Atomic(long)); float &ovl1(_Atomic(float)); double &ovl1(_Atomic(A const *const *)); double &ovl1(A const *const *_Atomic); short &ovl1(_Atomic(A **)); void test_overloading(int i, float f, _Atomic(int) ai, _Atomic(float) af, long l, _Atomic(long) al, A const *const *acc, A const ** ac, A **a) { int& ir1 = ovl1(i); int& ir2 = ovl1(ai); long& lr1 = ovl1(l); long& lr2 = ovl1(al); float &fr1 = ovl1(f); float &fr2 = ovl1(af); double &dr1 = ovl1(acc); double &dr2 = ovl1(ac); short &sr1 = ovl1(a); } typedef int (A::*fp)() _Atomic; // expected-error {{expected ';' after top level declarator}} expected-warning {{does not declare anything}} typedef _Atomic(int(A::*)) atomic_mem_ptr_to_int; typedef int(A::*_Atomic atomic_mem_ptr_to_int); typedef _Atomic(int)(A::*mem_ptr_to_atomic_int); typedef _Atomic int(A::*mem_ptr_to_atomic_int); typedef _Atomic(int)&atomic_int_ref; typedef _Atomic int &atomic_int_ref; typedef _Atomic atomic_int_ref atomic_int_ref; // expected-warning {{'_Atomic' qualifier on reference type 'atomic_int_ref' (aka '_Atomic(int) &') has no effect}} typedef int &_Atomic atomic_reference_to_int; // expected-error {{'_Atomic' qualifier may not be applied to a reference}} typedef _Atomic(int &) atomic_reference_to_int; // expected-error {{_Atomic cannot be applied to reference type 'int &'}} struct S { _Atomic union { int n; }; // expected-warning {{anonymous union cannot be '_Atomic'}} }; namespace copy_init { struct X { X(int); int n; }; _Atomic(X) y = X(0); _Atomic(X) z(X(0)); void f() { y = X(0); } _Atomic(X) e1(0); // expected-error {{cannot initialize}} #if __cplusplus >= 201103L _Atomic(X) e2{0}; // expected-error {{illegal initializer}} _Atomic(X) a{X(0)}; // FIXME: This does not seem like the right answer. _Atomic(int) e3{0}; // expected-error {{illegal initializer}} #endif struct Y { _Atomic(X) a; _Atomic(int) b; }; Y y1 = { X(0), 4 }; Y y2 = { 0, 4 }; // expected-error {{cannot initialize}} // FIXME: It's not really clear if we should allow these. Generally, C++11 // allows extraneous braces around initializers. We should at least give the // same answer in all these cases: Y y3 = { X(0), { 4 } }; // expected-error {{illegal initializer type}} Y y4 = { { X(0) }, 4 }; _Atomic(int) ai = { 4 }; // expected-error {{illegal initializer type}} _Atomic(X) ax = { X(0) }; } bool PR21836(_Atomic(int) *x) { return *x; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR10177.cpp
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s // RUN: %clang_cc1 -fsyntax-only -std=c++1y -verify %s -DCXX1Y #ifndef CXX1Y template<typename T, typename U, U> using alias_ref = T; template<typename T, typename U, U> void func_ref() {} template<typename T, typename U, U> struct class_ref {}; template<int N> struct U { static int a; }; template<int N> struct S; // expected-note 6{{here}} template<int N> int U<N>::a = S<N>::kError; // expected-error 6{{undefined}} template<typename T> void f() { (void)alias_ref<int, int&, U<0>::a>(); // expected-note {{here}} (void)func_ref<int, int&, U<1>::a>(); // expected-note {{here}} (void)class_ref<int, int&, U<2>::a>(); // expected-note {{here}} }; template<int N> void fi() { (void)alias_ref<int, int&, U<N>::a>(); // expected-note {{here}} (void)func_ref<int, int&, U<N+1>::a>(); // expected-note {{here}} (void)class_ref<int, int&, U<N+2>::a>(); // expected-note {{here}} }; int main() { f<int>(); // NOTE: Non-dependent name uses are type-checked at template definition time. fi<10>(); // expected-note 3{{here}} } namespace N { template<typename T> struct S { static int n; }; template<typename T> int S<T>::n = 5; void g(int*); template<typename T> int f() { int k[S<T>::n]; g(k); return k[3]; } int j = f<int>(); } #else // expected-no-diagnostics namespace { template<typename> extern int n; } template<typename T> int g() { return n<int>; } #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/altivec.cpp
// RUN: %clang_cc1 -faltivec -fno-lax-vector-conversions -triple powerpc-unknown-unknown -fcxx-exceptions -verify %s typedef int V4i __attribute__((vector_size(16))); void test_vec_step(vector short arg1) { vector bool char vbc; vector signed char vsc; vector unsigned char vuc; vector bool short vbs; vector short vs; vector unsigned short vus; vector pixel vp; vector bool int vbi; vector int vi; vector unsigned int vui; vector float vf; vector int *pvi; int res1[vec_step(arg1) == 8 ? 1 : -1]; int res2[vec_step(vbc) == 16 ? 1 : -1]; int res3[vec_step(vsc) == 16 ? 1 : -1]; int res4[vec_step(vuc) == 16 ? 1 : -1]; int res5[vec_step(vbs) == 8 ? 1 : -1]; int res6[vec_step(vs) == 8 ? 1 : -1]; int res7[vec_step(vus) == 8 ? 1 : -1]; int res8[vec_step(vp) == 8 ? 1 : -1]; int res9[vec_step(vbi) == 4 ? 1 : -1]; int res10[vec_step(vi) == 4 ? 1 : -1]; int res11[vec_step(vui) == 4 ? 1 : -1]; int res12[vec_step(vf) == 4 ? 1 : -1]; int res13[vec_step(*pvi) == 4 ? 1 : -1]; } void f(V4i a) { } void test1() { V4i vGCC; vector int vAltiVec; f(vAltiVec); vGCC = vAltiVec; bool res = vGCC > vAltiVec; vAltiVec = 0 ? vGCC : vGCC; } template<typename T> void template_f(T param) { param++; } void test2() { vector int vi; ++vi; vi++; --vi; vi--; vector float vf; vf++; ++vi=vi; // expected-warning {{unsequenced}} (++vi)[1]=1; template_f(vi); } namespace LValueToRValueConversions { struct Struct { float f(); int n(); }; vector float initFloat = (vector float)(Struct().f); // expected-error {{did you mean to call it}} vector int initInt = (vector int)(Struct().n); // expected-error {{did you mean to call it}} } void f() { try {} catch (vector pixel px) {} };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/ptrtomember-overload-resolution.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 // expected-no-diagnostics // 13.3.3.2 Ranking implicit conversion sequences // conversion of A::* to B::* is better than conversion of A::* to C::*, struct A { int Ai; }; struct B : public A {}; struct C : public B {}; const char * f(int C::*){ return ""; } int f(int B::*) { return 1; } struct D : public C {}; const char * g(int B::*){ return ""; } int g(int D::*) { return 1; } void test() { int i = f(&A::Ai); const char * str = g(&A::Ai); } // conversion of B::* to C::* is better than conversion of A::* to C::* typedef void (A::*pmfa)(); typedef void (B::*pmfb)(); typedef void (C::*pmfc)(); struct X { operator pmfa(); operator pmfb(); }; void g(pmfc); void test2(X x) { g(x); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-memsize-comparison.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // typedef __SIZE_TYPE__ size_t; extern "C" void *memset(void *, int, size_t); extern "C" void *memmove(void *s1, const void *s2, size_t n); extern "C" void *memcpy(void *s1, const void *s2, size_t n); extern "C" void *memcmp(void *s1, const void *s2, size_t n); extern "C" int strncmp(const char *s1, const char *s2, size_t n); extern "C" int strncasecmp(const char *s1, const char *s2, size_t n); extern "C" char *strncpy(char *dst, const char *src, size_t n); extern "C" char *strncat(char *dst, const char *src, size_t n); extern "C" char *strndup(const char *src, size_t n); extern "C" size_t strlcpy(char *dst, const char *src, size_t size); extern "C" size_t strlcat(char *dst, const char *src, size_t size); void f() { char b1[80], b2[80]; if (memset(b1, 0, sizeof(b1) != 0)) {} // \ expected-warning{{size argument in 'memset' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (memset(b1, 0, sizeof(b1)) != 0) {} if (memmove(b1, b2, sizeof(b1) == 0)) {} // \ expected-warning{{size argument in 'memmove' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (memmove(b1, b2, sizeof(b1)) == 0) {} if (memcpy(b1, b2, sizeof(b1) < 0)) {} // \ expected-warning{{size argument in 'memcpy' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (memcpy(b1, b2, sizeof(b1)) < 0) {} if (memcmp(b1, b2, sizeof(b1) <= 0)) {} // \ expected-warning{{size argument in 'memcmp' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (memcmp(b1, b2, sizeof(b1)) <= 0) {} if (strncmp(b1, b2, sizeof(b1) > 0)) {} // \ expected-warning{{size argument in 'strncmp' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (strncmp(b1, b2, sizeof(b1)) > 0) {} if (strncasecmp(b1, b2, sizeof(b1) >= 0)) {} // \ expected-warning{{size argument in 'strncasecmp' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (strncasecmp(b1, b2, sizeof(b1)) >= 0) {} if (strncpy(b1, b2, sizeof(b1) == 0 || true)) {} // \ expected-warning{{size argument in 'strncpy' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (strncpy(b1, b2, sizeof(b1)) == 0 || true) {} if (strncat(b1, b2, sizeof(b1) - 1 >= 0 && true)) {} // \ expected-warning{{size argument in 'strncat' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (strncat(b1, b2, sizeof(b1) - 1) >= 0 && true) {} if (strndup(b1, sizeof(b1) != 0)) {} // \ expected-warning{{size argument in 'strndup' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (strndup(b1, sizeof(b1)) != 0) {} if (strlcpy(b1, b2, sizeof(b1) != 0)) {} // \ expected-warning{{size argument in 'strlcpy' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (strlcpy(b1, b2, sizeof(b1)) != 0) {} if (strlcat(b1, b2, sizeof(b1) != 0)) {} // \ expected-warning{{size argument in 'strlcat' call is a comparison}} \ expected-note {{did you mean to compare}} \ expected-note {{explicitly cast the argument}} if (strlcat(b1, b2, sizeof(b1)) != 0) {} if (memset(b1, 0, sizeof(b1) / 2)) {} if (memset(b1, 0, sizeof(b1) >> 2)) {} if (memset(b1, 0, 4 << 2)) {} if (memset(b1, 0, 4 + 2)) {} if (memset(b1, 0, 4 - 2)) {} if (memset(b1, 0, 4 * 2)) {} if (memset(b1, 0, (size_t)(sizeof(b1) != 0))) {} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/generic-selection.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s template <typename T, typename U = void*> struct A { enum { id = _Generic(T(), // expected-error {{controlling expression type 'char' not compatible with any generic association type}} int: 1, // expected-note {{compatible type 'int' specified here}} float: 2, U: 3) // expected-error {{type 'int' in generic association compatible with previously specified type 'int'}} }; }; static_assert(A<int>::id == 1, "fail"); static_assert(A<float>::id == 2, "fail"); static_assert(A<double, double>::id == 3, "fail"); A<char> a1; // expected-note {{in instantiation of template class 'A<char, void *>' requested here}} A<short, int> a2; // expected-note {{in instantiation of template class 'A<short, int>' requested here}} template <typename T, typename U> struct B { enum { id = _Generic(T(), int: 1, // expected-note {{compatible type 'int' specified here}} int: 2, // expected-error {{type 'int' in generic association compatible with previously specified type 'int'}} U: 3) }; }; template <unsigned Arg, unsigned... Args> struct Or { enum { result = Arg | Or<Args...>::result }; }; template <unsigned Arg> struct Or<Arg> { enum { result = Arg }; }; template <class... Args> struct TypeMask { enum { result = Or<_Generic(Args(), int: 1, long: 2, short: 4, float: 8)...>::result }; }; static_assert(TypeMask<int, long, short>::result == 7, "fail"); static_assert(TypeMask<float, short>::result == 12, "fail"); static_assert(TypeMask<int, float, float>::result == 9, "fail");
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/ptrtomember.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 struct S { int i; int mem(int); }; int foo(int S::* ps, S *s) { return (s->*ps)(1); // expected-error {{called object type 'int' is not a function or function pointer}} } struct S2 { int bitfield : 1; }; int S2::*pf = &S2::bitfield; // expected-error {{address of bit-field requested}} struct S3 { void m(); }; void f3(S3* p, void (S3::*m)()) { p->*m; // expected-error {{reference to non-static member function must be called}} (void)(p->*m); // expected-error {{reference to non-static member function must be called}} (void)(void*)(p->*m); // expected-error {{reference to non-static member function must be called}} expected-error {{cannot cast from type 'void' to pointer type 'void *'}} (void)reinterpret_cast<void*>(p->*m); // expected-error {{reference to non-static member function must be called}} expected-error {{reinterpret_cast from 'void' to 'void *' is not allowed}} if (p->*m) {} // expected-error {{reference to non-static member function must be called}} expected-error {{value of type 'void' is not contextually convertible to 'bool'}} if (!(p->*m)) {} // expected-error {{reference to non-static member function must be called}} expected-error {{invalid argument type 'void' to unary expression}} if (p->m) {}; // expected-error {{reference to non-static member function must be called}} expected-error {{value of type 'void' is not contextually convertible to 'bool'}} if (!p->m) {}; // expected-error {{reference to non-static member function must be called}} expected-error {{invalid argument type 'void' to unary expression}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/auto-subst-failure.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 void f() { auto a = f(); // expected-error {{variable has incomplete type 'void'}} auto &b = f(); // expected-error {{cannot form a reference to 'void'}} auto *c = f(); // expected-error {{incompatible initializer of type 'void'}} auto d(f()); // expected-error {{variable has incomplete type 'void'}} auto &&e(f()); // expected-error {{cannot form a reference to 'void'}} auto *g(f()); // expected-error {{incompatible initializer of type 'void'}} (void)new auto(f()); // expected-error {{allocation of incomplete type 'void'}} (void)new auto&(f()); // expected-error {{cannot form a reference to 'void'}} (void)new auto*(f()); // expected-error {{incompatible constructor argument of type 'void'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx0x-initializer-scalars.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -pedantic-errors struct one { char c[1]; }; struct two { char c[2]; }; namespace std { typedef decltype(sizeof(int)) size_t; // libc++'s implementation template <class _E> class initializer_list { const _E* __begin_; size_t __size_; initializer_list(const _E* __b, size_t __s) : __begin_(__b), __size_(__s) {} public: typedef _E value_type; typedef const _E& reference; typedef const _E& const_reference; typedef size_t size_type; typedef const _E* iterator; typedef const _E* const_iterator; initializer_list() : __begin_(nullptr), __size_(0) {} size_t size() const {return __size_;} const _E* begin() const {return __begin_;} const _E* end() const {return __begin_ + __size_;} }; } namespace integral { void initialization() { { const int a{}; static_assert(a == 0, ""); } { const int a = {}; static_assert(a == 0, ""); } { const int a{1}; static_assert(a == 1, ""); } { const int a = {1}; static_assert(a == 1, ""); } { const int a{1, 2}; } // expected-error {{excess elements}} { const int a = {1, 2}; } // expected-error {{excess elements}} // FIXME: Redundant warnings. { const short a{100000}; } // expected-error {{cannot be narrowed}} expected-note {{insert an explicit cast}} expected-warning {{changes value}} { const short a = {100000}; } // expected-error {{cannot be narrowed}} expected-note {{insert an explicit cast}} expected-warning {{changes value}} { if (const int a{1}) static_assert(a == 1, ""); } { if (const int a = {1}) static_assert(a == 1, ""); } } int direct_usage() { int ar[10]; (void) ar[{1}]; // expected-error {{array subscript is not an integer}} return {1}; // expected-warning {{braces around scalar init}} } void inline_init() { auto v = int{1}; (void) new int{1}; } struct A { int i; A() : i{1} {} }; void function_call() { void takes_int(int); takes_int({1}); // expected-warning {{braces around scalar init}} } void overloaded_call() { one overloaded(int); two overloaded(double); static_assert(sizeof(overloaded({0})) == sizeof(one), "bad overload"); // expected-warning {{braces around scalar init}} static_assert(sizeof(overloaded({0.0})) == sizeof(two), "bad overload"); // expected-warning {{braces around scalar init}} void ambiguous(int, double); // expected-note {{candidate}} void ambiguous(double, int); // expected-note {{candidate}} ambiguous({0}, {0}); // expected-error {{ambiguous}} void emptylist(int); void emptylist(int, int, int); emptylist({}); emptylist({}, {}, {}); } void edge_cases() { // FIXME: very poor error message int a({0}); // expected-error {{cannot initialize}} (void) int({0}); // expected-error {{functional-style cast}} new int({0}); // expected-error {{cannot initialize}} } void default_argument(int i = {}) { } struct DefaultArgument { void default_argument(int i = {}) { } }; } namespace PR12118 { void test() { one f(std::initializer_list<int>); two f(int); // to initializer_list is preferred static_assert(sizeof(f({0})) == sizeof(one), "bad overload"); } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/overload-decl.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s void f(); void f(int); void f(int, float); void f(int, int); void f(int, ...); typedef float Float; void f(int, Float); // expected-note {{previous declaration is here}} int f(int, Float); // expected-error {{functions that differ only in their return type cannot be overloaded}} void g(void); // expected-note {{previous declaration is here}} int g(); // expected-error {{functions that differ only in their return type cannot be overloaded}} typedef int INT; class X { void f(); void f(int); // expected-note {{previous declaration is here}} void f() const; void f(INT); // expected-error{{cannot be redeclared}} void g(int); // expected-note {{previous declaration is here}} void g(int, float); // expected-note {{previous declaration is here}} int g(int, Float); // expected-error {{functions that differ only in their return type cannot be overloaded}} static void g(float); // expected-note {{previous declaration is here}} static void g(int); // expected-error {{static and non-static member functions with the same parameter types cannot be overloaded}} static void g(float); // expected-error {{class member cannot be redeclared}} void h(); // expected-note {{previous declaration is here}} void h() __restrict; // expected-error {{class member cannot be redeclared}} }; int main() {} // expected-note {{previous definition is here}} int main(int,char**) {} // expected-error {{conflicting types for 'main'}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/neon-vector-types.cpp
// RUN: %clang_cc1 -fsyntax-only -verify "-triple" "thumbv7-apple-ios3.0.0" -target-feature +neon %s // rdar://9208404 typedef int MP4Err; typedef float Float32; typedef float float32_t; typedef __attribute__((neon_vector_type(4))) float32_t float32x4_t; typedef float vFloat __attribute__((__vector_size__(16))); typedef vFloat VFLOAT; typedef unsigned long UInt32; extern int bar (float32x4_t const *p); int foo (const Float32 *realBufPtr) { float32x4_t const *vRealPtr = (VFLOAT *)&realBufPtr[0]; return bar(vRealPtr); } MP4Err autoCorrelation2nd_Neon(Float32 *alphar, Float32 *alphai, const Float32 *realBufPtr, const Float32 *imagBufPtr, const UInt32 len) { float32x4_t const *vRealPtr = (VFLOAT *)&realBufPtr[0]; return 0; } namespace rdar11688587 { typedef float float32_t; typedef __attribute__((neon_vector_type(4))) float32_t float32x4_t; template<int I> float test() { extern float32x4_t vec; return __extension__ ({ float32x4_t __a = (vec); (float32_t)__builtin_neon_vgetq_lane_f32(__a, I); // expected-error{{argument should be a value from 0 to 3}} }); } template float test<1>(); template float test<4>(); // expected-note{{in instantiation of function template specialization 'rdar11688587::test<4>' requested here}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx11-ast-print.cpp
// RUN: %clang_cc1 -std=c++11 -ast-print %s | FileCheck %s // CHECK: auto operator "" _foo(const char *p, decltype(sizeof(int))) -> decltype(nullptr); auto operator"" _foo(const char *p, decltype(sizeof(int))) -> decltype(nullptr); // CHECK: decltype(""_foo) operator "" _bar(unsigned long long); decltype(""_foo) operator"" _bar(unsigned long long); // CHECK: decltype(42_bar) operator "" _baz(long double); decltype(42_bar) operator"" _baz(long double); // CHECK: decltype(4.5_baz) operator "" _baz(char); decltype(4.5_baz) operator"" _baz(char); // CHECK: const char *operator "" _quux(const char *); const char *operator"" _quux(const char *); // CHECK: template <char ...> const char *operator "" _fritz(); template<char...> const char *operator"" _fritz(); // CHECK: const char *p1 = "bar1"_foo; const char *p1 = "bar1"_foo; // CHECK: const char *p2 = "bar2"_foo; const char *p2 = R"x(bar2)x"_foo; // CHECK: const char *p3 = u8"bar3"_foo; const char *p3 = u8"bar3"_foo; // CHECK: const char *p4 = 297_bar; const char *p4 = 0x129_bar; // CHECK: const char *p5 = 1.0E+12_baz; const char *p5 = 1e12_baz; // CHECK: const char *p6 = 'x'_baz; const char *p6 = 'x'_baz; // CHECK: const char *p7 = 123_quux; const char *p7 = 123_quux; // CHECK: const char *p8 = 4.9_quux; const char *p8 = 4.9_quux; // CHECK: const char *p9 = 0x42e3F_fritz; const char *p9 = 0x42e3F_fritz; // CHECK: const char *p10 = 3.300e+15_fritz; const char *p10 = 3.300e+15_fritz; template <class C, C...> const char *operator"" _suffix(); // CHECK: const char *PR23120 = operator "" _suffix<char32_t, 66615>(); const char *PR23120 = U"𐐷"_suffix; // CHECK: ; ; // CHECK-NOT: ;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/exception-spec-no-exceptions.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fobjc-exceptions %s // expected-no-diagnostics // Note that we're specifically excluding -fcxx-exceptions in the command line above. // That this should work even with -fobjc-exceptions is PR9358 // PR7243: redeclarations namespace test0 { void foo() throw(int); void foo() throw(); } // Overrides. namespace test1 { struct A { virtual void foo() throw(); }; struct B : A { virtual void foo() throw(int); }; } // Calls from less permissive contexts. We don't actually do this // check, but if we did it should also be disabled under // -fno-exceptions. namespace test2 { void foo() throw(int); void bar() throw() { foo(); } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cstyle-cast.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // REQUIRES: LP64 struct A {}; // ----------- const_cast -------------- typedef char c; typedef c *cp; typedef cp *cpp; typedef cpp *cppp; typedef cppp &cpppr; typedef const cppp &cpppcr; typedef const char cc; typedef cc *ccp; typedef volatile ccp ccvp; typedef ccvp *ccvpp; typedef const volatile ccvpp ccvpcvp; typedef ccvpcvp *ccvpcvpp; typedef int iar[100]; typedef iar &iarr; typedef int (*f)(int); void t_cc() { ccvpcvpp var = 0; // Cast away deep consts and volatiles. char ***var2 = (cppp)(var); char ***const &var3 = var2; // Const reference to reference. char ***&var4 = (cpppr)(var3); // Drop reference. Intentionally without qualifier change. char *** var5 = (cppp)(var4); const int ar[100] = {0}; // Array decay. Intentionally without qualifier change. int *pi = (int*)(ar); f fp = 0; // Don't misidentify fn** as a function pointer. f *fpp = (f*)(&fp); int const A::* const A::*icapcap = 0; int A::* A::* iapap = (int A::* A::*)(icapcap); } // ----------- static_cast ------------- struct B : public A {}; // Single public base. struct C1 : public virtual B {}; // Single virtual base. struct C2 : public virtual B {}; struct D : public C1, public C2 {}; // Diamond struct E : private A {}; // Single private base. struct F : public C1 {}; // Single path to B with virtual. struct G1 : public B {}; struct G2 : public B {}; struct H : public G1, public G2 {}; // Ambiguous path to B. enum Enum { En1, En2 }; enum Onom { On1, On2 }; struct Co1 { operator int(); }; struct Co2 { Co2(int); }; struct Co3 { }; struct Co4 { Co4(Co3); operator Co3(); }; // Explicit implicits void t_529_2() { int i = 1; (void)(float)(i); double d = 1.0; (void)(float)(d); (void)(int)(d); (void)(char)(i); (void)(unsigned long)(i); (void)(int)(En1); (void)(double)(En1); (void)(int&)(i); (void)(const int&)(i); int ar[1]; (void)(const int*)(ar); (void)(void (*)())(t_529_2); (void)(void*)(0); (void)(void*)((int*)0); (void)(volatile const void*)((const int*)0); (void)(A*)((B*)0); (void)(A&)(*((B*)0)); (void)(const B*)((C1*)0); (void)(B&)(*((C1*)0)); (void)(A*)((D*)0); (void)(const A&)(*((D*)0)); (void)(int B::*)((int A::*)0); (void)(void (B::*)())((void (A::*)())0); (void)(A*)((E*)0); // C-style cast ignores access control (void)(void*)((const int*)0); // const_cast appended (void)(int)(Co1()); (void)(Co2)(1); (void)(Co3)((Co4)(Co3())); // Bad code below //(void)(A*)((H*)0); // {{static_cast from 'struct H *' to 'struct A *' is not allowed}} } // Anything to void void t_529_4() { (void)(1); (void)(t_529_4); } // Static downcasts void t_529_5_8() { (void)(B*)((A*)0); (void)(B&)(*((A*)0)); (void)(const G1*)((A*)0); (void)(const G1&)(*((A*)0)); (void)(B*)((const A*)0); // const_cast appended (void)(B&)(*((const A*)0)); // const_cast appended (void)(E*)((A*)0); // access control ignored (void)(E&)(*((A*)0)); // access control ignored // Bad code below (void)(C1*)((A*)0); // expected-error {{cannot cast 'A *' to 'C1 *' via virtual base 'B'}} (void)(C1&)(*((A*)0)); // expected-error {{cannot cast 'A' to 'C1 &' via virtual base 'B'}} (void)(D*)((A*)0); // expected-error {{cannot cast 'A *' to 'D *' via virtual base 'B'}} (void)(D&)(*((A*)0)); // expected-error {{cannot cast 'A' to 'D &' via virtual base 'B'}} (void)(H*)((A*)0); // expected-error {{ambiguous cast from base 'A' to derived 'H':\n struct A -> struct B -> struct G1 -> struct H\n struct A -> struct B -> struct G2 -> struct H}} (void)(H&)(*((A*)0)); // expected-error {{ambiguous cast from base 'A' to derived 'H':\n struct A -> struct B -> struct G1 -> struct H\n struct A -> struct B -> struct G2 -> struct H}} // TODO: Test DR427. This requires user-defined conversions, though. } // Enum conversions void t_529_7() { (void)(Enum)(1); (void)(Enum)(1.0); (void)(Onom)(En1); // Bad code below (void)(Enum)((int*)0); // expected-error {{C-style cast from 'int *' to 'Enum' is not allowed}} } // Void pointer to object pointer void t_529_10() { (void)(int*)((void*)0); (void)(const A*)((void*)0); (void)(int*)((const void*)0); // const_cast appended } // Member pointer upcast. void t_529_9() { (void)(int A::*)((int B::*)0); // Bad code below (void)(int A::*)((int H::*)0); // expected-error {{ambiguous conversion from pointer to member of derived class 'H' to pointer to member of base class 'A':}} (void)(int A::*)((int F::*)0); // expected-error {{conversion from pointer to member of class 'F' to pointer to member of class 'A' via virtual base 'B' is not allowed}} } // -------- reinterpret_cast ----------- enum test { testval = 1 }; struct structure { int m; }; typedef void (*fnptr)(); // Test conversion between pointer and integral types, as in p3 and p4. void integral_conversion() { void *vp = (void*)(testval); long l = (long)(vp); (void)(float*)(l); fnptr fnp = (fnptr)(l); (void)(char)(fnp); // expected-error {{cast from pointer to smaller type 'char' loses information}} (void)(long)(fnp); } void pointer_conversion() { int *p1 = 0; float *p2 = (float*)(p1); structure *p3 = (structure*)(p2); typedef int **ppint; ppint *deep = (ppint*)(p3); (void)(fnptr*)(deep); } void constness() { int ***const ipppc = 0; int const *icp = (int const*)(ipppc); (void)(int*)(icp); // const_cast appended int const *const **icpcpp = (int const* const**)(ipppc); // const_cast appended int *ip = (int*)(icpcpp); (void)(int const*)(ip); (void)(int const* const* const*)(ipppc); } void fnptrs() { typedef int (*fnptr2)(int); fnptr fp = 0; (void)(fnptr2)(fp); void *vp = (void*)(fp); (void)(fnptr)(vp); } void refs() { long l = 0; char &c = (char&)(l); // Bad: from rvalue (void)(int&)(&c); // expected-error {{C-style cast from rvalue to reference type 'int &'}} } void memptrs() { const int structure::*psi = 0; (void)(const float structure::*)(psi); (void)(int structure::*)(psi); // const_cast appended void (structure::*psf)() = 0; (void)(int (structure::*)())(psf); (void)(void (structure::*)())(psi); // expected-error-re {{C-style cast from 'const int structure::*' to 'void (structure::*)(){{( __attribute__\(\(thiscall\)\))?}}' is not allowed}} (void)(int structure::*)(psf); // expected-error-re {{C-style cast from 'void (structure::*)(){{( __attribute__\(\(thiscall\)\))?}}' to 'int structure::*' is not allowed}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-using-namespace-in-header.cpp
// RUN: %clang_cc1 -fsyntax-only -Wheader-hygiene -verify %s #ifdef BE_THE_HEADER namespace warn_in_header_in_global_context {} using namespace warn_in_header_in_global_context; // expected-warning {{using namespace directive in global context in header}} // While we want to error on the previous using directive, we don't when we are // inside a namespace namespace dont_warn_here { using namespace warn_in_header_in_global_context; } // We should warn in toplevel extern contexts. namespace warn_inside_linkage {} extern "C++" { using namespace warn_inside_linkage; // expected-warning {{using namespace directive in global context in header}} } // This is really silly, but we should warn on it: extern "C++" { extern "C" { extern "C++" { using namespace warn_inside_linkage; // expected-warning {{using namespace directive in global context in header}} } } } // But we shouldn't warn in extern contexts inside namespaces. namespace dont_warn_here { extern "C++" { using namespace warn_in_header_in_global_context; } } // We also shouldn't warn in case of functions. inline void foo() { using namespace warn_in_header_in_global_context; } namespace macronamespace {} #define USING_MACRO using namespace macronamespace; // |using namespace| through a macro should warn if the instantiation is in a // header. USING_MACRO // expected-warning {{using namespace directive in global context in header}} #else #define BE_THE_HEADER #include __FILE__ namespace dont_warn {} using namespace dont_warn; // |using namespace| through a macro shouldn't warn if the instantiation is in a // cc file. USING_MACRO // Check behavior of line markers. namespace warn_header_with_line_marker {} # 1 "XXX.h" 1 using namespace warn_header_with_line_marker; // expected-warning {{using namespace directive in global context in header}} # 70 "warn-using-namespace-in-header.cpp" 2 namespace nowarn_after_line_marker {} using namespace nowarn_after_line_marker; #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/anonymous-union-cxx11.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -pedantic %s // expected-no-diagnostics namespace PR12866 { struct bar { union { int member; }; }; void foo( void ) { (void)sizeof(bar::member); } } namespace PR20021 { class C { union { static_assert(true, ""); int i; }; }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-regparm.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-pc-linux-gnu %s // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-apple-darwin10 %s // PR7025 struct X0 { void __attribute__((regparm(3))) f0(); void __attribute__((regparm(3))) f1(); void __attribute__((regparm(3))) f2(); // expected-note{{previous declaration is here}} void f3(); // expected-note{{previous declaration is here}} }; void X0::f0() { } void __attribute__((regparm(3))) X0::f1() { } void __attribute__((regparm(2))) X0::f2() { } // expected-error{{function declared with regparm(2) attribute was previously declared with the regparm(3) attribute}} void __attribute__((regparm(2))) X0::f3() { } // expected-error{{function declared with regparm(2) attribute was previously declared without the regparm attribute}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/constructor-recovery.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct C { virtual C() = 0; // expected-error{{constructor cannot be declared 'virtual'}} }; void f() { C c; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx0x-initializer-references.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s struct one { char c; }; struct two { char c[2]; }; namespace reference { struct A { int i1, i2; }; void single_init() { const int &cri1a = {1}; const int &cri1b{1}; int i = 1; int &ri1a = {i}; int &ri1b{i}; int &ri2 = {1}; // expected-error {{cannot bind to an initializer list temporary}} A a{1, 2}; A &ra1a = {a}; A &ra1b{a}; } void reference_to_aggregate() { const A &ra1{1, 2}; A &ra2{1, 2}; // expected-error {{cannot bind to an initializer list temporary}} const int (&arrayRef)[] = {1, 2, 3}; static_assert(sizeof(arrayRef) == 3 * sizeof(int), "bad array size"); } struct B { int i1; }; void call() { one f(const int&); f({1}); one g(int&); // expected-note {{passing argument}} g({1}); // expected-error {{cannot bind to an initializer list temporary}} int i = 0; g({i}); void h(const B&); h({1}); void a(B&); // expected-note {{passing argument}} a({1}); // expected-error {{cannot bind to an initializer list temporary}} B b{1}; a({b}); } void overloading() { one f(const int&); two f(const B&); // First is identity conversion, second is user-defined conversion. static_assert(sizeof(f({1})) == sizeof(one), "bad overload resolution"); one g(int&); two g(const B&); static_assert(sizeof(g({1})) == sizeof(two), "bad overload resolution"); one h(const int&); two h(const A&); static_assert(sizeof(h({1, 2})) == sizeof(two), "bad overload resolution"); } void edge_cases() { // FIXME: very poor error message int const &b({0}); // expected-error {{could not bind}} } } namespace PR12182 { void f(int const(&)[3]); void g() { f({1, 2}); } } namespace PR12660 { const int &i { 1 }; struct S { S(int); } const &s { 2 }; } namespace b7891773 { typedef void (*ptr)(); template <class T> void f(); int g(const ptr &); int k = g({ f<int> }); } namespace inner_init { struct A { int n; }; struct B { A &&r; }; B b1 { 0 }; // expected-error {{reference to type 'inner_init::A' could not bind to an rvalue of type 'int'}} B b2 { { 0 } }; B b3 { { { 0 } } }; // expected-warning {{braces around scalar init}} struct C { C(int); }; // expected-note 2{{candidate constructor (the implicit}} \ // expected-note {{candidate constructor not viable: cannot convert initializer list argument to 'int'}} struct D { C &&r; }; D d1 { 0 }; // ok, 0 implicitly converts to C D d2 { { 0 } }; // ok, { 0 } calls C(0) D d3 { { { 0 } } }; // ok, { { 0 } } calls C({ 0 }), expected-warning {{braces around scalar init}} D d4 { { { { 0 } } } }; // expected-error {{no matching constructor for initialization of 'inner_init::C &&'}} struct E { explicit E(int); }; // expected-note 2{{here}} struct F { E &&r; }; F f1 { 0 }; // expected-error {{could not bind to an rvalue of type 'int'}} F f2 { { 0 } }; // expected-error {{chosen constructor is explicit}} F f3 { { { 0 } } }; // expected-error {{chosen constructor is explicit}} } namespace PR20844 { struct A {}; struct B { operator A&(); } b; A &a{b}; // expected-error {{excess elements}} expected-note {{in initialization of temporary of type 'PR20844::A'}} } namespace PR21834 { const int &a = (const int &){0}; // expected-error {{cannot bind to an initializer list}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/using-decl-1.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s extern "C" { void f(bool); } namespace std { using ::f; inline void f() { return f(true); } } namespace M { void f(float); } namespace N { using M::f; void f(int) { } // expected-note{{previous}} void f(int) { } // expected-error{{redefinition}} } namespace N { void f(double); void f(long); } struct X0 { void operator()(int); void operator()(long); }; struct X1 : X0 { // FIXME: give this operator() a 'float' parameter to test overloading // behavior. It currently fails. void operator()(); using X0::operator(); void test() { (*this)(1); } }; struct A { void f(); }; struct B : A { }; class C : B { using B::f; }; // PR5751: Resolve overloaded functions through using decls. namespace O { void f(int i); void f(double d); } namespace P { void f(); void g(void (*ptr)(int)); using O::f; void test() { f(); f(1); void (*f_ptr1)(double) = f; void (*f_ptr2)() = f; g(f); } } // Make sure that ADL can find names brought in by using decls. namespace test0 { namespace ns { class Foo {}; namespace inner { void foo(char *); // expected-note {{no known conversion}} } using inner::foo; } void test(ns::Foo *p) { foo(*p); // expected-error {{no matching function for call to 'foo'}} } } // Redeclarations! namespace test1 { namespace ns0 { struct Foo {}; } namespace A { void foo(ns0::Foo *p, int y, int z); } namespace ns2 { using A::foo; } namespace ns1 { struct Bar : ns0::Foo {}; } namespace A { void foo(ns0::Foo *p, int y, int z = 0); } // expected-note {{candidate}} namespace ns1 { using A::foo; } namespace ns2 { struct Baz : ns1::Bar {}; } namespace A { void foo(ns0::Foo *p, int y = 0, int z); } void test(ns2::Baz *p) { foo(p, 0, 0); // okay! foo(p, 0); // should be fine! foo(p); // expected-error {{no matching function}} } } namespace test2 { namespace ns { int foo; } template <class T> using ns::foo; // expected-error {{cannot template a using declaration}} // PR8022 struct A { template <typename T> void f(T); }; class B : A { template <typename T> using A::f<T>; // expected-error {{cannot template a using declaration}} }; } // PR8756 namespace foo { class Class1; // expected-note{{forward declaration}} class Class2 { using ::foo::Class1::Function; // expected-error{{incomplete type 'foo::Class1' named in nested name specifier}} }; } // Don't suggest non-typenames for positions requiring typenames. namespace using_suggestion_tyname_val { namespace N { void FFF() {} } using typename N::FFG; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val::N'}} } namespace using_suggestion_member_tyname_val { class CCC { public: void AAA() { } }; class DDD : public CCC { public: using typename CCC::AAB; }; // expected-error {{no member named 'AAB' in 'using_suggestion_member_tyname_val::CCC'}} } namespace using_suggestion_tyname_val_dropped_specifier { void FFF() {} namespace N { } using typename N::FFG; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val_dropped_specifier::N'}} } // Currently hints aren't provided to drop out the incorrect M::. namespace using_suggestion_ty_dropped_nested_specifier { namespace N { class AAA {}; // expected-note {{'N::AAA' declared here}} namespace M { } } using N::M::AAA; // expected-error {{no member named 'AAA' in namespace 'using_suggestion_ty_dropped_nested_specifier::N::M'; did you mean 'N::AAA'?}} } namespace using_suggestion_tyname_ty_dropped_nested_specifier { namespace N { class AAA {}; // expected-note {{'N::AAA' declared here}} namespace M { } } using typename N::M::AAA; // expected-error {{no member named 'AAA' in namespace 'using_suggestion_tyname_ty_dropped_nested_specifier::N::M'; did you mean 'N::AAA'?}} } namespace using_suggestion_val_dropped_nested_specifier { namespace N { void FFF() {} // expected-note {{'N::FFF' declared here}} namespace M { } } using N::M::FFF; // expected-error {{no member named 'FFF' in namespace 'using_suggestion_val_dropped_nested_specifier::N::M'; did you mean 'N::FFF'?}} } namespace UsingDeclVsHiddenName { namespace A { enum HiddenTag1 {}; // expected-note {{previous use is here}} enum HiddenTag2 {}; // expected-note {{target}} int HiddenFn1; // expected-note {{target}} int HiddenFn2; // expected-note {{target}} int HiddenLocalExtern1; int HiddenLocalExtern2; } namespace B { using A::HiddenTag1; using A::HiddenFn1; // expected-note {{using declaration}} using A::HiddenLocalExtern1; struct S { friend struct HiddenTag1; // expected-error {{tag type that does not match previous}} friend struct HiddenTag2; // expected-note {{conflicting declaration}} friend void HiddenFn1(); // expected-error {{cannot befriend target of using declaration}} friend void HiddenFn2(); // expected-note {{conflicting declaration}} void f() { // OK, these are not in the scope of namespace B, even though they're // members of the namespace. void HiddenLocalExtern1(); void HiddenLocalExtern2(); } }; using A::HiddenTag2; // expected-error {{conflicts with declaration already in scope}} using A::HiddenFn2; // expected-error {{conflicts with declaration already in scope}} using A::HiddenLocalExtern2; } } namespace PR19171 { struct Z { Z(); }; typedef struct { Z i; } S; struct Y : S { using S::S; #if __cplusplus < 201103L // expected-error@-2 {{no member named 'S' in 'PR19171::S'}} #endif }; // [namespace.udecl]p3: In a using-declaration used as a member-declaration, // the nested-name-specifier shall name a base class of the class being defined. // If such a using-declaration names a constructor, the nested-name-specifier // shall name a direct base class of the class being defined; struct B_blah { }; struct C_blah : B_blah { C_blah(int); }; // expected-note 0-1{{declared here}} struct D1 : C_blah { // FIXME: We should be able to correct this in C++11 mode. using B_blah::C_blah; // expected-error-re {{no member named 'C_blah' in 'PR19171::B_blah'{{$}}}} }; struct D2 : C_blah { // Somewhat bizarrely, this names the injected-class-name of B_blah within // C_blah, and is valid. using C_blah::B_blah; }; struct D3 : C_blah { using C_blah::D_blah; #if __cplusplus < 201103L // expected-error-re@-2 {{no member named 'D_blah' in 'PR19171::C_blah'{{$}}}} #else // expected-error@-4 {{no member named 'D_blah' in 'PR19171::C_blah'; did you mean 'C_blah'?}} #endif }; #if __cplusplus >= 201103L D3 d3(0); // ok #endif struct E { }; struct EE { int EE; }; struct F : E { using E::EE; // expected-error-re {{no member named 'EE' in 'PR19171::E'{{$}}}} }; } namespace TypoCorrectTemplateMember { struct A { template<typename T> void foobar(T); // expected-note {{'foobar' declared here}} }; struct B : A { using A::goobar; // expected-error {{no member named 'goobar' in 'TypoCorrectTemplateMember::A'; did you mean 'foobar'?}} }; } namespace use_instance_in_static { struct A { int n; }; struct B : A { using A::n; static int f() { return n; } // expected-error {{invalid use of member 'n' in static member function}} }; } namespace PR24030 { namespace X { class A; // expected-note {{target}} int i; // expected-note {{target}} } namespace Y { using X::A; // expected-note {{using}} using X::i; // expected-note {{using}} class A {}; // expected-error {{conflicts}} int i; // expected-error {{conflicts}} } } namespace PR24033 { extern int a; // expected-note 2{{target of using declaration}} void f(); // expected-note 2{{target of using declaration}} struct s; // expected-note 2{{target of using declaration}} enum e {}; // expected-note 2{{target of using declaration}} template<typename> extern int vt; // expected-note 2{{target of using declaration}} expected-warning 0-1{{extension}} template<typename> void ft(); // expected-note 2{{target of using declaration}} template<typename> struct st; // expected-note 2{{target of using declaration}} namespace X { using PR24033::a; // expected-note {{using declaration}} using PR24033::f; // expected-note {{using declaration}} using PR24033::s; // expected-note {{using declaration}} using PR24033::e; // expected-note {{using declaration}} using PR24033::vt; // expected-note {{using declaration}} using PR24033::ft; // expected-note {{using declaration}} using PR24033::st; // expected-note {{using declaration}} extern int a; // expected-error {{declaration conflicts with target of using declaration already in scope}} void f(); // expected-error {{declaration conflicts with target of using declaration already in scope}} struct s; // expected-error {{declaration conflicts with target of using declaration already in scope}} enum e {}; // expected-error {{declaration conflicts with target of using declaration already in scope}} template<typename> extern int vt; // expected-error {{declaration conflicts with target of using declaration already in scope}} expected-warning 0-1{{extension}} template<typename> void ft(); // expected-error {{declaration conflicts with target of using declaration already in scope}} template<typename> struct st; // expected-error {{declaration conflicts with target of using declaration already in scope}} } namespace Y { extern int a; // expected-note {{conflicting declaration}} void f(); // expected-note {{conflicting declaration}} struct s; // expected-note {{conflicting declaration}} enum e {}; // expected-note {{conflicting declaration}} template<typename> extern int vt; // expected-note {{conflicting declaration}} expected-warning 0-1{{extension}} template<typename> void ft(); // expected-note {{conflicting declaration}} template<typename> struct st; // expected-note {{conflicting declaration}} using PR24033::a; // expected-error {{target of using declaration conflicts with declaration already in scope}} using PR24033::f; // expected-error {{target of using declaration conflicts with declaration already in scope}} using PR24033::s; // expected-error {{target of using declaration conflicts with declaration already in scope}} using PR24033::e; // expected-error {{target of using declaration conflicts with declaration already in scope}} using PR24033::vt; // expected-error {{target of using declaration conflicts with declaration already in scope}} using PR24033::ft; // expected-error {{target of using declaration conflicts with declaration already in scope}} using PR24033::st; // expected-error {{target of using declaration conflicts with declaration already in scope}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/incomplete-call.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct A; // expected-note 14 {{forward declaration of 'A'}} A f(); // expected-note {{'f' declared here}} struct B { A f(); // expected-note {{'f' declared here}} A operator()(); // expected-note 2 {{'operator()' declared here}} operator A(); // expected-note {{'operator A' declared here}} A operator!(); // expected-note 2 {{'operator!' declared here}} A operator++(int); // expected-note {{'operator++' declared here}} A operator[](int); // expected-note {{'operator[]' declared here}} A operator+(int); // expected-note {{'operator+' declared here}} A operator->(); // expected-note {{'operator->' declared here}} }; void g() { f(); // expected-error {{calling 'f' with incomplete return type 'A'}} typedef A (*Func)(); Func fp; fp(); // expected-error {{calling function with incomplete return type 'A'}} ((Func)0)(); // expected-error {{calling function with incomplete return type 'A'}} B b; b.f(); // expected-error {{calling 'f' with incomplete return type 'A'}} b.operator()(); // expected-error {{calling 'operator()' with incomplete return type 'A'}} b.operator A(); // expected-error {{calling 'operator A' with incomplete return type 'A'}} b.operator!(); // expected-error {{calling 'operator!' with incomplete return type 'A'}} !b; // expected-error {{calling 'operator!' with incomplete return type 'A'}} b(); // expected-error {{calling 'operator()' with incomplete return type 'A'}} b++; // expected-error {{calling 'operator++' with incomplete return type 'A'}} b[0]; // expected-error {{calling 'operator[]' with incomplete return type 'A'}} b + 1; // expected-error {{calling 'operator+' with incomplete return type 'A'}} b->f(); // expected-error {{calling 'operator->' with incomplete return type 'A'}} A (B::*mfp)() = 0; (b.*mfp)(); // expected-error {{calling function with incomplete return type 'A'}} } struct C; // expected-note{{forward declaration}} void test_incomplete_object_call(C& c) { c(); // expected-error{{incomplete type in call to object of type}} } namespace pr18542 { struct X { int count; template<typename CharT> class basic_istream; template<typename CharT> void basic_istream<CharT>::read() { // expected-error{{out-of-line definition of 'read' from class 'basic_istream<CharT>' without definition}} count = 0; } }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/friend.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14 friend class A; // expected-error {{'friend' used outside of class}} void f() { friend class A; } // expected-error {{'friend' used outside of class}} class C { friend class A; }; class D { void f() { friend class A; } }; // expected-error {{'friend' used outside of class}} // PR5760 namespace test0 { namespace ns { void f(int); } struct A { friend void ns::f(int a); }; } // Test derived from LLVM's Registry.h namespace test1 { template <class T> struct Outer { void foo(T); struct Inner { friend void Outer::foo(T); }; }; void test() { (void) Outer<int>::Inner(); } } // PR5476 namespace test2 { namespace foo { void Func(int x); } class Bar { friend void ::test2::foo::Func(int x); }; } // PR5134 namespace test3 { class Foo { friend const int getInt(int inInt = 0) {} }; } namespace test4 { class T4A { friend class T4B; public: T4A(class T4B *); protected: T4B *mB; // error here }; class T4B {}; } namespace rdar8529993 { struct A { ~A(); }; struct B : A { template<int> friend A::~A(); // expected-error {{destructor cannot be declared as a template}} }; } // PR7915 namespace test5 { struct A; struct A1 { friend void A(); }; struct B { friend void B(); }; } // PR8479 namespace test6_1 { class A { public: private: friend class vectorA; A() {} }; class vectorA { public: vectorA(int i, const A& t = A()) {} }; void f() { vectorA v(1); } } namespace test6_2 { template<class T> class vector { public: vector(int i, const T& t = T()) {} }; class A { public: private: friend class vector<A>; A() {} }; void f() { vector<A> v(1); } } namespace test6_3 { template<class T> class vector { public: vector(int i) {} void f(const T& t = T()) {} }; class A { public: private: friend void vector<A>::f(const A&); A() {} }; void f() { vector<A> v(1); v.f(); } } namespace test7 { extern "C" { class X { friend int test7_f() { return 42; } }; } } // PR15485 namespace test8 { namespace ns1 { namespace ns2 { template<class T> void f(T t); // expected-note {{target of using declaration}} } using ns2::f; // expected-note {{using declaration}} } struct A { void f(); }; // expected-note {{target of using declaration}} struct B : public A { using A::f; }; // expected-note {{using declaration}} struct X { template<class T> friend void ns1::f(T t); // expected-error {{cannot befriend target of using declaration}} friend void B::f(); // expected-error {{cannot befriend target of using declaration}} }; } // PR16423 namespace test9 { class C { }; struct A { friend void C::f(int, int, int) {} // expected-error {{no function named 'f' with type 'void (int, int, int)' was found in the specified scope}} }; } namespace test10 { struct X {}; extern void f10_a(); extern void f10_a(X); struct A { friend void f10_a(); friend void f10_b(); friend void f10_c(); friend void f10_d(); friend void f10_a(X); friend void f10_b(X); friend void f10_c(X); friend void f10_d(X); }; extern void f10_b(); extern void f10_b(X); struct B { friend void f10_a(); friend void f10_b(); friend void f10_c(); friend void f10_d(); friend void f10_a(X); friend void f10_b(X); friend void f10_c(X); friend void f10_d(X); }; extern void f10_c(); extern void f10_c(X); // FIXME: Give a better diagnostic for the case where a function exists but is // not visible. void g(X x) { f10_a(); f10_b(); f10_c(); f10_d(); // expected-error {{undeclared identifier}} ::test10::f10_a(); ::test10::f10_b(); ::test10::f10_c(); ::test10::f10_d(); // expected-error {{no member named 'f10_d'}} f10_a(x); f10_b(x); f10_c(x); f10_d(x); // PR16597: expected-error {{undeclared identifier}} ::test10::f10_a(x); ::test10::f10_b(x); ::test10::f10_c(x); ::test10::f10_d(x); // expected-error {{no type named 'f10_d'}} } struct Y : X { friend void f10_d(); friend void f10_d(X); }; struct Z { operator X(); friend void f10_d(); friend void f10_d(X); }; void g(X x, Y y, Z z) { f10_d(); // expected-error {{undeclared identifier}} ::test10::f10_d(); // expected-error {{no member named 'f10_d'}} // f10_d is visible to ADL in the second and third cases. f10_d(x); // expected-error {{undeclared identifier}} f10_d(y); f10_d(z); // No ADL here. ::test10::f10_d(x); // expected-error {{no type named 'f10_d'}} ::test10::f10_d(y); // expected-error {{no type named 'f10_d'}} ::test10::f10_d(z); // expected-error {{no type named 'f10_d'}} } void local_externs(X x, Y y) { extern void f10_d(); extern void f10_d(X); f10_d(); f10_d(x); // FIXME: This lookup should fail, because the local extern declaration // should suppress ADL. f10_d(y); { int f10_d; f10_d(); // expected-error {{not a function}} f10_d(x); // expected-error {{not a function}} f10_d(y); // expected-error {{not a function}} } } void i(X x, Y y) { f10_d(); // expected-error {{undeclared identifier}} f10_d(x); // expected-error {{undeclared identifier}} f10_d(y); } struct C { friend void f10_d(); friend void f10_d(X); }; void j(X x, Y y) { f10_d(); // expected-error {{undeclared identifier}} f10_d(x); // expected-error {{undeclared identifier}} f10_d(y); } extern void f10_d(); extern void f10_d(X); void k(X x, Y y, Z z) { // All OK now. f10_d(); f10_d(x); ::test10::f10_d(); ::test10::f10_d(x); ::test10::f10_d(y); ::test10::f10_d(z); } } namespace test11 { class __attribute__((visibility("hidden"))) B; class A { friend class __attribute__((visibility("hidden"), noreturn)) B; // expected-warning {{'noreturn' attribute only applies to functions and methods}} }; } namespace pr21851 { // PR21851 was a problem where we assumed that when the friend function redecl // lookup found a C++ method, it would necessarily have a qualifier. Below we // have some test cases where unqualified lookup finds C++ methods without using // qualifiers. Unfortunately, we can't exercise the case of an access check // failure because nested classes always have access to the members of outer // classes. void friend_own_method() { class A { void m() {} friend void m(); }; } void friend_enclosing_method() { class A; class C { int p; friend class A; }; class A { void enclosing_friend() { (void)b->p; (void)c->p; } class B { void b(A *a) { (void)a->c->p; } int p; friend void enclosing_friend(); }; B *b; C *c; }; } static auto friend_file_func() { extern void file_scope_friend(); class A { int p; friend void file_scope_friend(); }; return A(); } void file_scope_friend() { auto a = friend_file_func(); (void)a.p; } } template<typename T> struct X_pr6954 { operator int(); friend void f_pr6954(int x); }; int array0_pr6954[sizeof(X_pr6954<int>)]; int array1_pr6954[sizeof(X_pr6954<float>)]; void g_pr6954() { f_pr6954(5); // expected-error{{undeclared identifier 'f_pr6954'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/elaborated-type-specifier.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s // Test the use of elaborated-type-specifiers to inject the names of // structs (or classes or unions) into an outer scope as described in // C++ [basic.scope.pdecl]p5. typedef struct S1 { union { struct S2 *x; struct S3 *y; }; } S1; bool test_elab(S1 *s1, struct S2 *s2, struct S3 *s3) { if (s1->x == s2) return true; if (s1->y == s3) return true; return false; } namespace NS { class X { public: void test_elab2(struct S4 *s4); // expected-note{{'NS::S4' declared here}} }; void X::test_elab2(S4 *s4) { } // expected-note{{passing argument to parameter 's4' here}} } void test_X_elab(NS::X x) { struct S4 *s4 = 0; x.test_elab2(s4); // expected-error{{cannot initialize a parameter of type 'NS::S4 *' with an lvalue of type 'struct S4 *'}} } namespace NS { S4 *get_S4(); } void test_S5_scope() { S4 *s4; // expected-error{{unknown type name 'S4'; did you mean 'NS::S4'?}} } int test_funcparam_scope(struct S5 * s5) { struct S5 { int y; } *s5_2 = 0; if (s5 == s5_2) return 1; // expected-error {{comparison of distinct pointer types ('struct S5 *' and 'struct S5 *')}} return 0; } namespace test5 { struct A { class __attribute__((visibility("hidden"))) B {}; void test(class __attribute__((visibility("hidden"), noreturn)) B b) { // expected-warning {{'noreturn' attribute only applies to functions and methods}} } }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/format-strings.cpp
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks %s #include <stdarg.h> extern "C" { extern int scanf(const char *restrict, ...); extern int printf(const char *restrict, ...); extern int vprintf(const char *restrict, va_list); } void f(char **sp, float *fp) { scanf("%as", sp); // expected-warning{{'a' length modifier is not supported by ISO C}} // TODO: Warn that the 'a' conversion specifier is a C++11 feature. printf("%a", 1.0); scanf("%afoobar", fp); } void g() { printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}} } // Test that we properly handle format_idx on C++ members. class Foo { public: const char *gettext(const char *fmt) __attribute__((format_arg(2))); int scanf(const char *, ...) __attribute__((format(scanf, 2, 3))); int printf(const char *, ...) __attribute__((format(printf, 2, 3))); int printf2(const char *, ...); static const char *gettext_static(const char *fmt) __attribute__((format_arg(1))); static int printf_static(const char *fmt, ...) __attribute__((format(printf, 1, 2))); }; void h(int *i) { Foo foo; foo.scanf("%d"); // expected-warning{{more '%' conversions than data arguments}} foo.printf("%d", i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} Foo::printf_static("%d", i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} printf(foo.gettext("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} printf(Foo::gettext_static("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} } // Test handling __null for format string literal checking. extern "C" { int test_null_format(const char *format, ...) __attribute__((__format__ (__printf__, 1, 2))); } void rdar8269537(const char *f) { test_null_format(false); // expected-warning {{null from a constant boolean}} test_null_format(0); // no-warning test_null_format(__null); // no-warning test_null_format(f); // expected-warning {{not a string literal}} } int Foo::printf(const char *fmt, ...) { va_list ap; va_start(ap,fmt); const char * const format = fmt; vprintf(format, ap); // no-warning const char *format2 = fmt; vprintf(format2, ap); // expected-warning{{format string is not a string literal}} return 0; } int Foo::printf2(const char *fmt, ...) { va_list ap; va_start(ap,fmt); vprintf(fmt, ap); // expected-warning{{format string is not a string literal}} return 0; } namespace Templates { template<typename T> void my_uninstantiated_print(const T &arg) { printf("%d", arg); // no-warning } template<typename T> void my_print(const T &arg) { printf("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}} } void use_my_print() { my_print("abc"); // expected-note {{requested here}} } template<typename T> class UninstantiatedPrinter { public: static void print(const T &arg) { printf("%d", arg); // no-warning } }; template<typename T> class Printer { void format(const char *fmt, ...) __attribute__((format(printf,2,3))); public: void print(const T &arg) { format("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}} } }; void use_class(Printer<const char *> &p) { p.print("abc"); // expected-note {{requested here}} } extern void (^block_print)(const char * format, ...) __attribute__((format(printf, 1, 2))); template<typename T> void uninstantiated_call_block_print(const T &arg) { block_print("%d", arg); // no-warning } template<typename T> void call_block_print(const T &arg) { block_print("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}} } void use_block_print() { call_block_print("abc"); // expected-note {{requested here}} } } namespace implicit_this_tests { struct t { void func1(const char *, ...) __attribute__((__format__(printf, 1, 2))); // expected-error {{format attribute cannot specify the implicit this argument as the format string}} void (*func2)(const char *, ...) __attribute__((__format__(printf, 1, 2))); static void (*func3)(const char *, ...) __attribute__((__format__(printf, 1, 2))); static void func4(const char *, ...) __attribute__((__format__(printf, 1, 2))); }; void f() { t t1; t1.func2("Hello %s"); // expected-warning {{more '%' conversions than data arguments}} t::func3("Hello %s"); // expected-warning {{more '%' conversions than data arguments}} t::func4("Hello %s"); // expected-warning {{more '%' conversions than data arguments}} } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/alignof-sizeof-reference.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s struct s0; // expected-note {{forward declaration}} char ar[sizeof(s0&)]; // expected-error {{invalid application of 'sizeof' to an incomplete type}} void test() { char &r = ar[0]; static_assert(alignof(r) == 1, "bad alignment"); // expected-warning {{GNU extension}} static_assert(alignof(char&) == 1, "bad alignment"); static_assert(sizeof(r) == 1, "bad size"); static_assert(sizeof(char&) == 1, "bad size"); } int f(); // expected-note{{possible target for call}} int f(int); // expected-note{{possible target for call}} void g() { sizeof(&f); // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} \ // expected-warning{{expression result unused}} } template<typename T> void f_template(); // expected-note{{possible target for call}} template<typename T> void f_template(T*); // expected-note{{possible target for call}} void rdar9659191() { (void)alignof(f_template<int>); // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}} expected-warning {{GNU extension}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/addr-of-overloaded-function.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s int f(double); // expected-note{{candidate function}} int f(int); // expected-note{{candidate function}} int (*pfd)(double) = f; // selects f(double) int (*pfd2)(double) = &f; // selects f(double) int (*pfd3)(double) = ((&((f)))); // selects f(double) int (*pfi)(int) = &f; // selects f(int) // FIXME: This error message is not very good. We need to keep better // track of what went wrong when the implicit conversion failed to // give a better error message here. int (*pfe)(...) = &f; // expected-error{{address of overloaded function 'f' does not match required type 'int (...)'}} int (&rfi)(int) = f; // selects f(int) int (&rfd)(double) = f; // selects f(double) void g(int (*fp)(int)); // expected-note{{candidate function}} void g(int (*fp)(float)); void g(int (*fp)(double)); // expected-note{{candidate function}} int g1(int); int g1(char); int g2(int); int g2(double); template<typename T> T g3(T); int g3(int); int g3(char); void g_test() { g(g1); g(g2); // expected-error{{call to 'g' is ambiguous}} g(g3); } template<typename T> T h1(T); template<typename R, typename A1> R h1(A1); int h1(char); void ha(int (*fp)(int)); void hb(int (*fp)(double)); void h_test() { ha(h1); hb(h1); } struct A { }; void f(void (*)(A *)); struct B { void g() { f(d); } void d(void *); static void d(A *); }; struct C { C &getC() { return makeAC; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} } // FIXME: filter by const so we can unambiguously suggest '()' & point to just the one candidate, probably C &makeAC(); // expected-note{{possible target for call}} const C &makeAC() const; // expected-note{{possible target for call}} static void f(); // expected-note{{candidate function}} static void f(int); // expected-note{{candidate function}} void g() { int (&fp)() = f; // expected-error{{address of overloaded function 'f' does not match required type 'int ()'}} } template<typename T> void q1(int); // expected-note{{possible target for call}} template<typename T> void q2(T t = T()); // expected-note{{possible target for call}} template<typename T> void q3(); // expected-note{{possible target for call}} template<typename T1, typename T2> void q4(); // expected-note{{possible target for call}} template<typename T1 = int> // expected-warning{{default template arguments for a function template are a C++11 extension}} void q5(); // expected-note{{possible target for call}} void h() { // Do not suggest '()' since an int argument is required q1<int>; // expected-error-re{{reference to non-static member function must be called{{$}}}} // Suggest '()' since there's a default value for the only argument & the // type argument is already provided q2<int>; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} // Suggest '()' since no arguments are required & the type argument is // already provided q3<int>; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} // Do not suggest '()' since another type argument is required q4<int>; // expected-error-re{{reference to non-static member function must be called{{$}}}} // Suggest '()' since the type parameter has a default value q5; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} } }; // PR6886 namespace test0 { void myFunction(void (*)(void *)); class Foo { void foo(); static void bar(void*); static void bar(); }; void Foo::foo() { myFunction(bar); } } namespace PR7971 { struct S { void g() { f(&g); } void f(bool (*)(int, char)); static bool g(int, char); }; } namespace PR8033 { template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}} \ // expected-note{{candidate function}} template <typename T1, typename T2> int f(const T1 *, T2 *); // expected-note {{candidate function [with T1 = int, T2 = const int]}} \ // expected-note{{candidate function}} int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} \ // expected-error{{address of overloaded function 'f' is ambiguous}} } namespace PR8196 { template <typename T> struct mcdata { typedef int result_type; }; template <class T> typename mcdata<T>::result_type wrap_mean(mcdata<T> const&); void add_property(double(*)(mcdata<double> const &)); // expected-note{{candidate function not viable: no overload of 'wrap_mean' matching}} void f() { add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}} } } namespace PR7425 { template<typename T> void foo() { } struct B { template<typename T> B(const T&) { } }; void bar(const B& b) { } void bar2(const B& b = foo<int>) { } void test(int argc, char** argv) { bar(foo<int>); bar2(); } } namespace test1 { void fun(int x) {} void parameter_number() { void (*ptr1)(int, int) = &fun; // expected-error {{cannot initialize a variable of type 'void (*)(int, int)' with an rvalue of type 'void (*)(int)': different number of parameters (2 vs 1)}} void (*ptr2)(int, int); ptr2 = &fun; // expected-error {{assigning to 'void (*)(int, int)' from incompatible type 'void (*)(int)': different number of parameters (2 vs 1)}} } void parameter_mismatch() { void (*ptr1)(double) = &fun; // expected-error {{cannot initialize a variable of type 'void (*)(double)' with an rvalue of type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}} void (*ptr2)(double); ptr2 = &fun; // expected-error {{assigning to 'void (*)(double)' from incompatible type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}} } void return_type_test() { int (*ptr1)(int) = &fun; // expected-error {{cannot initialize a variable of type 'int (*)(int)' with an rvalue of type 'void (*)(int)': different return type ('int' vs 'void')}} int (*ptr2)(int); ptr2 = &fun; // expected-error {{assigning to 'int (*)(int)' from incompatible type 'void (*)(int)': different return type ('int' vs 'void')}} } int foo(double x, double y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} int foo(int x, int y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} int foo(double x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'double')}} double foo(float x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} double foo(int x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} double foo(float x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'float')}} double foo(int x) {return 0;} // expected-note {{candidate function has different return type ('int' expected but has 'double')}} int (*ptr)(int) = &foo; // expected-error {{address of overloaded function 'foo' does not match required type 'int (int)'}} struct Qualifiers { void N() {}; void C() const {}; void V() volatile {}; void R() __restrict {}; void CV() const volatile {}; void CR() const __restrict {}; void VR() volatile __restrict {}; void CVR() const volatile __restrict {}; }; void QualifierTest() { void (Qualifiers::*X)(); X = &Qualifiers::C; // expected-error-re {{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} const': different qualifiers (none vs const)}} X = &Qualifiers::V; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} volatile': different qualifiers (none vs volatile)}} X = &Qualifiers::R; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} __restrict': different qualifiers (none vs restrict)}} X = &Qualifiers::CV; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} const volatile': different qualifiers (none vs const and volatile)}} X = &Qualifiers::CR; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} const __restrict': different qualifiers (none vs const and restrict)}} X = &Qualifiers::VR; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} volatile __restrict': different qualifiers (none vs volatile and restrict)}} X = &Qualifiers::CVR; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} const volatile __restrict': different qualifiers (none vs const, volatile, and restrict)}} } struct Dummy { void N() {}; }; void (Qualifiers::*X)() = &Dummy::N; // expected-error-re{{cannot initialize a variable of type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' with an rvalue of type 'void (test1::Dummy::*)(){{( __attribute__\(\(thiscall\)\))?}}': different classes ('test1::Qualifiers' vs 'test1::Dummy')}} } template <typename T> class PR16561 { virtual bool f() { if (f) {} return false; } // expected-error {{reference to non-static member function must be called}} };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp
// RUN: %clang_cc1 -verify -fsyntax-only %s float foof(float x); double food(double x); void foo(bool b, float f); void bar() { float c = 1.7; bool b = c; double e = 1.7; b = e; b = foof(4.0); b = foof(c < 1); // expected-warning {{implicit conversion turns floating-point number into bool: 'float' to 'bool'}} b = food(e < 2); // expected-warning {{implicit conversion turns floating-point number into bool: 'double' to 'bool'}} foo(c, b); // expected-warning {{implicit conversion turns floating-point number into bool: 'float' to 'bool'}} foo(c, c); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/libstdcxx_pointer_return_false_hack.cpp
// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify // This is a test for an egregious hack in Clang that works around // an issue with libstdc++-4.2's <tr1/hashtable> implementation. // The code in question returns 'false' from a function with a pointer // return type, which is ill-formed in C++11. #ifdef BE_THE_HEADER #pragma GCC system_header namespace std { namespace tr1 { template<typename T> struct hashnode; template<typename T> struct hashtable { typedef hashnode<T> node; node *find_node() { // This is ill-formed in C++11, per core issue 903, but we accept // it anyway in a system header. return false; } }; } } #else #define BE_THE_HEADER #include "libstdcxx_pointer_return_false_hack.cpp" auto *test1 = std::tr1::hashtable<int>().find_node(); void *test2() { return false; } // expected-error {{cannot initialize}} #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/string-init.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s void f() { char a1[] = "a"; // No error. char a2[] = u8"a"; // No error. char a3[] = u"a"; // expected-error{{initializing char array with wide string literal}} char a4[] = U"a"; // expected-error{{initializing char array with wide string literal}} char a5[] = L"a"; // expected-error{{initializing char array with wide string literal}} wchar_t b1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}} wchar_t b2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}} wchar_t b3[] = u"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} wchar_t b4[] = U"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} wchar_t b5[] = L"a"; // No error. char16_t c1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}} char16_t c2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}} char16_t c3[] = u"a"; // No error. char16_t c4[] = U"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} char16_t c5[] = L"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} char32_t d1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}} char32_t d2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}} char32_t d3[] = u"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} char32_t d4[] = U"a"; // No error. char32_t d5[] = L"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} int e1[] = "a"; // expected-error{{array initializer must be an initializer list}} int e2[] = u8"a"; // expected-error{{array initializer must be an initializer list}} int e3[] = u"a"; // expected-error{{array initializer must be an initializer list}} int e4[] = U"a"; // expected-error{{array initializer must be an initializer list}} int e5[] = L"a"; // expected-error{{array initializer must be an initializer list}} } void g() { char a[] = 1; // expected-error{{array initializer must be an initializer list or string literal}} wchar_t b[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}} char16_t c[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}} char32_t d[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/direct-initializer.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s int x(1); int (x2)(1); void f() { int x(1); int (x2)(1); for (int x(1);;) {} } class Y { public: explicit Y(float); }; class X { // expected-note{{candidate constructor (the implicit copy constructor)}} public: explicit X(int); // expected-note{{candidate constructor}} X(float, float, float); // expected-note{{candidate constructor}} X(float, Y); // expected-note{{candidate constructor}} }; class Z { // expected-note{{candidate constructor (the implicit copy constructor)}} public: Z(int); // expected-note{{candidate constructor}} }; void g() { X x1(5); X x2(1.0, 3, 4.2); X x3(1.0, 1.0); // expected-error{{no matching constructor for initialization of 'X'}} Y y(1.0); X x4(3.14, y); Z z; // expected-error{{no matching constructor for initialization of 'Z'}} } struct Base { operator int*() const; }; struct Derived : Base { operator int*(); // expected-note {{candidate function}} }; void foo(const Derived cd, Derived d) { int *pi = cd; // expected-error {{no viable conversion from 'const Derived' to 'int *'}} int *ppi = d; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-unused-value-cxx11.cpp
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wunused-value %s void f() __attribute__((const)); namespace PR18571 { // Unevaluated contexts should not trigger unused result warnings. template <typename T> auto foo(T) -> decltype(f(), bool()) { // Should not warn. return true; } void g() { foo(1); } void h() { int i = 0; (void)noexcept(++i); // expected-warning {{expression with side effects has no effect in an unevaluated context}} decltype(i++) j = 0; // expected-warning {{expression with side effects has no effect in an unevaluated context}} } struct S { S operator++(int); S(int i); S(); int& f(); S g(); }; void j() { S s; int i = 0; (void)noexcept(s++); // Ok (void)noexcept(i++); // expected-warning {{expression with side effects has no effect in an unevaluated context}} (void)noexcept(i = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}} (void)noexcept(s = 5); // Ok (void)sizeof(s.f()); // Ok (void)sizeof(s.f() = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}} (void)noexcept(s.g() = 5); // Ok } }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/virtual-member-functions-key-function.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s struct A { virtual ~A(); }; struct B : A { // expected-error {{no suitable member 'operator delete' in 'B'}} B() { } // expected-note {{implicit destructor for 'B' first required here}} void operator delete(void *, int); // expected-note {{'operator delete' declared here}} }; struct C : A { // expected-error {{no suitable member 'operator delete' in 'C'}} void operator delete(void *, int); // expected-note {{'operator delete' declared here}} }; void f() { (void)new B; (void)new C; // expected-note {{implicit destructor for 'C' first required here}} } // Make sure that the key-function computation is consistent when the // first virtual member function of a nested class has an inline body. struct Outer { struct Inner { virtual void f() { } void g(); }; }; void Outer::Inner::g() { }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/missing-members.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s namespace A { namespace B { class C { }; // expected-note {{'A::B::C' declared here}} struct S { }; union U { }; } } void f() { A::B::i; // expected-error {{no member named 'i' in namespace 'A::B'}} A::B::C::i; // expected-error {{no member named 'i' in 'A::B::C'}} ::i; // expected-error {{no member named 'i' in the global namespace}} } namespace B { class B { }; } void g() { A::B::D::E; // expected-error-re {{no member named 'D' in namespace 'A::B'{{$}}}} // FIXME: The typo corrections below should be suppressed since A::B::C // doesn't have a member named D. B::B::C::D; // expected-error {{no member named 'C' in 'B::B'; did you mean 'A::B::C'?}} \ // expected-error-re {{no member named 'D' in 'A::B::C'{{$}}}} ::C::D; // expected-error-re {{no member named 'C' in the global namespace{{$}}}} } int A::B::i = 10; // expected-error {{no member named 'i' in namespace 'A::B'}} int A::B::C::i = 10; // expected-error {{no member named 'i' in 'A::B::C'}} int A::B::S::i = 10; // expected-error {{no member named 'i' in 'A::B::S'}} int A::B::U::i = 10; // expected-error {{no member named 'i' in 'A::B::U'}} using A::B::D; // expected-error {{no member named 'D' in namespace 'A::B'}} struct S : A::B::C { using A::B::C::f; // expected-error {{no member named 'f' in 'A::B::C'}} };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR23334.cpp
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-unused // This must be at the start of the file (the failure depends on a SmallPtrSet // not having been reallocated yet). void fn1() { // expected-no-diagnostics constexpr int kIsolationClass = 0; const int kBytesPerConnection = 0; [=] { kIsolationClass, kBytesPerConnection, kBytesPerConnection; }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-used.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s extern char test1[] __attribute__((used)); // expected-warning {{'used' attribute ignored}} extern const char test2[] __attribute__((used)); // expected-warning {{'used' attribute ignored}} extern const char test3[] __attribute__((used)) = "";
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/invalid-member-expr.cpp
// RUN: %clang_cc1 -fsyntax-only -verify %s class X {}; void test() { X x; x.int; // expected-error{{expected unqualified-id}} x.~int(); // expected-error{{expected a class name}} x.operator; // expected-error{{expected a type}} x.operator typedef; // expected-error{{expected a type}} expected-error{{type name does not allow storage class}} } void test2() { X *x; x->int; // expected-error{{expected unqualified-id}} x->~int(); // expected-error{{expected a class name}} x->operator; // expected-error{{expected a type}} x->operator typedef; // expected-error{{expected a type}} expected-error{{type name does not allow storage class}} } // PR6327 namespace test3 { template <class A, class B> struct pair {}; void test0() { pair<int, int> z = minmax({}); // expected-error {{expected expression}} } struct string { class iterator {}; }; void test1() { string s; string::iterator i = s.foo(); // expected-error {{no member named 'foo'}} } } // Make sure we don't crash. namespace rdar11293995 { struct Length { explicit Length(PassRefPtr<CalculationValue>); // expected-error {{unknown type name}} \ expected-error {{expected ')'}} \ expected-note {{to match this '('}} }; struct LengthSize { Length m_width; Length m_height; }; enum EFillSizeType { Contain, Cover, SizeLength, SizeNone }; struct FillSize { EFillSizeType type; LengthSize size; }; class FillLayer { public: void setSize(FillSize f) { m_sizeType = f.type;} private: unsigned m_sizeType : 2; }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/ast-print.cpp
// RUN: %clang_cc1 -ast-print %s -std=gnu++11 | FileCheck %s // CHECK: r; // CHECK-NEXT: (r->method()); struct MyClass { void method() {} }; struct Reference { MyClass* object; MyClass* operator ->() { return object; } }; void test1() { Reference r; (r->method()); } // CHECK: if (int a = 1) // CHECK: while (int a = 1) // CHECK: switch (int a = 1) void test2() { if (int a = 1) { } while (int a = 1) { } switch (int a = 1) { } } // CHECK: new (1) int; void *operator new (typeof(sizeof(1)), int, int = 2); void test3() { new (1) int; } // CHECK: new X; struct X { void *operator new (typeof(sizeof(1)), int = 2); }; void test4() { new X; } // CHECK: for (int i = 2097, j = 42; false;) void test5() { for (int i = 2097, j = 42; false;) {} } // CHECK: test6fn((int &)y); void test6fn(int& x); void test6() { unsigned int y = 0; test6fn((int&)y); } // CHECK: S s(1, 2); template <class S> void test7() { S s( 1,2 ); } // CHECK: t.~T(); template <typename T> void test8(T t) { t.~T(); } // CHECK: enum E { // CHECK-NEXT: A, // CHECK-NEXT: B, // CHECK-NEXT: C // CHECK-NEXT: }; // CHECK-NEXT: {{^[ ]+}}E a = A; struct test9 { void f() { enum E { A, B, C }; E a = A; } }; namespace test10 { namespace M { template<typename T> struct X { enum { value }; }; } } typedef int INT; // CHECK: test11 // CHECK-NEXT: return test10::M::X<INT>::value; int test11() { return test10::M::X<INT>::value; } struct DefaultArgClass { DefaultArgClass(int a = 1) {} DefaultArgClass(int a, int b, int c = 1) {} }; struct NoArgClass { NoArgClass() {} }; struct VirualDestrClass { VirualDestrClass(int arg); virtual ~VirualDestrClass(); }; struct ConstrWithCleanupsClass { ConstrWithCleanupsClass(const VirualDestrClass& cplx = VirualDestrClass(42)); }; // CHECK: test12 // CHECK-NEXT: DefaultArgClass useDefaultArg; // CHECK-NEXT: DefaultArgClass overrideDefaultArg(1); // CHECK-NEXT: DefaultArgClass(1, 2); // CHECK-NEXT: DefaultArgClass(1, 2, 3); // CHECK-NEXT: NoArgClass noArg; // CHECK-NEXT: ConstrWithCleanupsClass cwcNoArg; // CHECK-NEXT: ConstrWithCleanupsClass cwcOverrideArg(48); // CHECK-NEXT: ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56)); void test12() { DefaultArgClass useDefaultArg; DefaultArgClass overrideDefaultArg(1); DefaultArgClass tempWithDefaultArg = DefaultArgClass(1, 2); DefaultArgClass tempWithExplictArg = DefaultArgClass(1, 2, 3); NoArgClass noArg; ConstrWithCleanupsClass cwcNoArg; ConstrWithCleanupsClass cwcOverrideArg(48); ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56)); } // CHECK: void test13() { // CHECK: _Atomic(int) i; // CHECK: __c11_atomic_init(&i, 0); // CHECK: __c11_atomic_load(&i, 0); // CHECK: } void test13() { _Atomic(int) i; __c11_atomic_init(&i, 0); __c11_atomic_load(&i, 0); } // CHECK: void test14() { // CHECK: struct X { // CHECK: union { // CHECK: int x; // CHECK: } x; // CHECK: }; // CHECK: } void test14() { struct X { union { int x; } x; }; } // CHECK: float test15() { // CHECK: return __builtin_asinf(1.F); // CHECK: } // CHECK-NOT: extern "C" float test15() { return __builtin_asinf(1.0F); } namespace PR18776 { struct A { operator void *(); explicit operator bool(); A operator&(A); }; // CHECK: struct A // CHECK-NEXT: {{^[ ]*operator}} void *(); // CHECK-NEXT: {{^[ ]*explicit}} operator bool(); void bar(void *); void foo() { A a, b; bar(a & b); // CHECK: bar(a & b); if (a & b) // CHECK: if (a & b) return; } }; namespace { void test(int i) { switch (i) { case 1: // CHECK: {{\[\[clang::fallthrough\]\]}} [[clang::fallthrough]]; case 2: break; } } } namespace { // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S; struct [[gnu::visibility("hidden")]] S; } // CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{}; struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{}; // CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{}; struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{};
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-absolute-value-header.cpp
// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s extern "C" { int abs(int); float fabsf(float); } namespace std { int abs(int); float abs(float); } void test(long long ll, double d, int i, float f) { // Suggest including cmath (void)abs(d); // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} // expected-note@-2{{use function 'std::abs' instead}} // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs" (void)fabsf(d); // expected-warning@-1{{absolute value function 'fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value}} // expected-note@-2{{use function 'std::abs' instead}} // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs" // Suggest including cstdlib (void)abs(ll); // expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}} // expected-note@-2{{use function 'std::abs' instead}} // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs" (void)fabsf(ll); // expected-warning@-1{{using floating point absolute value function 'fabsf' when argument is of integer type}} // expected-note@-2{{use function 'std::abs' instead}} // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs" // Proper function already called, no warnings. (void)abs(i); (void)fabsf(f); // Declarations found, suggest name change. (void)fabsf(i); // expected-warning@-1{{using floating point absolute value function 'fabsf' when argument is of integer type}} // expected-note@-2{{use function 'std::abs' instead}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" (void)abs(f); // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} // expected-note@-2{{use function 'std::abs' instead}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"std::abs" }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/conversion.cpp
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wconversion -std=c++11 -verify %s // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wconversion -std=c++11 %s 2>&1 | FileCheck %s #include <stddef.h> typedef signed char int8_t; typedef signed short int16_t; typedef signed int int32_t; typedef signed long int64_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef unsigned long uint64_t; // <rdar://problem/7909130> namespace test0 { int32_t test1_positive(char *I, char *E) { return (E - I); // expected-warning {{implicit conversion loses integer precision}} } int32_t test1_negative(char *I, char *E) { return static_cast<int32_t>(E - I); } uint32_t test2_positive(uint64_t x) { return x; // expected-warning {{implicit conversion loses integer precision}} } uint32_t test2_negative(uint64_t x) { return (uint32_t) x; } } namespace test1 { uint64_t test1(int x, unsigned y) { return sizeof(x == y); } uint64_t test2(int x, unsigned y) { return __alignof(x == y); } void * const foo(); bool test2(void *p) { return p == foo(); } } namespace test2 { struct A { unsigned int x : 2; A() : x(10) {} // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} }; } // This file tests -Wnull-conversion, a subcategory of -Wconversion // which is on by default. void test3() { int a = NULL; // expected-warning {{implicit conversion of NULL constant to 'int'}} int b; b = NULL; // expected-warning {{implicit conversion of NULL constant to 'int'}} long l = NULL; // FIXME: this should also warn, but currently does not if sizeof(NULL)==sizeof(inttype) int c = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to 'int'}} int d; d = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to 'int'}} bool bl = NULL; // expected-warning {{implicit conversion of NULL constant to 'bool'}} char ch = NULL; // expected-warning {{implicit conversion of NULL constant to 'char'}} unsigned char uch = NULL; // expected-warning {{implicit conversion of NULL constant to 'unsigned char'}} short sh = NULL; // expected-warning {{implicit conversion of NULL constant to 'short'}} double dbl = NULL; // expected-warning {{implicit conversion of NULL constant to 'double'}} // Use FileCheck to ensure we don't get any unnecessary macro-expansion notes // (that don't appear as 'real' notes & can't be seen/tested by -verify) // CHECK-NOT: note: // CHECK: note: expanded from macro 'FINIT' #define FINIT int a3 = NULL; FINIT // expected-warning {{implicit conversion of NULL constant to 'int'}} // we don't catch the case of #define FOO NULL ... int i = FOO; but that seems a bit narrow anyway // and avoiding that helps us skip these cases: #define NULL_COND(cond) ((cond) ? &a : NULL) bool bl2 = NULL_COND(true); // don't warn on NULL conversion through the conditional operator across a macro boundary if (NULL_COND(true)) ; while (NULL_COND(true)) ; for (; NULL_COND(true); ) ; do ; while(NULL_COND(true)); #define NULL_WRAPPER NULL_COND(false) if (NULL_WRAPPER) ; while (NULL_WRAPPER) ; for (; NULL_WRAPPER;) ; do ; while (NULL_WRAPPER); int *ip = NULL; int (*fp)() = NULL; struct foo { int n; void func(); }; int foo::*datamem = NULL; int (foo::*funmem)() = NULL; } namespace test4 { // FIXME: We should warn for non-dependent args (only when the param type is also non-dependent) only once // not once for the template + once for every instantiation template<typename T> void tmpl(char c = NULL, // expected-warning 4 {{implicit conversion of NULL constant to 'char'}} T a = NULL, // expected-warning {{implicit conversion of NULL constant to 'char'}} \ expected-warning 2 {{implicit conversion of NULL constant to 'int'}} T b = 1024) { // expected-warning {{implicit conversion from 'int' to 'char' changes value from 1024 to 0}} } template<typename T> void tmpl2(T t = NULL) { } void func() { tmpl<char>(); // expected-note 2 {{in instantiation of default function argument expression for 'tmpl<char>' required here}} tmpl<int>(); // expected-note 2 {{in instantiation of default function argument expression for 'tmpl<int>' required here}} // FIXME: We should warn only once for each template instantiation - not once for each call tmpl<int>(); // expected-note 2 {{in instantiation of default function argument expression for 'tmpl<int>' required here}} tmpl2<int*>(); } } namespace test5 { template<int I> void func() { bool b = I; } template void func<3>(); } namespace test6 { decltype(nullptr) func() { return NULL; } } namespace test7 { bool fun() { bool x = nullptr; // expected-warning {{implicit conversion of nullptr constant to 'bool'}} if (nullptr) {} // expected-warning {{implicit conversion of nullptr constant to 'bool'}} return nullptr; // expected-warning {{implicit conversion of nullptr constant to 'bool'}} } }