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/virtual-override.cpp
|
// RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify %s -std=c++11
// RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -verify %s -std=c++11
namespace T1 {
class A {
virtual int f(); // expected-note{{overridden virtual function is here}}
};
class B : A {
virtual void f(); // expected-error{{virtual function 'f' has a different return type ('void') than the function it overrides (which has return type 'int')}}
};
}
namespace T2 {
struct a { };
struct b { };
class A {
virtual a* f(); // expected-note{{overridden virtual function is here}}
};
class B : A {
virtual b* f(); // expected-error{{return type of virtual function 'f' is not covariant with the return type of the function it overrides ('T2::b *' is not derived from 'T2::a *')}}
};
}
namespace T3 {
struct a { };
struct b : private a { }; // expected-note{{declared private here}}
class A {
virtual a* f(); // FIXME: desired-note{{overridden virtual function is here}}
};
class B : A {
virtual b* f(); // expected-error{{invalid covariant return for virtual function: 'T3::a' is a private base class of 'T3::b'}}
};
}
namespace T4 {
struct a { };
struct a1 : a { };
struct b : a, a1 { }; // expected-warning{{direct base 'T4::a' is inaccessible due to ambiguity:\n struct T4::b -> struct T4::a\n struct T4::b -> struct T4::a1 -> struct T4::a}}
class A {
virtual a* f(); // expected-note{{overridden virtual function is here}}
};
class B : A {
virtual b* f(); // expected-error{{return type of virtual function 'f' is not covariant with the return type of the function it overrides (ambiguous conversion from derived class 'T4::b' to base class 'T4::a':\n\
struct T4::b -> struct T4::a\n\
struct T4::b -> struct T4::a1 -> struct T4::a)}}
};
}
namespace T5 {
struct a { };
class A {
virtual a* const f();
virtual a* const g(); // expected-note{{overridden virtual function is here}}
};
class B : A {
virtual a* const f();
virtual a* g(); // expected-error{{return type of virtual function 'g' is not covariant with the return type of the function it overrides ('T5::a *' has different qualifiers than 'T5::a *const')}}
};
}
namespace T6 {
struct a { };
class A {
virtual const a* f();
virtual a* g(); // expected-note{{overridden virtual function is here}}
};
class B : A {
virtual a* f();
virtual const a* g(); // expected-error{{return type of virtual function 'g' is not covariant with the return type of the function it overrides (class type 'const T6::a *' is more qualified than class type 'T6::a *'}}
};
}
namespace T7 {
struct a { };
struct b { };
class A {
a* f();
};
class B : A {
virtual b* f();
};
}
namespace T8 {
struct a { };
struct b; // expected-note {{forward declaration of 'T8::b'}}
class A {
virtual a *f();
};
class B : A {
b* f(); // expected-error {{return type of virtual function 'f' is not covariant with the return type of the function it overrides ('T8::b' is incomplete)}}
};
}
namespace T9 {
struct a { };
template<typename T> struct b : a {
int a[sizeof(T) ? -1 : -1]; // expected-error {{array with a negative size}}
};
class A {
virtual a *f();
};
class B : A {
virtual b<int> *f(); // expected-note {{in instantiation of template class 'T9::b<int>' requested here}}
};
}
// PR5656
class X0 {
virtual void f0();
};
class X1 : public X0 {
void f0() = 0;
};
template <typename Base>
struct Foo : Base {
void f(int) = 0; // expected-error{{not virtual and cannot be declared pure}}
};
struct Base1 { virtual void f(int); };
struct Base2 { };
void test() {
(void)sizeof(Foo<Base1>);
(void)sizeof(Foo<Base2>); // expected-note{{instantiation}}
}
template<typename Base>
struct Foo2 : Base {
template<typename T> int f(T);
};
void test2() {
Foo2<Base1> f1;
Foo2<Base2> f2;
f1.f(17);
f2.f(17);
};
struct Foo3 {
virtual void f(int) = 0; // expected-note{{unimplemented pure virtual method}}
};
template<typename T>
struct Bar3 : Foo3 {
void f(T);
};
void test3() {
Bar3<int> b3i; // okay
Bar3<float> b3f; // expected-error{{is an abstract class}}
}
// 5920
namespace PR5920 {
class Base {};
template <typename T>
class Derived : public Base {};
class Foo {
public:
virtual Base* Method();
};
class Bar : public Foo {
public:
virtual Derived<int>* Method();
};
}
// Look through template types and typedefs to see whether return types are
// pointers or references.
namespace PR6110 {
class Base {};
class Derived : public Base {};
typedef Base* BaseP;
typedef Derived* DerivedP;
class X { virtual BaseP f(); };
class X1 : public X { virtual DerivedP f(); };
template <typename T> class Y { virtual T f(); };
template <typename T1, typename T> class Y1 : public Y<T> { virtual T1 f(); };
Y1<Derived*, Base*> y;
}
// Defer checking for covariance if either return type is dependent.
namespace type_dependent_covariance {
struct B {};
template <int N> struct TD : public B {};
template <> struct TD<1> {};
template <int N> struct TB {};
struct D : public TB<0> {};
template <int N> struct X {
virtual B* f1(); // expected-note{{overridden virtual function is here}}
virtual TB<N>* f2(); // expected-note{{overridden virtual function is here}}
};
template <int N, int M> struct X1 : X<N> {
virtual TD<M>* f1(); // expected-error{{return type of virtual function 'f1' is not covariant with the return type of the function it overrides ('TD<1> *'}}
virtual D* f2(); // expected-error{{return type of virtual function 'f2' is not covariant with the return type of the function it overrides ('type_dependent_covariance::D *' is not derived from 'TB<1> *')}}
};
X1<0, 0> good;
X1<0, 1> bad_derived; // expected-note{{instantiation}}
X1<1, 0> bad_base; // expected-note{{instantiation}}
}
namespace T10 {
struct A { };
struct B : A { };
struct C {
virtual A&& f();
};
struct D : C {
virtual B&& f();
};
};
namespace T11 {
struct A { };
struct B : A { };
struct C {
virtual A& f(); // expected-note {{overridden virtual function is here}}
};
struct D : C {
virtual B&& f(); // expected-error {{virtual function 'f' has a different return type ('T11::B &&') than the function it overrides (which has return type 'T11::A &')}}
};
};
namespace T12 {
struct A { };
struct B : A { };
struct C {
virtual A&& f(); // expected-note {{overridden virtual function is here}}
};
struct D : C {
virtual B& f(); // expected-error {{virtual function 'f' has a different return type ('T12::B &') than the function it overrides (which has return type 'T12::A &&')}}
};
};
namespace PR8168 {
class A {
public:
virtual void foo() {} // expected-note{{overridden virtual function is here}}
};
class B : public A {
public:
static void foo() {} // expected-error{{'static' member function 'foo' overrides a virtual function}}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/addr-of-overloaded-function-casting.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
void g();
void f(); // expected-note 11{{candidate function}}
void f(int); // expected-note 11{{candidate function}}
template <class T>
void t(T); // expected-note 3{{candidate function}} \
// expected-note 3{{candidate template ignored: could not match 'void' against 'int'}}
template <class T>
void t(T *); // expected-note 3{{candidate function}} \
// expected-note 3{{candidate template ignored: could not match 'void' against 'int'}}
template<class T> void u(T);
int main()
{
{ bool b = (void (&)(char))f; } // expected-error{{does not match required type}}
{ bool b = (void (*)(char))f; } // expected-error{{does not match required type}}
{ bool b = (void (&)(int))f; } //ok
{ bool b = (void (*)(int))f; } //ok
{ bool b = static_cast<void (&)(char)>(f); } // expected-error{{does not match}}
{ bool b = static_cast<void (*)(char)>(f); } // expected-error{{address of overloaded function}}
{ bool b = static_cast<void (&)(int)>(f); } //ok
{ bool b = static_cast<void (*)(int)>(f); } //ok
{ bool b = reinterpret_cast<void (&)(char)>(f); } // expected-error{{cannot resolve}}
{ bool b = reinterpret_cast<void (*)(char)>(f); } // expected-error{{cannot resolve}}
{ bool b = reinterpret_cast<void (*)(char)>(g); } //ok
{ bool b = static_cast<void (*)(char)>(g); } // expected-error{{not allowed}}
{ bool b = reinterpret_cast<void (&)(int)>(f); } // expected-error{{cannot resolve}}
{ bool b = reinterpret_cast<void (*)(int)>(f); } // expected-error{{cannot resolve}}
{ bool b = (int (&)(char))t; } // expected-error{{does not match}}
{ bool b = (int (*)(char))t; } // expected-error{{does not match}}
{ bool b = (void (&)(int))t; } //ok
{ bool b = (void (*)(int))t; } //ok
{ bool b = static_cast<void (&)(char)>(t); } //ok
{ bool b = static_cast<void (*)(char)>(t); } //ok
{ bool b = static_cast<void (&)(int)>(t); } //ok
{ bool b = static_cast<void (*)(int)>(t); } //ok
{ bool b = reinterpret_cast<void (&)(char)>(t); } // expected-error{{cannot resolve}}
{ bool b = reinterpret_cast<void (*)(char)>(t); } // expected-error{{cannot resolve}}
{ bool b = reinterpret_cast<int (*)(char)>(g); } //ok
{ bool b = static_cast<int (*)(char)>(t); } // expected-error{{cannot be static_cast}}
{ bool b = static_cast<int (&)(char)>(t); } // expected-error{{does not match required}}
{ bool b = static_cast<void (&)(char)>(f); } // expected-error{{does not match}}
{
// The error should be reported when casting overloaded function to the
// compatible function type (not to be confused with function pointer or
// function reference type.)
typedef void (FnType)(int);
FnType a = static_cast<FnType>(f); // expected-error{{address of overloaded function}}
FnType b = (FnType)(f); // expected-error{{address of overloaded function}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/no-exceptions.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// Various tests for -fno-exceptions
typedef __SIZE_TYPE__ size_t;
namespace test0 {
// rdar://problem/7878149
class Foo {
public:
void* operator new(size_t x);
private:
void operator delete(void *x);
};
void test() {
// Under -fexceptions, this does access control for the associated
// 'operator delete'.
(void) new Foo();
}
}
namespace test1 {
void f() {
throw; // expected-error {{cannot use 'throw' with exceptions disabled}}
}
void g() {
try { // expected-error {{cannot use 'try' with exceptions disabled}}
f();
} catch (...) {
}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/typo-correction.cpp
|
// RUN: %clang_cc1 -fspell-checking-limit 0 -verify -Wno-c++11-extensions %s
namespace PR21817{
int a(-rsing[2]); // expected-error {{undeclared identifier 'rsing'; did you mean 'using'?}}
// expected-error@-1 {{expected expression}}
}
struct errc {
int v_;
operator int() const {return v_;}
};
class error_condition
{
int _val_;
public:
error_condition() : _val_(0) {}
error_condition(int _val)
: _val_(_val) {}
template <class E>
error_condition(E _e) {
// make_error_condition must not be typo corrected to error_condition
// even though the first declaration of make_error_condition has not
// yet been encountered. This was a bug in the first version of the type
// name typo correction patch that wasn't noticed until building LLVM with
// Clang failed.
*this = make_error_condition(_e);
}
};
inline error_condition make_error_condition(errc _e) {
return error_condition(static_cast<int>(_e));
}
// Prior to the introduction of a callback object to further filter possible
// typo corrections, this example would not trigger a suggestion as "base_type"
// is a closer match to "basetype" than is "BaseType" but "base_type" does not
// refer to a base class or non-static data member.
struct BaseType { };
struct Derived : public BaseType { // expected-note {{base class 'BaseType' specified here}}
static int base_type; // expected-note {{'base_type' declared here}}
Derived() : basetype() {} // expected-error{{initializer 'basetype' does not name a non-static data member or base class; did you mean the base class 'BaseType'?}}
};
// Test the improvement from passing a callback object to CorrectTypo in
// the helper function LookupMemberExprInRecord.
int get_type(struct Derived *st) {
return st->Base_Type; // expected-error{{no member named 'Base_Type' in 'Derived'; did you mean 'base_type'?}}
}
// In this example, somename should not be corrected to the cached correction
// "some_name" since "some_name" is a class and a namespace name is needed.
class some_name {}; // expected-note {{'some_name' declared here}}
somename Foo; // expected-error {{unknown type name 'somename'; did you mean 'some_name'?}}
namespace SomeName {} // expected-note {{namespace 'SomeName' defined here}}
using namespace somename; // expected-error {{no namespace named 'somename'; did you mean 'SomeName'?}}
// Without the callback object, CorrectTypo would choose "field1" as the
// correction for "fielda" as it is closer than "FieldA", but that correction
// would be later discarded by the caller and no suggestion would be given.
struct st {
struct {
int field1;
};
double FieldA; // expected-note{{'FieldA' declared here}}
};
st var = { .fielda = 0.0 }; // expected-error{{field designator 'fielda' does not refer to any field in type 'st'; did you mean 'FieldA'?}}
// Test the improvement from passing a callback object to CorrectTypo in
// Sema::BuildCXXNestedNameSpecifier. And also for the improvement by doing
// so in Sema::getTypeName.
typedef char* another_str; // expected-note{{'another_str' declared here}}
namespace AnotherStd { // expected-note{{'AnotherStd' declared here}}
class string {};
}
another_std::string str; // expected-error{{use of undeclared identifier 'another_std'; did you mean 'AnotherStd'?}}
another_str *cstr = new AnotherStr; // expected-error{{unknown type name 'AnotherStr'; did you mean 'another_str'?}}
// Test the improvement from passing a callback object to CorrectTypo in
// Sema::ActOnSizeofParameterPackExpr.
char* TireNames;
template<typename ...TypeNames> struct count { // expected-note{{parameter pack 'TypeNames' declared here}}
static const unsigned value = sizeof...(TyreNames); // expected-error{{'TyreNames' does not refer to the name of a parameter pack; did you mean 'TypeNames'?}}
};
// Test the typo-correction callback in Sema::DiagnoseUnknownTypeName.
namespace unknown_type_test {
class StreamOut {}; // expected-note 2 {{'StreamOut' declared here}}
long stream_count; // expected-note 2 {{'stream_count' declared here}}
};
unknown_type_test::stream_out out; // expected-error{{no type named 'stream_out' in namespace 'unknown_type_test'; did you mean 'StreamOut'?}}
// Demonstrate a case where using only the cached value returns the wrong thing
// when the cached value was the result of a previous callback object that only
// accepts a subset of the current callback object.
namespace cache_invalidation_test {
using namespace unknown_type_test;
void bar(long i);
void before_caching_classname() {
bar((stream_out)); // expected-error{{use of undeclared identifier 'stream_out'; did you mean 'stream_count'?}}
}
stream_out out; // expected-error{{unknown type name 'stream_out'; did you mean 'StreamOut'?}}
void after_caching_classname() {
bar((stream_out)); // expected-error{{use of undeclared identifier 'stream_out'; did you mean 'stream_count'?}}
}
}
// Test the typo-correction callback in Sema::DiagnoseInvalidRedeclaration.
struct BaseDecl {
void add_in(int i);
};
struct TestRedecl : public BaseDecl {
void add_it(int i); // expected-note{{'add_it' declared here}}
};
void TestRedecl::add_in(int i) {} // expected-error{{out-of-line definition of 'add_in' does not match any declaration in 'TestRedecl'; did you mean 'add_it'?}}
// Test the improved typo correction for the Parser::ParseCastExpr =>
// Sema::ActOnIdExpression => Sema::DiagnoseEmptyLookup call path.
class SomeNetMessage; // expected-note 2{{'SomeNetMessage'}}
class Message {};
void foo(Message&);
void foo(SomeNetMessage&);
void doit(void *data) {
Message somenetmsg; // expected-note{{'somenetmsg' declared here}}
foo(somenetmessage); // expected-error{{use of undeclared identifier 'somenetmessage'; did you mean 'somenetmsg'?}}
foo((somenetmessage)data); // expected-error{{unknown type name 'somenetmessage'; did you mean 'SomeNetMessage'?}} expected-error{{incomplete type}}
}
// Test the typo-correction callback in BuildRecoveryCallExpr.
// Solves the main issue in PR 9320 of suggesting corrections that take the
// wrong number of arguments.
void revoke(const char*); // expected-note 2{{'revoke' declared here}}
void Test() {
Invoke(); // expected-error{{use of undeclared identifier 'Invoke'}}
Invoke("foo"); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'revoke'?}}
Invoke("foo", "bar"); // expected-error{{use of undeclared identifier 'Invoke'}}
}
void Test2(void (*invoke)(const char *, int)) { // expected-note{{'invoke' declared here}}
Invoke(); // expected-error{{use of undeclared identifier 'Invoke'}}
Invoke("foo"); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'revoke'?}}
Invoke("foo", 7); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'invoke'?}}
Invoke("foo", 7, 22); // expected-error{{use of undeclared identifier 'Invoke'}}
}
void provoke(const char *x, bool y=false) {} // expected-note 2{{'provoke' declared here}}
void Test3() {
Provoke(); // expected-error{{use of undeclared identifier 'Provoke'}}
Provoke("foo"); // expected-error{{use of undeclared identifier 'Provoke'; did you mean 'provoke'?}}
Provoke("foo", true); // expected-error{{use of undeclared identifier 'Provoke'; did you mean 'provoke'?}}
Provoke("foo", 7, 22); // expected-error{{use of undeclared identifier 'Provoke'}}
}
// PR 11737 - Don't try to typo-correct the implicit 'begin' and 'end' in a
// C++11 for-range statement.
struct R {};
bool begun(R);
void RangeTest() {
for (auto b : R()) {} // expected-error {{invalid range expression of type 'R'}}
}
// PR 12019 - Avoid infinite mutual recursion in DiagnoseInvalidRedeclaration
// by not trying to typo-correct a method redeclaration to declarations not
// in the current record.
class Parent {
void set_types(int index, int value);
void add_types(int value);
};
class Child: public Parent {};
void Child::add_types(int value) {} // expected-error{{out-of-line definition of 'add_types' does not match any declaration in 'Child'}}
// Fix the callback based filtering of typo corrections within
// Sema::ActOnIdExpression by Parser::ParseCastExpression to allow type names as
// potential corrections for template arguments.
namespace clash {
class ConstructExpr {}; // expected-note 2{{'clash::ConstructExpr' declared here}}
}
class ClashTool {
bool HaveConstructExpr();
template <class T> T* getExprAs();
void test() {
ConstructExpr *expr = // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}}
getExprAs<ConstructExpr>(); // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}}
}
};
namespace test1 {
struct S {
struct Foobar *f; // expected-note{{'Foobar' declared here}}
};
test1::FooBar *b; // expected-error{{no type named 'FooBar' in namespace 'test1'; did you mean 'Foobar'?}}
}
namespace ImplicitInt {
void f(int, unsinged); // expected-error{{did you mean 'unsigned'}}
struct S {
unsinged : 4; // expected-error{{did you mean 'unsigned'}}
};
}
namespace PR13051 {
template<typename T> struct S {
template<typename U> void f();
operator bool() const;
};
void foo(); // expected-note{{'foo' declared here}}
void g(void(*)()); // expected-note{{candidate function not viable}}
void g(bool(S<int>::*)() const); // expected-note{{candidate function not viable}}
void test() {
g(&S<int>::tempalte f<int>); // expected-error{{did you mean 'template'?}} \
// expected-error{{no matching function for call to 'g'}}
g(&S<int>::opeartor bool); // expected-error{{did you mean 'operator'?}}
g(&S<int>::foo); // expected-error{{no member named 'foo' in 'PR13051::S<int>'; did you mean simply 'foo'?}}
}
}
inf f(doulbe); // expected-error{{'int'}} expected-error{{'double'}}
namespace PR6325 {
class foo { }; // expected-note{{'foo' declared here}}
// Note that for this example (pulled from the PR), if keywords are not excluded
// as correction candidates then no suggestion would be given; correcting
// 'boo' to 'bool' is the same edit distance as correcting 'boo' to 'foo'.
class bar : boo { }; // expected-error{{unknown class name 'boo'; did you mean 'foo'?}}
}
namespace outer {
void somefunc(); // expected-note{{'::outer::somefunc' declared here}}
void somefunc(int, int); // expected-note{{'::outer::somefunc' declared here}}
namespace inner {
void somefunc(int) {
someFunc(); // expected-error{{use of undeclared identifier 'someFunc'; did you mean '::outer::somefunc'?}}
someFunc(1, 2); // expected-error{{use of undeclared identifier 'someFunc'; did you mean '::outer::somefunc'?}}
}
}
}
namespace b6956809_test1 {
struct A {};
struct B {};
struct S1 {
void method(A*); // no note here
void method(B*); // expected-note{{'method' declared here}}
};
void test1() {
B b;
S1 s;
s.methodd(&b); // expected-error{{no member named 'methodd' in 'b6956809_test1::S1'; did you mean 'method'}}
}
struct S2 {
S2();
void method(A*) const;
private:
void method(B*);
};
void test2() {
B b;
const S2 s;
s.methodd(&b); // expected-error-re{{no member named 'methodd' in 'b6956809_test1::S2'{{$}}}}
}
}
namespace b6956809_test2 {
template<typename T> struct Err { typename T::error n; }; // expected-error{{type 'void *' cannot be used prior to '::' because it has no members}}
struct S {
template<typename T> typename Err<T>::type method(T); // expected-note{{in instantiation of template class 'b6956809_test2::Err<void *>' requested here}}
template<typename T> int method(T *); // expected-note{{'method' declared here}}
};
void test() {
S s;
int k = s.methodd((void*)0); // expected-error{{no member named 'methodd' in 'b6956809_test2::S'; did you mean 'method'?}} expected-note{{while substituting deduced template arguments into function template 'method' [with T = void *]}}
}
}
namespace PR12951 {
// If there are two corrections that have the same identifier and edit distance
// and only differ by their namespaces, don't suggest either as a correction
// since both are equally likely corrections.
namespace foobar { struct Thing {}; }
namespace bazquux { struct Thing {}; }
void f() { Thing t; } // expected-error{{unknown type name 'Thing'}}
}
namespace bogus_keyword_suggestion {
void test() {
status = "OK"; // expected-error-re {{use of undeclared identifier 'status'{{$}}}}
return status; // expected-error-re {{use of undeclared identifier 'status'{{$}}}}
}
}
namespace PR13387 {
struct A {
void CreateFoo(float, float);
void CreateBar(float, float);
};
struct B : A {
using A::CreateFoo;
void CreateFoo(int, int); // expected-note {{'CreateFoo' declared here}}
};
void f(B &x) {
x.Createfoo(0,0); // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}}
}
}
struct DataStruct {void foo();};
struct T {
DataStruct data_struct;
void f();
};
// should be void T::f();
void f() {
data_struct->foo(); // expected-error-re{{use of undeclared identifier 'data_struct'{{$}}}}
}
namespace PR12287 {
class zif {
void nab(int);
};
void nab(); // expected-note{{'::PR12287::nab' declared here}}
void zif::nab(int) {
nab(); // expected-error{{too few arguments to function call, expected 1, have 0; did you mean '::PR12287::nab'?}}
}
}
namespace TemplateFunction {
template <class T>
void A(T) { } // expected-note {{'::TemplateFunction::A' declared here}}
template <class T>
void B(T) { } // expected-note {{'::TemplateFunction::B' declared here}}
class Foo {
public:
void A(int, int) {}
void B() {}
};
void test(Foo F, int num) {
F.A(num); // expected-error {{too few arguments to function call, expected 2, have 1; did you mean '::TemplateFunction::A'?}}
F.B(num); // expected-error {{too many arguments to function call, expected 0, have 1; did you mean '::TemplateFunction::B'?}}
}
}
namespace using_suggestion_val_dropped_specifier {
void FFF() {} // expected-note {{'::using_suggestion_val_dropped_specifier::FFF' declared here}}
namespace N { }
using N::FFF; // expected-error {{no member named 'FFF' in namespace 'using_suggestion_val_dropped_specifier::N'; did you mean '::using_suggestion_val_dropped_specifier::FFF'?}}
}
namespace class_member_typo_corrections {
class Outer {
public:
class Inner {}; // expected-note {{'Outer::Inner' declared here}}
Inner MyMethod(Inner arg);
};
Inner Outer::MyMethod(Inner arg) { // expected-error {{unknown type name 'Inner'; did you mean 'Outer::Inner'?}}
return Inner();
}
class Result {
public:
enum ResultType {
ENTITY, // expected-note {{'Result::ENTITY' declared here}}
PREDICATE, // expected-note {{'Result::PREDICATE' declared here}}
LITERAL // expected-note {{'Result::LITERAL' declared here}}
};
ResultType type();
};
void test() {
Result result_cell;
switch (result_cell.type()) {
case ENTITY: // expected-error {{use of undeclared identifier 'ENTITY'; did you mean 'Result::ENTITY'?}}
case LITERAL: // expected-error {{use of undeclared identifier 'LITERAL'; did you mean 'Result::LITERAL'?}}
case PREDICAT: // expected-error {{use of undeclared identifier 'PREDICAT'; did you mean 'Result::PREDICATE'?}}
break;
}
}
class Figure {
enum ResultType {
SQUARE,
TRIANGLE,
CIRCLE
};
public:
ResultType type();
};
void testAccess() {
Figure obj;
switch (obj.type()) { // expected-warning {{enumeration values 'SQUARE', 'TRIANGLE', and 'CIRCLE' not handled in switch}}
case SQUARE: // expected-error-re {{use of undeclared identifier 'SQUARE'{{$}}}}
case TRIANGLE: // expected-error-re {{use of undeclared identifier 'TRIANGLE'{{$}}}}
case CIRCE: // expected-error-re {{use of undeclared identifier 'CIRCE'{{$}}}}
break;
}
}
}
long readline(const char *, char *, unsigned long);
void assign_to_unknown_var() {
deadline_ = 1; // expected-error-re {{use of undeclared identifier 'deadline_'{{$}}}}
}
namespace no_ns_before_dot {
namespace re2 {}
void test() {
req.set_check(false); // expected-error-re {{use of undeclared identifier 'req'{{$}}}}
}
}
namespace PR17394 {
class A {
protected:
long zzzzzzzzzz;
};
class B : private A {};
B zzzzzzzzzy<>; // expected-error {{expected ';' after top level declarator}}{}
}
namespace correct_fields_in_member_funcs {
struct S {
int my_member; // expected-note {{'my_member' declared here}}
void f() { my_menber = 1; } // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}}
};
}
namespace PR17019 {
template<class F>
struct evil {
evil(F de) { // expected-note {{'de' declared here}}
de_; // expected-error {{use of undeclared identifier 'de_'; did you mean 'de'?}} \
// expected-warning {{expression result unused}}
}
~evil() {
de_->bar() // expected-error {{use of undeclared identifier 'de_'}}
}
};
void meow() {
evil<int> Q(0); // expected-note {{in instantiation of member function}}
}
}
namespace fix_class_name_qualifier {
class MessageHeaders {};
class MessageUtils {
public:
static void ParseMessageHeaders(int, int); // expected-note {{'MessageUtils::ParseMessageHeaders' declared here}}
};
void test() {
// No, we didn't mean to call MessageHeaders::MessageHeaders.
MessageHeaders::ParseMessageHeaders(5, 4); // expected-error {{no member named 'ParseMessageHeaders' in 'fix_class_name_qualifier::MessageHeaders'; did you mean 'MessageUtils::ParseMessageHeaders'?}}
}
}
namespace PR18213 { // expected-note {{'PR18213' declared here}}
struct WrapperInfo {
int i;
};
template <typename T> struct Wrappable {
static WrapperInfo kWrapperInfo;
};
// Note the space before "::PR18213" is intended and needed, as it highlights
// the actual typo, which is the leading "::".
// TODO: Suggest removing the "::" from "::PR18213" (the right correction)
// instead of incorrectly suggesting dropping "PR18213::WrapperInfo::".
template <>
PR18213::WrapperInfo ::PR18213::Wrappable<int>::kWrapperInfo = { 0 }; // expected-error {{no member named 'PR18213' in 'PR18213::WrapperInfo'; did you mean simply 'PR18213'?}} \
// expected-error {{C++ requires a type specifier for all declarations}}
}
namespace PR18651 {
struct {
int x;
} a, b;
int y = x; // expected-error-re {{use of undeclared identifier 'x'{{$}}}}
}
namespace PR18685 {
template <class C, int I, int J>
class SetVector {
public:
SetVector() {}
};
template <class C, int I>
class SmallSetVector : public SetVector<C, I, 8> {};
class foo {};
SmallSetVector<foo*, 2> fooSet;
}
PR18685::BitVector Map; // expected-error-re {{no type named 'BitVector' in namespace 'PR18685'{{$}}}}
namespace shadowed_template {
template <typename T> class Fizbin {}; // expected-note {{'::shadowed_template::Fizbin' declared here}}
class Baz {
int Fizbin();
// TODO: Teach the parser to recover from the typo correction instead of
// continuing to treat the template name as an implicit-int declaration.
Fizbin<int> qux; // expected-error {{unknown type name 'Fizbin'; did you mean '::shadowed_template::Fizbin'?}} \
// expected-error {{expected member name or ';' after declaration specifiers}}
};
}
namespace PR18852 {
void func() {
struct foo {
void bar() {}
};
bar(); // expected-error-re {{use of undeclared identifier 'bar'{{$}}}}
}
class Thread {
public:
void Start();
static void Stop(); // expected-note {{'Thread::Stop' declared here}}
};
class Manager {
public:
void Start(int); // expected-note {{'Start' declared here}}
void Stop(int); // expected-note {{'Stop' declared here}}
};
void test(Manager *m) {
// Don't suggest Thread::Start as a correction just because it has the same
// (unqualified) name and accepts the right number of args; this is a method
// call on an object in an unrelated class.
m->Start(); // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}}
m->Stop(); // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}}
Stop(); // expected-error {{use of undeclared identifier 'Stop'; did you mean 'Thread::Stop'?}}
}
}
namespace std {
class bernoulli_distribution {
public:
double p() const;
};
}
void test() {
// Make sure that typo correction doesn't suggest changing 'p' to
// 'std::bernoulli_distribution::p' as that is most likely wrong.
if (p) // expected-error-re {{use of undeclared identifier 'p'{{$}}}}
return;
}
namespace PR19681 {
struct TypoA {};
struct TypoB {
void test();
private:
template<typename T> void private_memfn(T); // expected-note{{declared here}}
};
void TypoB::test() {
// FIXME: should suggest 'PR19681::TypoB::private_memfn' instead of '::PR19681::TypoB::private_memfn'
(void)static_cast<void(TypoB::*)(int)>(&TypoA::private_memfn); // expected-error{{no member named 'private_memfn' in 'PR19681::TypoA'; did you mean '::PR19681::TypoB::private_memfn'?}}
}
}
namespace testWantFunctionLikeCasts {
long test(bool a) {
if (a)
return struc(5.7); // expected-error-re {{use of undeclared identifier 'struc'{{$}}}}
else
return lon(8.0); // expected-error {{use of undeclared identifier 'lon'; did you mean 'long'?}}
}
}
namespace testCXXDeclarationSpecifierParsing {
namespace test {
struct SomeSettings {}; // expected-note {{'test::SomeSettings' declared here}}
}
class Test {};
int bar() {
Test::SomeSettings some_settings; // expected-error {{no type named 'SomeSettings' in 'testCXXDeclarationSpecifierParsing::Test'; did you mean 'test::SomeSettings'?}}
}
}
namespace testNonStaticMemberHandling {
struct Foo {
bool usesMetadata; // expected-note {{'usesMetadata' declared here}}
};
int test(Foo f) {
if (UsesMetadata) // expected-error-re {{use of undeclared identifier 'UsesMetadata'{{$}}}}
return 5;
if (f.UsesMetadata) // expected-error {{no member named 'UsesMetadata' in 'testNonStaticMemberHandling::Foo'; did you mean 'usesMetadata'?}}
return 11;
return 0;
}
};
namespace testMemberExprDeclarationNameInfo {
// The AST should only have the corrected name with no mention of 'data_'.
void f(int);
struct S {
int data; // expected-note 2{{'data' declared here}}
void m_fn1() {
data_ // expected-error {{use of undeclared identifier 'data_'}}
[] = // expected-error {{expected expression}}
f(data_); // expected-error {{use of undeclared identifier 'data_'}}
}
};
}
namespace testArraySubscriptIndex {
struct S {
int data; // expected-note {{'data' declared here}}
void m_fn1() {
(+)[data_]; // expected-error{{expected expression}} expected-error {{use of undeclared identifier 'data_'; did you mean 'data'}}
}
};
}
namespace crash_has_include {
int has_include(int); // expected-note {{'has_include' declared here}}
// expected-error@+1 {{__has_include must be used within a preprocessing directive}}
int foo = __has_include(42); // expected-error {{use of undeclared identifier '__has_include'; did you mean 'has_include'?}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/convert-to-bool.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct ConvToBool {
operator bool() const;
};
struct ConvToInt {
operator int();
};
struct ExplicitConvToBool {
explicit operator bool(); // expected-warning{{explicit conversion functions are a C++11 extension}}
};
void test_conv_to_bool(ConvToBool ctb, ConvToInt cti, ExplicitConvToBool ecb) {
if (ctb) { }
if (cti) { }
if (ecb) { }
for (; ctb; ) { }
for (; cti; ) { }
for (; ecb; ) { }
while (ctb) { };
while (cti) { }
while (ecb) { }
do { } while (ctb);
do { } while (cti);
do { } while (ecb);
if (!ctb) { }
if (!cti) { }
if (!ecb) { }
bool b1 = !ecb;
if (ctb && ecb) { }
bool b2 = ctb && ecb;
if (ctb || ecb) { }
bool b3 = ctb || ecb;
}
void accepts_bool(bool) { } // expected-note{{candidate function}}
struct ExplicitConvToRef {
explicit operator int&(); // expected-warning{{explicit conversion functions are a C++11 extension}}
};
void test_explicit_bool(ExplicitConvToBool ecb) {
bool b1(ecb); // okay
bool b2 = ecb; // expected-error{{no viable conversion from 'ExplicitConvToBool' to 'bool'}}
accepts_bool(ecb); // expected-error{{no matching function for call to}}
}
void test_explicit_conv_to_ref(ExplicitConvToRef ecr) {
int& i1 = ecr; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'ExplicitConvToRef'}}
int& i2(ecr); // okay
}
struct A { };
struct B { };
struct C {
explicit operator A&(); // expected-warning{{explicit conversion functions are a C++11 extension}}
operator B&(); // expected-note{{candidate}}
};
void test_copy_init_conversions(C c) {
A &a = c; // expected-error{{no viable conversion from 'C' to 'A'}}
B &b = c; // okay
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/short-wchar-sign.cpp
|
// RUN: %clang_cc1 -triple i386-mingw32 -fsyntax-only -pedantic -verify %s
// RUN: %clang_cc1 -fshort-wchar -fsyntax-only -pedantic -verify %s
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -pedantic -verify %s
// expected-no-diagnostics
// Check that short wchar_t is unsigned, and that regular wchar_t is not.
int test[(wchar_t(-1)<wchar_t(0)) == (sizeof(wchar_t) == 4) ?1:-1];
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/no-warn-unused-const-variables.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wno-unused-const-variable -verify %s
namespace {
int i = 0; // expected-warning {{unused variable 'i'}}
const int j = 0;;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/unreachable-catch-clauses.cpp
|
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
class BaseEx {};
class Ex1: public BaseEx {};
typedef Ex1 Ex2;
void f();
void test()
try {}
catch (BaseEx &e) { f(); } // expected-note 2{{for type 'BaseEx &'}}
catch (Ex1 &e) { f(); } // expected-warning {{exception of type 'Ex1 &' will be caught by earlier handler}}
catch (Ex2 &e) { f(); } // expected-warning {{exception of type 'Ex2 &' (aka 'Ex1 &') will be caught by earlier handler}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-consumed-parsing.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
#define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__)))
#define CONSUMABLE(state) __attribute__ ((consumable(state)))
#define SET_TYPESTATE(state) __attribute__ ((set_typestate(state)))
#define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
#define TEST_TYPESTATE(state) __attribute__ ((test_typestate(state)))
// FIXME: This test is here because the warning is issued by the Consumed
// analysis, not SemaDeclAttr. The analysis won't run after an error
// has been issued. Once the attribute propagation for template
// instantiation has been fixed, this can be moved somewhere else and the
// definition can be removed.
int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}
int returnTypestateForUnconsumable() {
return 0;
}
class AttrTester0 {
void consumes() __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}}
bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}}
void callableWhen() __attribute__ ((callable_when())); // expected-error {{'callable_when' attribute takes at least 1 argument}}
};
int var0 SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}}
int var1 TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to methods}}
int var2 CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to methods}}
int var3 CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}}
void function0() SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}}
void function1() TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to methods}}
void function2() CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to methods}}
void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
class CONSUMABLE(unknown) AttrTester1 {
void callableWhen0() CALLABLE_WHEN("unconsumed");
void callableWhen1() CALLABLE_WHEN(42); // expected-error {{'callable_when' attribute requires a string}}
void callableWhen2() CALLABLE_WHEN("foo"); // expected-warning {{'callable_when' attribute argument not supported: foo}}
void callableWhen3() CALLABLE_WHEN(unconsumed);
void consumes() SET_TYPESTATE(consumed);
bool testUnconsumed() TEST_TYPESTATE(consumed);
};
AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{'return_typestate' attribute argument not supported: 'not_a_state'}}
AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{'return_typestate' attribute requires an identifier}}
void returnTypestateTester2(AttrTester1 &Param RETURN_TYPESTATE(unconsumed));
class AttrTester2 {
void callableWhen() CALLABLE_WHEN("unconsumed"); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
void consumes() SET_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
bool testUnconsumed() TEST_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
};
class CONSUMABLE(42) AttrTester3; // expected-error {{'consumable' attribute requires an identifier}}
class CONSUMABLE(unconsumed)
__attribute__((consumable_auto_cast_state))
__attribute__((consumable_set_state_on_read))
Status {
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/self-comparison.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
int foo(int x) {
return x == x; // expected-warning {{self-comparison always evaluates to true}}
}
struct X {
bool operator==(const X &x);
};
struct A {
int x;
X x2;
int a[3];
int b[3];
bool f() { return x == x; } // expected-warning {{self-comparison always evaluates to true}}
bool g() { return x2 == x2; } // no-warning
bool h() { return a == b; } // expected-warning {{array comparison always evaluates to false}}
bool i() {
int c[3];
return a == c; // expected-warning {{array comparison always evaluates to false}}
}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-pointer-compare -fblocks -std=c++11 -verify %s
void foo() {
int a;
bool b;
a = 0 ? nullptr + a : a + nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr - a : a - nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr / a : a / nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr * a : a * nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr >> a : a >> nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr << a : a << nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr % a : a % nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr & a : a & nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr | a : a | nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr ^ a : a ^ nullptr; // expected-error 2{{invalid operands to binary expression}}
// Using two nullptrs should only give one error instead of two.
a = nullptr + nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr - nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr / nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr * nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr >> nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr << nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr % nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr & nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr | nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr ^ nullptr; // expected-error{{invalid operands to binary expression}}
a += nullptr; // expected-error{{invalid operands to binary expression}}
a -= nullptr; // expected-error{{invalid operands to binary expression}}
a /= nullptr; // expected-error{{invalid operands to binary expression}}
a *= nullptr; // expected-error{{invalid operands to binary expression}}
a >>= nullptr; // expected-error{{invalid operands to binary expression}}
a <<= nullptr; // expected-error{{invalid operands to binary expression}}
a %= nullptr; // expected-error{{invalid operands to binary expression}}
a &= nullptr; // expected-error{{invalid operands to binary expression}}
a |= nullptr; // expected-error{{invalid operands to binary expression}}
a ^= nullptr; // expected-error{{invalid operands to binary expression}}
b = a < nullptr || nullptr < a; // expected-error 2{{invalid operands to binary expression}}
b = a > nullptr || nullptr > a; // expected-error 2{{invalid operands to binary expression}}
b = a <= nullptr || nullptr <= a; // expected-error 2{{invalid operands to binary expression}}
b = a >= nullptr || nullptr >= a; // expected-error 2{{invalid operands to binary expression}}
b = a == nullptr || nullptr == a; // expected-error 2{{invalid operands to binary expression}}
b = a != nullptr || nullptr != a; // expected-error 2{{invalid operands to binary expression}}
b = &a < nullptr || nullptr < &a || &a > nullptr || nullptr > &a;
b = &a <= nullptr || nullptr <= &a || &a >= nullptr || nullptr >= &a;
b = &a == nullptr || nullptr == &a || &a != nullptr || nullptr != &a;
b = nullptr < nullptr || nullptr > nullptr;
b = nullptr <= nullptr || nullptr >= nullptr;
b = nullptr == nullptr || nullptr != nullptr;
b = ((nullptr)) != a; // expected-error{{invalid operands to binary expression}}
void (^c)();
c = nullptr;
b = c == nullptr || nullptr == c || c != nullptr || nullptr != c;
class X;
void (X::*d) ();
d = nullptr;
b = d == nullptr || nullptr == d || d != nullptr || nullptr != d;
extern void e();
b = e == nullptr || nullptr == e || e != nullptr || nullptr != e;
int f[2];
b = f == nullptr || nullptr == f || f != nullptr || nullptr != f;
b = "f" == nullptr || nullptr == "f" || "f" != nullptr || nullptr != "f";
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/rval-references.cpp
|
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
typedef int&& irr;
typedef irr& ilr_c1; // Collapses to int&
typedef int& ilr;
typedef ilr&& ilr_c2; // Collapses to int&
irr ret_irr() {
return 0; // expected-warning {{returning reference to local temporary}}
}
struct not_int {};
int over(int&);
not_int over(int&&);
int over2(const int&);
not_int over2(int&&);
struct conv_to_not_int_rvalue {
operator not_int &&();
};
typedef void (fun_type)();
void fun();
fun_type &&make_fun();
void f() {
int &&virr1; // expected-error {{declaration of reference variable 'virr1' requires an initializer}}
int &&virr2 = 0;
int &&virr3 = virr2; // expected-error {{rvalue reference to type 'int' cannot bind to lvalue of type 'int'}}
int i1 = 0;
int &&virr4 = i1; // expected-error {{rvalue reference to type 'int' cannot bind to lvalue of type 'int'}}
int &&virr5 = ret_irr();
int &&virr6 = static_cast<int&&>(i1);
(void)static_cast<not_int&&>(i1); // expected-error {{types are not compatible}}
int i2 = over(i1);
not_int ni1 = over(0);
int i3 = over(virr2);
not_int ni2 = over(ret_irr());
int i4 = over2(i1);
not_int ni3 = over2(0);
ilr_c1 vilr1 = i1;
ilr_c2 vilr2 = i1;
conv_to_not_int_rvalue cnir;
not_int &&ni4 = cnir;
not_int &ni5 = cnir; // expected-error{{non-const lvalue reference to type 'not_int' cannot bind to a value of unrelated type 'conv_to_not_int_rvalue'}}
not_int &&ni6 = conv_to_not_int_rvalue();
fun_type &&fun_ref = fun; // works because functions are special
fun_type &&fun_ref2 = make_fun(); // same
fun_type &fun_lref = make_fun(); // also special
try {
} catch(int&&) { // expected-error {{cannot catch exceptions by rvalue reference}}
}
}
int&& should_warn(int i) {
// FIXME: The stack address return test doesn't reason about casts.
return static_cast<int&&>(i); // xpected-warning {{returning reference to temporary}}
}
int&& should_not_warn(int&& i) { // But GCC 4.4 does
return static_cast<int&&>(i);
}
// Test the return dance. This also tests IsReturnCopyElidable.
struct MoveOnly {
MoveOnly();
MoveOnly(const MoveOnly&) = delete; // expected-note {{candidate constructor}} \
// expected-note 3{{explicitly marked deleted here}}
MoveOnly(MoveOnly&&); // expected-note {{candidate constructor}}
MoveOnly(int&&); // expected-note {{candidate constructor}}
};
MoveOnly gmo;
MoveOnly returningNonEligible() {
int i;
static MoveOnly mo;
MoveOnly &r = mo;
if (0) // Copy from global can't be elided
return gmo; // expected-error {{call to deleted constructor}}
else if (0) // Copy from local static can't be elided
return mo; // expected-error {{call to deleted constructor}}
else if (0) // Copy from reference can't be elided
return r; // expected-error {{call to deleted constructor}}
else // Construction from different type can't be elided
return i; // expected-error {{no viable conversion from 'int' to 'MoveOnly'}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/return-noreturn.cpp
|
// RUN: %clang_cc1 %s -fsyntax-only -fcxx-exceptions -verify -Wreturn-type -Wmissing-noreturn -Wno-unreachable-code -Wno-covered-switch-default
// RUN: %clang_cc1 %s -fsyntax-only -fcxx-exceptions -std=c++11 -verify -Wreturn-type -Wmissing-noreturn -Wno-unreachable-code -Wno-covered-switch-default
// A destructor may be marked noreturn and should still influence the CFG.
void pr6884_abort() __attribute__((noreturn));
struct pr6884_abort_struct {
pr6884_abort_struct() {}
~pr6884_abort_struct() __attribute__((noreturn)) { pr6884_abort(); }
};
struct other { ~other() {} };
// Ensure that destructors from objects are properly modeled in the CFG despite
// the presence of switches, case statements, labels, and blocks. These tests
// try to cover bugs reported in both PR6884 and PR10063.
namespace abort_struct_complex_cfgs {
int basic(int x) {
switch (x) { default: pr6884_abort(); }
}
int f1(int x) {
switch (x) default: pr6884_abort_struct();
}
int f2(int x) {
switch (x) { default: pr6884_abort_struct(); }
}
int f2_positive(int x) {
switch (x) { default: ; }
} // expected-warning {{control reaches end of non-void function}}
int f3(int x) {
switch (x) { default: { pr6884_abort_struct(); } }
}
int f4(int x) {
switch (x) default: L1: L2: case 4: pr6884_abort_struct();
}
int f5(int x) {
switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); }
}
int f6(int x) {
switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); }
}
// FIXME: detect noreturn destructors triggered by calls to delete.
int f7(int x) {
switch (x) default: L1: L2: case 4: {
pr6884_abort_struct *p = new pr6884_abort_struct();
delete p;
}
} // expected-warning {{control reaches end of non-void function}}
// Test that these constructs work even when extraneous blocks are created
// before and after the switch due to implicit destructors.
int g1(int x) {
other o;
switch (x) default: pr6884_abort_struct();
}
int g2(int x) {
other o;
switch (x) { default: pr6884_abort_struct(); }
}
int g2_positive(int x) {
other o;
switch (x) { default: ; }
} // expected-warning {{control reaches end of non-void function}}
int g3(int x) {
other o;
switch (x) { default: { pr6884_abort_struct(); } }
}
int g4(int x) {
other o;
switch (x) default: L1: L2: case 4: pr6884_abort_struct();
}
int g5(int x) {
other o;
switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); }
}
int g6(int x) {
other o;
switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); }
}
// Test that these constructs work even with variables carrying the no-return
// destructor instead of temporaries.
int h1(int x) {
other o;
switch (x) default: pr6884_abort_struct a;
}
int h2(int x) {
other o;
switch (x) { default: pr6884_abort_struct a; }
}
int h3(int x) {
other o;
switch (x) { default: { pr6884_abort_struct a; } }
}
int h4(int x) {
other o;
switch (x) default: L1: L2: case 4: pr6884_abort_struct a;
}
int h5(int x) {
other o;
switch (x) default: L1: { L2: case 4: pr6884_abort_struct a; }
}
int h6(int x) {
other o;
switch (x) default: L1: L2: case 4: { pr6884_abort_struct a; }
}
}
// PR9380
struct PR9380 {
~PR9380();
};
struct PR9380_B : public PR9380 {
PR9380_B( const PR9380& str );
};
void test_PR9380(const PR9380& aKey) {
const PR9380& flatKey = PR9380_B(aKey);
}
// Array of objects with destructors. This is purely a coverage test case.
void test_array() {
PR9380 a[2];
}
// Test classes wrapped in typedefs. This is purely a coverage test case
// for CFGImplictDtor::getDestructorDecl().
void test_typedefs() {
typedef PR9380 PR9380_Ty;
PR9380_Ty test;
PR9380_Ty test2[20];
}
// PR9412 - Handle CFG traversal with null successors.
enum PR9412_MatchType { PR9412_Exact };
template <PR9412_MatchType type> int PR9412_t() {
switch (type) {
case PR9412_Exact:
default:
break;
}
} // expected-warning {{control reaches end of non-void function}}
void PR9412_f() {
PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<PR9412_MatchType::PR9412_Exact>' requested here}}
}
struct NoReturn {
~NoReturn() __attribute__((noreturn));
operator bool() const;
};
struct Return {
~Return();
operator bool() const;
};
int testTernaryUnconditionalNoreturn() {
true ? NoReturn() : NoReturn();
}
int testTernaryStaticallyConditionalNoretrunOnTrue() {
true ? NoReturn() : Return();
}
int testTernaryStaticallyConditionalRetrunOnTrue() {
true ? Return() : NoReturn();
} // expected-warning {{control reaches end of non-void function}}
int testTernaryStaticallyConditionalNoretrunOnFalse() {
false ? Return() : NoReturn();
}
int testTernaryStaticallyConditionalRetrunOnFalse() {
false ? NoReturn() : Return();
} // expected-warning {{control reaches end of non-void function}}
int testTernaryConditionalNoreturnTrueBranch(bool value) {
value ? (NoReturn() || NoReturn()) : Return();
} // expected-warning {{control may reach end of non-void function}}
int testTernaryConditionalNoreturnFalseBranch(bool value) {
value ? Return() : (NoReturn() || NoReturn());
} // expected-warning {{control may reach end of non-void function}}
int testConditionallyExecutedComplexTernaryTrueBranch(bool value) {
value || (true ? NoReturn() : true);
} // expected-warning {{control may reach end of non-void function}}
int testConditionallyExecutedComplexTernaryFalseBranch(bool value) {
value || (false ? true : NoReturn());
} // expected-warning {{control may reach end of non-void function}}
int testStaticallyExecutedLogicalOrBranch() {
false || NoReturn();
}
int testStaticallyExecutedLogicalAndBranch() {
true && NoReturn();
}
int testStaticallySkippedLogicalOrBranch() {
true || NoReturn();
} // expected-warning {{control reaches end of non-void function}}
int testStaticallySkppedLogicalAndBranch() {
false && NoReturn();
} // expected-warning {{control reaches end of non-void function}}
int testConditionallyExecutedComplexLogicalBranch(bool value) {
value || (true && NoReturn());
} // expected-warning {{control may reach end of non-void function}}
int testConditionallyExecutedComplexLogicalBranch2(bool value) {
(true && value) || (true && NoReturn());
} // expected-warning {{control may reach end of non-void function}}
int testConditionallyExecutedComplexLogicalBranch3(bool value) {
(false && (Return() || true)) || (true && NoReturn());
}
int testConditionallyExecutedComplexLogicalBranch4(bool value) {
false || ((Return() || true) && (true && NoReturn()));
}
#if __cplusplus >= 201103L
namespace LambdaVsTemporaryDtor {
struct Y { ~Y(); };
struct X { template<typename T> X(T, Y = Y()) {} };
struct Fatal { ~Fatal() __attribute__((noreturn)); };
struct FatalCopy { FatalCopy(); FatalCopy(const FatalCopy&, Fatal F = Fatal()); };
void foo();
int bar() {
X work([](){ Fatal(); });
foo();
} // expected-warning {{control reaches end of non-void function}}
int baz() {
FatalCopy fc;
X work([fc](){});
foo();
} // ok, initialization of lambda does not return
}
#endif
// Ensure that function-try-blocks also check for return values properly.
int functionTryBlock1(int s) try {
return 0;
} catch (...) {
} // expected-warning {{control may reach end of non-void function}}
int functionTryBlock2(int s) try {
} catch (...) {
return 0;
} // expected-warning {{control may reach end of non-void function}}
int functionTryBlock3(int s) try {
return 0;
} catch (...) {
return 0;
} // ok, both paths return.
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/thread-safety-reference-handling.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety-analysis -std=c++11 %s
// expected-no-diagnostics
class Base {
public:
Base() {}
virtual ~Base();
};
class S : public Base {
public:
~S() override = default;
};
void Test() {
const S &s = S();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/deleted-operator.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
struct PR10757 {
bool operator~() = delete; // expected-note {{explicitly deleted}}
bool operator==(const PR10757&) = delete; // expected-note {{explicitly deleted}}
operator float();
};
int PR10757f() {
PR10757 a1;
// FIXME: We get a ridiculous number of "built-in candidate" notes here...
if(~a1) {} // expected-error {{overload resolution selected deleted operator}} expected-note 8 {{built-in candidate}}
if(a1==a1) {} // expected-error {{overload resolution selected deleted operator}} expected-note 121 {{built-in candidate}}
}
struct DelOpDel {
// FIXME: In MS ABI, we error twice below.
virtual ~DelOpDel() {} // expected-error 1-2 {{attempt to use a deleted function}}
void operator delete(void*) = delete; // expected-note 1-2 {{deleted here}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/old-style-cast.cpp
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify -Wold-style-cast %s
void test1() {
long x = (long)12; // expected-warning {{use of old-style cast}}
(long)x; // expected-warning {{use of old-style cast}} expected-warning {{expression result unused}}
(void**)x; // expected-warning {{use of old-style cast}} expected-warning {{expression result unused}}
long y = static_cast<long>(12);
(void)y;
typedef void VOID;
(VOID)y;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-thread-safety-negative.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-beta -Wthread-safety-negative -fcxx-exceptions %s
// FIXME: should also run %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++11 -Wc++98-compat %s
// FIXME: should also run %clang_cc1 -fsyntax-only -verify -Wthread-safety %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();
};
namespace SimpleTest {
class Bar {
Mutex mu;
int a GUARDED_BY(mu);
public:
void baz() EXCLUSIVE_LOCKS_REQUIRED(!mu) {
mu.Lock();
a = 0;
mu.Unlock();
}
};
class Foo {
Mutex mu;
int a GUARDED_BY(mu);
public:
void foo() {
mu.Lock(); // expected-warning {{acquiring mutex 'mu' requires negative capability '!mu'}}
baz(); // expected-warning {{cannot call function 'baz' while mutex 'mu' is held}}
bar();
mu.Unlock();
}
void bar() {
baz(); // expected-warning {{calling function 'baz' requires holding '!mu'}}
}
void baz() EXCLUSIVE_LOCKS_REQUIRED(!mu) {
mu.Lock();
a = 0;
mu.Unlock();
}
void test() {
Bar b;
b.baz(); // no warning -- in different class.
}
void test2() {
mu.Lock(); // expected-warning {{acquiring mutex 'mu' requires negative capability '!mu'}}
a = 0;
mu.Unlock();
baz(); // no warning -- !mu in set.
}
void test3() EXCLUSIVE_LOCKS_REQUIRED(!mu) {
mu.Lock();
a = 0;
mu.Unlock();
baz(); // no warning -- !mu in set.
}
};
} // end namespace SimpleTest
namespace DoubleAttribute {
struct Foo {
Mutex &mutex();
};
template <typename A>
class TemplateClass {
template <typename B>
static void Function(Foo *F)
EXCLUSIVE_LOCKS_REQUIRED(F->mutex()) UNLOCK_FUNCTION(F->mutex()) {}
};
void test() { TemplateClass<int> TC; }
} // end namespace DoubleAttribute
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/enum-increment.cpp
|
// RUN: %clang_cc1 -fsyntax-only %s -verify
enum A { A1, A2, A3 };
void test() {
A a;
a++; // expected-error{{cannot increment expression of enum type 'A'}}
a--; // expected-error{{cannot decrement expression of enum type 'A'}}
++a; // expected-error{{cannot increment expression of enum type 'A'}}
--a; // expected-error{{cannot decrement expression of enum type 'A'}}
}
enum B {B1, B2};
inline B &operator++ (B &b) { b = B((int)b+1); return b; }
inline B operator++ (B &b, int) { B ret = b; ++b; return b; }
void foo(enum B b) { ++b; b++; }
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/member-pointers-2.cpp
|
// RUN: %clang_cc1 -emit-llvm-only %s
// Tests that Sema properly creates member-access expressions for
// these instead of bare FieldDecls.
struct Foo {
int myvalue;
// We have to override these to get something with an lvalue result.
int &operator++(int);
int &operator--(int);
};
struct Test0 {
Foo memfoo;
int memint;
int memarr[10];
Test0 *memptr;
struct MemClass { int a; } memstruct;
int &memfun();
void test() {
int *p;
p = &Test0::memfoo++;
p = &Test0::memfoo--;
p = &Test0::memarr[1];
p = &Test0::memptr->memint;
p = &Test0::memstruct.a;
p = &Test0::memfun();
}
};
void test0() {
Test0 mytest;
mytest.test();
}
namespace rdar9065289 {
typedef void (*FuncPtr)();
struct X0 { };
struct X1
{
X0* x0;
FuncPtr X0::*fptr;
};
void f(X1 p) {
(p.x0->*(p.fptr))();
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-empty-body.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
void a(int i);
int b();
int c();
#define MACRO_A 0
void test1(int x, int y) {
while(true) {
if (x); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
// Check that we handle conditions that start or end with a macro
// correctly.
if (x == MACRO_A); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
if (MACRO_A == x); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
int i;
// PR11329
for (i = 0; i < x; i++); { // expected-warning{{for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
b();
}
for (i = 0; i < x; i++); // expected-warning{{for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
{
a(i);
}
for (i = 0;
i < x;
i++); // expected-warning{{for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
{
a(i);
}
int arr[3] = { 1, 2, 3 };
for (int j : arr); // expected-warning{{range-based for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
for (int j :
arr); // expected-warning{{range-based for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
while (b() == 0); // expected-warning{{while loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
while (b() == 0); { // expected-warning{{while loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
}
while (b() == 0); // expected-warning{{while loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
{
a(i);
}
while (b() == 0 ||
c() == 0); // expected-warning{{while loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
{
a(i);
}
do; // expected-note{{to match this 'do'}}
b(); // expected-error{{expected 'while' in do/while loop}}
while (b()); // no-warning
c();
do; // expected-note{{to match this 'do'}}
b(); // expected-error{{expected 'while' in do/while loop}}
while (b()); // expected-warning{{while loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
c();
switch(x) // no-warning
{
switch(y); // expected-warning{{switch statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
{
case 0:
a(10);
break;
default:
a(20);
break;
}
}
}
}
/// There should be no warning when null statement is placed on its own line.
void test2(int x, int y) {
if (x) // no-warning
; // no-warning
int i;
for (i = 0; i < x; i++) // no-warning
; // no-warning
for (i = 0;
i < x;
i++) // no-warning
; // no-warning
int arr[3] = { 1, 2, 3 };
for (int j : arr) // no-warning
; // no-warning
while (b() == 0) // no-warning
; // no-warning
while (b() == 0 ||
c() == 0) // no-warning
; // no-warning
switch(x)
{
switch(y) // no-warning
; // no-warning
}
// Last `for' or `while' statement in compound statement shouldn't warn.
while(b() == 0); // no-warning
}
/// There should be no warning for a null statement resulting from an empty macro.
#define EMPTY(a)
void test3(int x, int y) {
if (x) EMPTY(x); // no-warning
int i;
for (i = 0; i < x; i++) EMPTY(i); // no-warning
for (i = 0;
i < x;
i++) EMPTY(i); // no-warning
int arr[3] = { 1, 2, 3 };
for (int j : arr) EMPTY(j); // no-warning
for (int j :
arr) EMPTY(j); // no-warning
while (b() == 0) EMPTY(i); // no-warning
while (b() == 0 ||
c() == 0) EMPTY(i); // no-warning
switch (x) {
switch (y)
EMPTY(i); // no-warning
}
}
void test4(int x)
{
// Idiom used in some metaprogramming constructs.
switch (x) default:; // no-warning
// Frequent idiom used in macros.
do {} while (false); // no-warning
}
/// There should be no warning for a common for/while idiom when it is obvious
/// from indentation that next statement wasn't meant to be a body.
void test5(int x, int y) {
int i;
for (i = 0; i < x; i++); // expected-warning{{for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
for (i = 0; i < x; i++); // no-warning
a(i);
for (i = 0;
i < x;
i++); // expected-warning{{for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
for (i = 0;
i < x;
i++); // no-warning
a(i);
while (b() == 0); // expected-warning{{while loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
while (b() == 0); // no-warning
a(i);
while (b() == 0 ||
c() == 0); // expected-warning{{while loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(i);
while (b() == 0 ||
c() == 0); // no-warning
a(i);
}
/// There should be no warning for a statement with a non-null body.
void test6(int x, int y) {
if (x) {} // no-warning
if (x)
a(x); // no-warning
int i;
for (i = 0; i < x; i++) // no-warning
a(i); // no-warning
for (i = 0; i < x; i++) { // no-warning
a(i); // no-warning
}
for (i = 0;
i < x;
i++) // no-warning
a(i); // no-warning
int arr[3] = { 1, 2, 3 };
for (int j : arr) // no-warning
a(j);
for (int j : arr) {} // no-warning
while (b() == 0) // no-warning
a(i); // no-warning
while (b() == 0) {} // no-warning
switch(x) // no-warning
{
switch(y) // no-warning
{
case 0:
a(10);
break;
default:
a(20);
break;
}
}
}
void test_errors(int x) {
if (1)
aa; // expected-error{{use of undeclared identifier}}
// no empty body warning.
int i;
for (i = 0; i < x; i++)
bb; // expected-error{{use of undeclared identifier}}
int arr[3] = { 1, 2, 3 };
for (int j : arr)
cc; // expected-error{{use of undeclared identifier}}
while (b() == 0)
dd; // expected-error{{use of undeclared identifier}}
}
// Warnings for statements in templates shouldn't be duplicated for all
// instantiations.
template <typename T>
void test_template(int x) {
if (x); // expected-warning{{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
if (x)
EMPTY(x); // no-warning
int arr[3] = { 1, 2, 3 };
for (int j : arr); // expected-warning{{range-based for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
while (b() == 0); // expected-warning{{while loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
a(x);
}
void test_template_inst(int x) {
test_template<int>(x);
test_template<double>(x);
}
#define IDENTITY(a) a
void test7(int x, int y) {
if (x) IDENTITY(); // no-warning
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-optnone.cpp
|
// RUN: %clang_cc1 -std=c++11 -fms-compatibility -fsyntax-only -verify %s
int foo() __attribute__((optnone));
int bar() __attribute__((optnone)) __attribute__((noinline));
int baz() __attribute__((always_inline)) __attribute__((optnone)); // expected-warning{{'always_inline' attribute ignored}} expected-note{{conflicting attribute is here}}
int quz() __attribute__((optnone)) __attribute__((always_inline)); // expected-warning{{'always_inline' attribute ignored}} expected-note{{conflicting attribute is here}}
__attribute__((always_inline)) int baz1(); // expected-warning{{'always_inline' attribute ignored}}
__attribute__((optnone)) int baz1() { return 1; } // expected-note{{conflicting attribute is here}}
__attribute__((optnone)) int quz1(); // expected-note{{conflicting attribute is here}}
__attribute__((always_inline)) int quz1() { return 1; } // expected-warning{{'always_inline' attribute ignored}}
int bay() __attribute__((minsize)) __attribute__((optnone)); // expected-warning{{'minsize' attribute ignored}} expected-note{{conflicting}}
int quy() __attribute__((optnone)) __attribute__((minsize)); // expected-warning{{'minsize' attribute ignored}} expected-note{{conflicting}}
__attribute__((minsize)) int bay1(); // expected-warning{{'minsize' attribute ignored}}
__attribute__((optnone)) int bay1() { return 1; } // expected-note{{conflicting attribute is here}}
__attribute__((optnone)) int quy1(); // expected-note{{conflicting attribute is here}}
__attribute__((minsize)) int quy1() { return 1; } // expected-warning{{'minsize' attribute ignored}}
__attribute__((always_inline)) // expected-warning{{'always_inline' attribute ignored}}
__attribute__((minsize)) // expected-warning{{'minsize' attribute ignored}}
void bay2();
__attribute__((optnone)) // expected-note 2 {{conflicting}}
void bay2() {}
__forceinline __attribute__((optnone)) int bax(); // expected-warning{{'__forceinline' attribute ignored}} expected-note{{conflicting}}
__attribute__((optnone)) __forceinline int qux(); // expected-warning{{'__forceinline' attribute ignored}} expected-note{{conflicting}}
__forceinline int bax2(); // expected-warning{{'__forceinline' attribute ignored}}
__attribute__((optnone)) int bax2() { return 1; } // expected-note{{conflicting}}
__attribute__((optnone)) int qux2(); // expected-note{{conflicting}}
__forceinline int qux2() { return 1; } // expected-warning{{'__forceinline' attribute ignored}}
int globalVar __attribute__((optnone)); // expected-warning{{'optnone' attribute only applies to functions}}
int fubar(int __attribute__((optnone)), int); // expected-warning{{'optnone' attribute only applies to functions}}
struct A {
int aField __attribute__((optnone)); // expected-warning{{'optnone' attribute only applies to functions}}
};
struct B {
void foo() __attribute__((optnone));
static void bar() __attribute__((optnone));
};
// Verify that we can specify the [[clang::optnone]] syntax as well.
[[clang::optnone]]
int foo2();
[[clang::optnone]]
int bar2() __attribute__((noinline));
[[clang::optnone]] // expected-note {{conflicting}}
int baz2() __attribute__((always_inline)); // expected-warning{{'always_inline' attribute ignored}}
[[clang::optnone]] int globalVar2; //expected-warning{{'optnone' attribute only applies to functions}}
struct A2 {
[[clang::optnone]] int aField; // expected-warning{{'optnone' attribute only applies to functions}}
};
struct B2 {
[[clang::optnone]]
void foo();
[[clang::optnone]]
static void bar();
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-unreachable.cpp
|
// RUN: %clang_cc1 %s -fcxx-exceptions -fexceptions -fsyntax-only -verify -fblocks -std=c++11 -Wunreachable-code-aggressive -Wno-unused-value -Wno-tautological-compare
int &halt() __attribute__((noreturn));
int &live();
int dead();
int liveti() throw(int);
int (*livetip)() throw(int);
int test1() {
try {
live();
} catch (int i) {
live();
}
return 1;
}
void test2() {
try {
live();
} catch (int i) {
live();
}
try {
liveti();
} catch (int i) {
live();
}
try {
livetip();
} catch (int i) {
live();
}
throw 1;
dead(); // expected-warning {{will never be executed}}
}
void test3() {
halt()
--; // expected-warning {{will never be executed}}
// FIXME: The unreachable part is just the '?', but really all of this
// code is unreachable and shouldn't be separately reported.
halt() // expected-warning {{will never be executed}}
?
dead() : dead();
live(),
float
(halt()); // expected-warning {{will never be executed}}
}
void test4() {
struct S {
int mem;
} s;
S &foor();
halt(), foor()// expected-warning {{will never be executed}}
.mem;
}
void test5() {
struct S {
int mem;
} s;
S &foonr() __attribute__((noreturn));
foonr()
.mem; // expected-warning {{will never be executed}}
}
void test6() {
struct S {
~S() { }
S(int i) { }
};
live(),
S
(halt()); // expected-warning {{will never be executed}}
}
// Don't warn about unreachable code in template instantiations, as
// they may only be unreachable in that specific instantiation.
void isUnreachable();
template <typename T> void test_unreachable_templates() {
T::foo();
isUnreachable(); // no-warning
}
struct TestUnreachableA {
static void foo() __attribute__((noreturn));
};
struct TestUnreachableB {
static void foo();
};
void test_unreachable_templates_harness() {
test_unreachable_templates<TestUnreachableA>();
test_unreachable_templates<TestUnreachableB>();
}
// Do warn about explict template specializations, as they represent
// actual concrete functions that somebody wrote.
template <typename T> void funcToSpecialize() {}
template <> void funcToSpecialize<int>() {
halt();
dead(); // expected-warning {{will never be executed}}
}
// Handle 'try' code dominating a dead return.
enum PR19040_test_return_t
{ PR19040_TEST_FAILURE };
namespace PR19040_libtest
{
class A {
public:
~A ();
};
}
PR19040_test_return_t PR19040_fn1 ()
{
try
{
throw PR19040_libtest::A ();
} catch (...)
{
return PR19040_TEST_FAILURE;
}
return PR19040_TEST_FAILURE; // expected-warning {{will never be executed}}
}
__attribute__((noreturn))
void raze();
namespace std {
template<typename T> struct basic_string {
basic_string(const T* x) {}
~basic_string() {};
};
typedef basic_string<char> string;
}
std::string testStr() {
raze();
return ""; // expected-warning {{'return' will never be executed}}
}
std::string testStrWarn(const char *s) {
raze();
return s; // expected-warning {{will never be executed}}
}
bool testBool() {
raze();
return true; // expected-warning {{'return' will never be executed}}
}
static const bool ConditionVar = 1;
int test_global_as_conditionVariable() {
if (ConditionVar)
return 1;
return 0; // no-warning
}
// Handle unreachable temporary destructors.
class A {
public:
A();
~A();
};
__attribute__((noreturn))
void raze(const A& x);
void test_with_unreachable_tmp_dtors(int x) {
raze(x ? A() : A()); // no-warning
}
// Test sizeof - sizeof in enum declaration.
enum { BrownCow = sizeof(long) - sizeof(char) };
enum { CowBrown = 8 - 1 };
int test_enum_sizeof_arithmetic() {
if (BrownCow)
return 1;
return 2;
}
int test_enum_arithmetic() {
if (CowBrown)
return 1;
return 2; // expected-warning {{never be executed}}
}
int test_arithmetic() {
if (8 -1)
return 1;
return 2; // expected-warning {{never be executed}}
}
int test_treat_const_bool_local_as_config_value() {
const bool controlValue = false;
if (!controlValue)
return 1;
test_treat_const_bool_local_as_config_value(); // no-warning
return 0;
}
int test_treat_non_const_bool_local_as_non_config_value() {
bool controlValue = false;
if (!controlValue)
return 1;
// There is no warning here because 'controlValue' isn't really
// a control value at all. The CFG will not treat this
// branch as unreachable.
test_treat_non_const_bool_local_as_non_config_value(); // no-warning
return 0;
}
void test_do_while(int x) {
// Handle trivial expressions with
// implicit casts to bool.
do {
break;
} while (0); // no-warning
}
class Frobozz {
public:
Frobozz(int x);
~Frobozz();
};
Frobozz test_return_object(int flag) {
return Frobozz(flag);
return Frobozz(42); // expected-warning {{'return' will never be executed}}
}
Frobozz test_return_object_control_flow(int flag) {
return Frobozz(flag);
return Frobozz(flag ? 42 : 24); // expected-warning {{code will never be executed}}
}
void somethingToCall();
static constexpr bool isConstExprConfigValue() { return true; }
int test_const_expr_config_value() {
if (isConstExprConfigValue()) {
somethingToCall();
return 0;
}
somethingToCall(); // no-warning
return 1;
}
int test_const_expr_config_value_2() {
if (!isConstExprConfigValue()) {
somethingToCall(); // no-warning
return 0;
}
somethingToCall();
return 1;
}
class Frodo {
public:
static const bool aHobbit = true;
};
void test_static_class_var() {
if (Frodo::aHobbit)
somethingToCall();
else
somethingToCall(); // no-warning
}
void test_static_class_var(Frodo &F) {
if (F.aHobbit)
somethingToCall();
else
somethingToCall(); // no-warning
}
void test_unreachable_for_null_increment() {
for (unsigned i = 0; i < 10 ; ) // no-warning
break;
}
void test_unreachable_forrange_increment() {
int x[10] = { 0 };
for (auto i : x) { // expected-warning {{loop will run at most once (loop increment never executed)}}
break;
}
}
void calledFun() {}
// Test "silencing" with parentheses.
void test_with_paren_silencing(int x) {
if (false) calledFun(); // expected-warning {{will never be executed}} expected-note {{silence by adding parentheses to mark code as explicitly dead}}
if ((false)) calledFun(); // no-warning
if (true) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
calledFun();
else
calledFun(); // expected-warning {{will never be executed}}
if ((true))
calledFun();
else
calledFun(); // no-warning
if (!true) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
calledFun(); // expected-warning {{code will never be executed}}
else
calledFun();
if ((!true))
calledFun(); // no-warning
else
calledFun();
if (!(true))
calledFun(); // no-warning
else
calledFun();
}
void test_with_paren_silencing_impcast(int x) {
if (0) calledFun(); // expected-warning {{will never be executed}} expected-note {{silence by adding parentheses to mark code as explicitly dead}}
if ((0)) calledFun(); // no-warning
if (1) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
calledFun();
else
calledFun(); // expected-warning {{will never be executed}}
if ((1))
calledFun();
else
calledFun(); // no-warning
if (!1) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
calledFun(); // expected-warning {{code will never be executed}}
else
calledFun();
if ((!1))
calledFun(); // no-warning
else
calledFun();
if (!(1))
calledFun(); // no-warning
else
calledFun();
}
void tautological_compare(bool x, int y) {
if (x > 10) // expected-note {{silence}}
calledFun(); // expected-warning {{will never be executed}}
if (10 < x) // expected-note {{silence}}
calledFun(); // expected-warning {{will never be executed}}
if (x == 10) // expected-note {{silence}}
calledFun(); // expected-warning {{will never be executed}}
if (x < 10) // expected-note {{silence}}
calledFun();
else
calledFun(); // expected-warning {{will never be executed}}
if (10 > x) // expected-note {{silence}}
calledFun();
else
calledFun(); // expected-warning {{will never be executed}}
if (x != 10) // expected-note {{silence}}
calledFun();
else
calledFun(); // expected-warning {{will never be executed}}
if (y != 5 && y == 5) // expected-note {{silence}}
calledFun(); // expected-warning {{will never be executed}}
if (y > 5 && y < 4) // expected-note {{silence}}
calledFun(); // expected-warning {{will never be executed}}
if (y < 10 || y > 5) // expected-note {{silence}}
calledFun();
else
calledFun(); // expected-warning {{will never be executed}}
// TODO: Extend warning to the following code:
if (x < -1)
calledFun();
if (x == -1)
calledFun();
if (x != -1)
calledFun();
else
calledFun();
if (-1 > x)
calledFun();
else
calledFun();
if (y == -1 && y != -1)
calledFun();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/nullptr-98.cpp
|
// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s
// expected-no-diagnostics
void f(void *);
void g() { f(__nullptr); }
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/member-init.cpp
|
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall %s
struct Bitfield {
int n : 3 = 7; // expected-error {{bitfield member cannot have an in-class initializer}}
};
int a;
class NoWarning {
int &n = a;
public:
int &GetN() { return n; }
};
bool b();
int k;
struct Recurse {
int &n = // expected-error {{cannot use defaulted default constructor of 'Recurse' within the class outside of member functions because 'n' has an initializer}}
b() ?
Recurse().n : // expected-note {{implicit default constructor for 'Recurse' first required here}}
k;
};
struct UnknownBound {
int as[] = { 1, 2, 3 }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
int bs[4] = { 4, 5, 6, 7 };
int cs[] = { 8, 9, 10 }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
};
template<int n> struct T { static const int B; };
template<> struct T<2> { template<int C, int D> using B = int; };
const int C = 0, D = 0;
struct S {
int as[] = { decltype(x)::B<C, D>(0) }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
T<sizeof(as) / sizeof(int)> x;
// test that we handle invalid array bound deductions without crashing when the declarator name is itself invalid
operator int[](){}; // expected-error {{'operator int' cannot be the name of a variable or data member}} \
// expected-error {{array bound cannot be deduced from an in-class initializer}}
};
struct ThrowCtor { ThrowCtor(int) noexcept(false); };
struct NoThrowCtor { NoThrowCtor(int) noexcept(true); };
struct Throw { ThrowCtor tc = 42; };
struct NoThrow { NoThrowCtor tc = 42; };
static_assert(!noexcept(Throw()), "incorrect exception specification");
static_assert(noexcept(NoThrow()), "incorrect exception specification");
struct CheckExcSpec {
CheckExcSpec() noexcept(true) = default;
int n = 0;
};
struct CheckExcSpecFail {
CheckExcSpecFail() noexcept(true) = default; // expected-error {{exception specification of explicitly defaulted default constructor does not match the calculated one}}
ThrowCtor tc = 123;
};
struct TypedefInit {
typedef int A = 0; // expected-error {{illegal initializer}}
};
// PR10578 / <rdar://problem/9877267>
namespace PR10578 {
template<typename T>
struct X {
X() {
T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
}
};
struct Y : X<int> {
Y();
};
Y::Y() try { // expected-note{{in instantiation of member function 'PR10578::X<int>::X' requested here}}
} catch(...) {
}
}
namespace PR14838 {
struct base { ~base() {} };
class function : base {
~function() {} // expected-note {{implicitly declared private here}}
public:
function(...) {}
};
struct thing {};
struct another {
another() : r(thing()) {}
// expected-error@-1 {{temporary of type 'const PR14838::function' has private destructor}}
// expected-warning@-2 {{binding reference member 'r' to a temporary value}}
const function &r; // expected-note {{reference member declared here}}
} af;
}
namespace rdar14084171 {
struct Point { // expected-note 3 {{candidate constructor}}
double x;
double y;
};
struct Sprite {
Point location = Point(0,0); // expected-error {{no matching constructor for initialization of 'rdar14084171::Point'}}
};
void f(Sprite& x) { x = x; }
}
namespace PR18560 {
struct X { int m; };
template<typename T = X,
typename U = decltype(T::m)>
int f();
struct Y { int b = f(); };
}
namespace template_valid {
// Valid, we shouldn't build a CXXDefaultInitExpr until A's ctor definition.
struct A {
A();
template <typename T>
struct B { int m1 = sizeof(A) + sizeof(T); };
B<int> m2;
};
A::A() {}
}
namespace template_default_ctor {
struct A {
template <typename T>
struct B {
int m1 = 0; // expected-error {{cannot use defaulted default constructor of 'B' within 'A' outside of member functions because 'm1' has an initializer}}
};
// expected-note@+1 {{implicit default constructor for 'template_default_ctor::A::B<int>' first required here}}
enum { NOE = noexcept(B<int>()) };
};
}
namespace default_ctor {
struct A {
struct B {
int m1 = 0; // expected-error {{cannot use defaulted default constructor of 'B' within 'A' outside of member functions because 'm1' has an initializer}}
};
// expected-note@+1 {{implicit default constructor for 'default_ctor::A::B' first required here}}
enum { NOE = noexcept(B()) };
};
}
namespace member_template {
struct A {
template <typename T>
struct B {
struct C {
int m1 = 0; // expected-error {{cannot use defaulted default constructor of 'C' within 'A' outside of member functions because 'm1' has an initializer}}
};
template <typename U>
struct D {
int m1 = 0; // expected-error {{cannot use defaulted default constructor of 'D' within 'A' outside of member functions because 'm1' has an initializer}}
};
};
enum {
// expected-note@+1 {{implicit default constructor for 'member_template::A::B<int>::C' first required here}}
NOE1 = noexcept(B<int>::C()),
// expected-note@+1 {{implicit default constructor for 'member_template::A::B<int>::D<int>' first required here}}
NOE2 = noexcept(B<int>::D<int>())
};
};
}
namespace explicit_instantiation {
template<typename T> struct X {
X(); // expected-note {{in instantiation of default member initializer 'explicit_instantiation::X<float>::n' requested here}}
int n = T::error; // expected-error {{type 'float' cannot be used prior to '::' because it has no members}}
};
template struct X<int>; // ok
template<typename T> X<T>::X() {}
template struct X<float>; // expected-note {{in instantiation of member function 'explicit_instantiation::X<float>::X' requested here}}
}
namespace local_class {
template<typename T> void f() {
struct X { // expected-note {{in instantiation of default member initializer 'local_class::f()::X::n' requested here}}
int n = T::error; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
};
}
void g() { f<int>(); } // expected-note {{in instantiation of function template specialization 'local_class::f<int>' requested here}}
}
namespace PR22056 {
template <int N>
struct S {
int x[3] = {[N] = 3};
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/offsetof.cpp
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s -Winvalid-offsetof
struct NonPOD {
virtual void f();
int m;
};
struct P {
NonPOD fieldThatPointsToANonPODType;
};
void f() {
int i = __builtin_offsetof(P, fieldThatPointsToANonPODType.m); // expected-warning{{offset of on non-POD type 'P'}}
}
struct Base { int x; };
struct Derived : Base { int y; };
int o = __builtin_offsetof(Derived, x); // expected-warning{{offset of on non-POD type}}
const int o2 = sizeof(__builtin_offsetof(Derived, x));
struct HasArray {
int array[17];
};
// Constant and non-constant offsetof expressions
void test_ice(int i) {
int array0[__builtin_offsetof(HasArray, array[5])];
int array1[__builtin_offsetof(HasArray, array[i])];
}
// Bitfields
struct has_bitfields {
int i : 7;
int j : 12; // expected-note{{bit-field is declared here}}
};
int test3 = __builtin_offsetof(struct has_bitfields, j); // expected-error{{cannot compute offset of bit-field 'j'}}
// offsetof referring to members of a base class.
struct Base1 {
int x;
};
struct Base2 {
int y;
};
struct Derived2 : public Base1, public Base2 {
int z;
};
int derived1[__builtin_offsetof(Derived2, x) == 0? 1 : -1];
int derived2[__builtin_offsetof(Derived2, y) == 4? 1 : -1];
int derived3[__builtin_offsetof(Derived2, z) == 8? 1 : -1];
// offsetof referring to anonymous struct in base.
// PR7769
struct foo {
struct {
int x;
};
};
struct bar : public foo {
};
int anonstruct[__builtin_offsetof(bar, x) == 0 ? 1 : -1];
struct LtoRCheck {
int a[10];
int f();
};
int ltor = __builtin_offsetof(struct LtoRCheck, a[LtoRCheck().f]); // \
expected-error {{reference to non-static member function must be called}}
namespace PR17578 {
struct Base {
int Field;
};
struct Derived : virtual Base {
void Fun() { (void)__builtin_offsetof(Derived, Field); } // expected-warning {{offset of on non-POD type}} \
expected-error {{invalid application of 'offsetof' to a field of a virtual base}}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/switch-0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// PR5518
struct A {
explicit operator int(); // expected-note{{conversion to integral type}}
};
void x() {
switch(A()) { // expected-error{{explicit conversion to}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/converting-constructor.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class Z { };
class Y {
public:
Y(const Z&);
};
class X {
public:
X(int);
X(const Y&);
};
void f(X); // expected-note{{candidate function}}
void g(short s, Y y, Z z) {
f(s);
f(1.0f);
f(y);
f(z); // expected-error{{no matching function}}
}
class FromShort {
public:
FromShort(short s);
};
class FromShortExplicitly { // expected-note{{candidate constructor (the implicit copy constructor)}}
public:
explicit FromShortExplicitly(short s);
};
void explicit_constructor(short s) {
FromShort fs1(s);
FromShort fs2 = s;
FromShortExplicitly fse1(s);
FromShortExplicitly fse2 = s; // expected-error{{no viable conversion}}
}
// PR5519
struct X1 { X1(const char&); };
void x1(X1);
void y1() {
x1(1);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR11358.cpp
|
// RUN: %clang_cc1 %s -verify
// PR11358
namespace test1 {
template<typename T>
struct container {
class iterator {};
iterator begin() { return iterator(); }
};
template<typename T>
struct Test {
typedef container<T> Container;
void test() {
Container::iterator i = c.begin(); // expected-error{{missing 'typename'}}
}
Container c;
};
}
namespace test2 {
template <typename Key, typename Value>
class hash_map {
class const_iterator { void operator++(); };
const_iterator begin() const;
const_iterator end() const;
};
template <typename KeyType, typename ValueType>
void MapTest(hash_map<KeyType, ValueType> map) {
for (hash_map<KeyType, ValueType>::const_iterator it = map.begin(); // expected-error{{missing 'typename'}}
it != map.end(); it++) {
}
}
}
namespace test3 {
template<typename T>
struct container {
class iterator {};
};
template<typename T>
struct Test {
typedef container<T> Container;
void test() {
Container::iterator const i; // expected-error{{missing 'typename'}}
}
Container c;
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/defaulted-ctor-loop.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// WARNING: This test may recurse infinitely if failing.
struct foo;
struct bar {
bar(foo&);
};
struct foo {
bar b;
foo()
: b(b) // expected-warning{{field 'b' is uninitialized}}
{}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-func-not-needed.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
namespace test1 {
static void f() {} // expected-warning {{is not needed and will not be emitted}}
static void f();
template <typename T>
void foo() {
f();
}
}
namespace test2 {
static void f() {}
static void f();
static void g() { f(); }
void h() { g(); }
}
namespace test3 {
static void f();
template<typename T>
static void g() {
f();
}
static void f() {
}
void h() {
g<int>();
}
}
namespace test4 {
static void f();
static void f();
template<typename T>
static void g() {
f();
}
static void f() {
}
void h() {
g<int>();
}
}
namespace test4 {
static void func();
void bar() {
void func();
func();
}
static void func() {}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-pessmizing-move.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wpessimizing-move -std=c++11 -verify %s
// RUN: %clang_cc1 -fsyntax-only -Wpessimizing-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
// definitions for std::move
namespace std {
inline namespace foo {
template <class T> struct remove_reference { typedef T type; };
template <class T> struct remove_reference<T&> { typedef T type; };
template <class T> struct remove_reference<T&&> { typedef T type; };
template <class T> typename remove_reference<T>::type &&move(T &&t);
}
}
struct A {};
struct B {
B() {}
B(A) {}
};
A test1(A a1) {
A a2;
return a1;
return a2;
return std::move(a1);
return std::move(a2);
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:23}:""
}
B test2(A a1, B b1) {
// Object is different than return type so don't warn.
A a2;
return a1;
return a2;
return std::move(a1);
return std::move(a2);
B b2;
return b1;
return b2;
return std::move(b1);
return std::move(b2);
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:23}:""
}
A global_a;
A test3() {
// Don't warn when object is not local.
return global_a;
return std::move(global_a);
static A static_a;
return static_a;
return std::move(static_a);
}
A test4() {
return A();
return test3();
return std::move(A());
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:""
return std::move(test3());
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:27-[[@LINE-4]]:28}:""
}
void test5(A) {
test5(A());
test5(test4());
test5(std::move(A()));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:19}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:23}:""
test5(std::move(test4()));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:19}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:26-[[@LINE-4]]:27}:""
}
void test6() {
A a1 = A();
A a2 = test3();
A a3 = std::move(A());
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:""
A a4 = std::move(test3());
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:27-[[@LINE-4]]:28}:""
}
A test7() {
A a1 = std::move(A());
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:""
A a2 = std::move((A()));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:25-[[@LINE-4]]:26}:""
A a3 = (std::move(A()));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:21}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:25}:""
A a4 = (std::move((A())));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:21}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:26-[[@LINE-4]]:27}:""
return std::move(a1);
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:23}:""
return std::move((a1));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:25}:""
return (std::move(a1));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:21}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:""
return (std::move((a1)));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:21}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:25-[[@LINE-4]]:26}:""
}
#define wrap1(x) x
#define wrap2(x) x
// Macro test. Since the std::move call is outside the macro, it is
// safe to suggest a fix-it.
A test8() {
A a;
return std::move(a);
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]:22}:""
return std::move(wrap1(a));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:28-[[@LINE-4]]:29}:""
return std::move(wrap1(wrap2(a)));
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:35-[[@LINE-4]]:36}:""
}
#define test9 \
A test9() { \
A a; \
return std::move(a); \
}
// Macro test. The std::call is inside the macro, so no fix-it is suggested.
test9
// expected-warning@-1{{prevents copy elision}}
// CHECK-NOT: fix-it
#define return_a return std::move(a)
// Macro test. The std::call is inside the macro, so no fix-it is suggested.
A test10() {
A a;
return_a;
// expected-warning@-1{{prevents copy elision}}
// CHECK-NOT: fix-it
}
namespace templates {
struct A {};
struct B { B(A); };
// Warn once here since the type is not dependent.
template <typename T>
A test1() {
A a;
return std::move(a);
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:22}:""
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:""
}
void run_test1() {
test1<A>();
test1<B>();
}
// T1 and T2 may not be the same, the warning may not always apply.
template <typename T1, typename T2>
T1 test2() {
T2 t;
return std::move(t);
}
void run_test2() {
test2<A, A>();
test2<B, A>();
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR12481.cpp
|
// RUN: %clang_cc1 -x c++ -fsyntax-only %s
class C1 { };
class C2 { };
template<class TrieData> struct BinaryTrie {
~BinaryTrie() {
(void)(({
static int x = 5;
}
));
}
};
class FooTable {
BinaryTrie<C1> c1_trie_;
BinaryTrie<C2> c2_trie_;
};
FooTable* foo = new FooTable;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR9460.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// Don't crash.
template<typename aT>
struct basic_string{
a; // expected-error {{requires a type specifier}}
basic_string(aT*);
};
struct runtime_error{
runtime_error(
basic_string<char> struct{ // expected-error {{cannot combine with previous 'type-name' declaration specifier}}
a(){ // expected-error {{requires a type specifier}}
runtime_error(0);
}
}
);
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/no-warn-composite-pointer-type.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wno-compare-distinct-pointer-types -verify %s
// expected-no-diagnostics
// rdar://12501960
void Foo(int **thing, const int **thingMax)
{
if ((thing + 3) > thingMax)
return;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/vararg-non-pod.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs
// Check that the warning is still there under -fms-compatibility.
// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs -fms-compatibility
extern char version[];
class C {
public:
C(int);
void g(int a, ...);
static void h(int a, ...);
};
void g(int a, ...);
void t1()
{
C c(10);
g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
g(10, version);
void (*ptr)(int, ...) = g;
ptr(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
ptr(10, version);
}
void t2()
{
C c(10);
c.g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
c.g(10, version);
void (C::*ptr)(int, ...) = &C::g;
(c.*ptr)(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
(c.*ptr)(10, version);
C::h(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
C::h(10, version);
void (*static_ptr)(int, ...) = &C::h;
static_ptr(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
static_ptr(10, version);
}
int (^block)(int, ...);
void t3()
{
C c(10);
block(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
block(10, version);
}
class D {
public:
void operator() (int a, ...);
};
void t4()
{
C c(10);
D d;
d(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
d(10, version);
}
class E {
E(int, ...); // expected-note 2{{implicitly declared private here}}
};
void t5()
{
C c(10);
E e(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} \
// expected-error{{calling a private constructor of class 'E'}}
(void)E(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} \
// expected-error{{calling a private constructor of class 'E'}}
}
// PR5761: unevaluated operands and the non-POD warning
class Foo {
public:
Foo() {}
};
int Helper(...);
const int size = sizeof(Helper(Foo()));
namespace std {
class type_info { };
}
struct Base { virtual ~Base(); };
Base &get_base(...);
int eat_base(...);
void test_typeid(Base &base) {
(void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}} expected-warning{{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
(void)typeid(eat_base(base)); // okay
}
// rdar://7985267 - Shouldn't warn, doesn't actually use __builtin_va_start is
// magic.
void t6(Foo somearg, ... ) {
__builtin_va_list list;
__builtin_va_start(list, somearg);
}
void t7(int n, ...) {
__builtin_va_list list;
__builtin_va_start(list, n);
(void)__builtin_va_arg(list, C); // expected-warning{{second argument to 'va_arg' is of non-POD type 'C'}}
__builtin_va_end(list);
}
struct Abstract {
virtual void doit() = 0; // expected-note{{unimplemented pure virtual method}}
};
void t8(int n, ...) {
__builtin_va_list list;
__builtin_va_start(list, n);
(void)__builtin_va_arg(list, Abstract); // expected-error{{second argument to 'va_arg' is of abstract type 'Abstract'}}
__builtin_va_end(list);
}
int t9(int n) {
// Make sure the error works in potentially-evaluated sizeof
return (int)sizeof(*(Helper(Foo()), (int (*)[n])0)); // expected-warning{{cannot pass object of non-POD type}}
}
// PR14057
namespace t10 {
struct F {
F();
};
struct S {
void operator()(F, ...);
};
void foo() {
S s;
F f;
s.operator()(f);
s(f);
}
}
namespace t11 {
typedef void(*function_ptr)(int, ...);
typedef void(C::*member_ptr)(int, ...);
typedef void(^block_ptr)(int, ...);
function_ptr get_f_ptr();
member_ptr get_m_ptr();
block_ptr get_b_ptr();
function_ptr arr_f_ptr[5];
member_ptr arr_m_ptr[5];
block_ptr arr_b_ptr[5];
void test() {
C c(10);
(get_f_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
(get_f_ptr())(10, version);
(c.*get_m_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
(c.*get_m_ptr())(10, version);
(get_b_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
(get_b_ptr())(10, version);
(arr_f_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
(arr_f_ptr[3])(10, version);
(c.*arr_m_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
(c.*arr_m_ptr[3])(10, version);
(arr_b_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
(arr_b_ptr[3])(10, version);
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/constant-expression-cxx11.cpp
|
// RUN: %clang_cc1 -triple i686-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -fsyntax-only -fcxx-exceptions -verify -std=c++11 -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
namespace StaticAssertFoldTest {
int x;
static_assert(++x, "test"); // expected-error {{not an integral constant expression}}
static_assert(false, "test"); // expected-error {{test}}
}
typedef decltype(sizeof(char)) size_t;
template<typename T> constexpr T id(const T &t) { return t; }
template<typename T> constexpr T min(const T &a, const T &b) {
return a < b ? a : b;
}
template<typename T> constexpr T max(const T &a, const T &b) {
return a < b ? b : a;
}
template<typename T, size_t N> constexpr T *begin(T (&xs)[N]) { return xs; }
template<typename T, size_t N> constexpr T *end(T (&xs)[N]) { return xs + N; }
struct MemberZero {
constexpr int zero() const { return 0; }
};
namespace DerivedToVBaseCast {
struct U { int n; };
struct V : U { int n; };
struct A : virtual V { int n; };
struct Aa { int n; };
struct B : virtual A, Aa {};
struct C : virtual A, Aa {};
struct D : B, C {};
D d;
constexpr B *p = &d;
constexpr C *q = &d;
static_assert((void*)p != (void*)q, "");
static_assert((A*)p == (A*)q, "");
static_assert((Aa*)p != (Aa*)q, "");
constexpr B &pp = d;
constexpr C &qq = d;
static_assert((void*)&pp != (void*)&qq, "");
static_assert(&(A&)pp == &(A&)qq, "");
static_assert(&(Aa&)pp != &(Aa&)qq, "");
constexpr V *v = p;
constexpr V *w = q;
constexpr V *x = (A*)p;
static_assert(v == w, "");
static_assert(v == x, "");
static_assert((U*)&d == p, "");
static_assert((U*)&d == q, "");
static_assert((U*)&d == v, "");
static_assert((U*)&d == w, "");
static_assert((U*)&d == x, "");
struct X {};
struct Y1 : virtual X {};
struct Y2 : X {};
struct Z : Y1, Y2 {};
Z z;
static_assert((X*)(Y1*)&z != (X*)(Y2*)&z, "");
}
namespace ConstCast {
constexpr int n1 = 0;
constexpr int n2 = const_cast<int&>(n1);
constexpr int *n3 = const_cast<int*>(&n1);
constexpr int n4 = *const_cast<int*>(&n1);
constexpr const int * const *n5 = const_cast<const int* const*>(&n3);
constexpr int **n6 = const_cast<int**>(&n3);
constexpr int n7 = **n5;
constexpr int n8 = **n6;
// const_cast from prvalue to xvalue.
struct A { int n; };
constexpr int n9 = (const_cast<A&&>(A{123})).n;
static_assert(n9 == 123, "");
}
namespace TemplateArgumentConversion {
template<int n> struct IntParam {};
using IntParam0 = IntParam<0>;
using IntParam0 = IntParam<id(0)>;
using IntParam0 = IntParam<MemberZero().zero>; // expected-error {{did you mean to call it with no arguments?}}
}
namespace CaseStatements {
int x;
void f(int n) {
switch (n) {
case MemberZero().zero: // expected-error {{did you mean to call it with no arguments?}} expected-note {{previous}}
case id(0): // expected-error {{duplicate case value '0'}}
return;
case __builtin_constant_p(true) ? (__SIZE_TYPE__)&x : 0:; // expected-error {{constant}}
}
}
}
extern int &Recurse1;
int &Recurse2 = Recurse1; // expected-note {{declared here}}
int &Recurse1 = Recurse2;
constexpr int &Recurse3 = Recurse2; // expected-error {{must be initialized by a constant expression}} expected-note {{initializer of 'Recurse2' is not a constant expression}}
extern const int RecurseA;
const int RecurseB = RecurseA; // expected-note {{declared here}}
const int RecurseA = 10;
constexpr int RecurseC = RecurseB; // expected-error {{must be initialized by a constant expression}} expected-note {{initializer of 'RecurseB' is not a constant expression}}
namespace MemberEnum {
struct WithMemberEnum {
enum E { A = 42 };
} wme;
static_assert(wme.A == 42, "");
}
namespace DefaultArguments {
const int z = int();
constexpr int Sum(int a = 0, const int &b = 0, const int *c = &z, char d = 0) {
return a + b + *c + d;
}
const int four = 4;
constexpr int eight = 8;
constexpr const int twentyseven = 27;
static_assert(Sum() == 0, "");
static_assert(Sum(1) == 1, "");
static_assert(Sum(1, four) == 5, "");
static_assert(Sum(1, eight, &twentyseven) == 36, "");
static_assert(Sum(1, 2, &four, eight) == 15, "");
}
namespace Ellipsis {
// Note, values passed through an ellipsis can't actually be used.
constexpr int F(int a, ...) { return a; }
static_assert(F(0) == 0, "");
static_assert(F(1, 0) == 1, "");
static_assert(F(2, "test") == 2, "");
static_assert(F(3, &F) == 3, "");
int k = 0; // expected-note {{here}}
static_assert(F(4, k) == 3, ""); // expected-error {{constant expression}} expected-note {{read of non-const variable 'k'}}
}
namespace Recursion {
constexpr int fib(int n) { return n > 1 ? fib(n-1) + fib(n-2) : n; }
static_assert(fib(11) == 89, "");
constexpr int gcd_inner(int a, int b) {
return b == 0 ? a : gcd_inner(b, a % b);
}
constexpr int gcd(int a, int b) {
return gcd_inner(max(a, b), min(a, b));
}
static_assert(gcd(1749237, 5628959) == 7, "");
}
namespace FunctionCast {
// When folding, we allow functions to be cast to different types. Such
// cast functions cannot be called, even if they're constexpr.
constexpr int f() { return 1; }
typedef double (*DoubleFn)();
typedef int (*IntFn)();
int a[(int)DoubleFn(f)()]; // expected-error {{variable length array}} expected-warning{{C99 feature}}
int b[(int)IntFn(f)()]; // ok
}
namespace StaticMemberFunction {
struct S {
static constexpr int k = 42;
static constexpr int f(int n) { return n * k + 2; }
} s;
constexpr int n = s.f(19);
static_assert(S::f(19) == 800, "");
static_assert(s.f(19) == 800, "");
static_assert(n == 800, "");
constexpr int (*sf1)(int) = &S::f;
constexpr int (*sf2)(int) = &s.f;
constexpr const int *sk = &s.k;
}
namespace ParameterScopes {
const int k = 42;
constexpr const int &ObscureTheTruth(const int &a) { return a; }
constexpr const int &MaybeReturnJunk(bool b, const int a) { // expected-note 2{{declared here}}
return ObscureTheTruth(b ? a : k);
}
static_assert(MaybeReturnJunk(false, 0) == 42, ""); // ok
constexpr int a = MaybeReturnJunk(true, 0); // expected-error {{constant expression}} expected-note {{read of variable whose lifetime has ended}}
constexpr const int MaybeReturnNonstaticRef(bool b, const int a) {
return ObscureTheTruth(b ? a : k);
}
static_assert(MaybeReturnNonstaticRef(false, 0) == 42, ""); // ok
constexpr int b = MaybeReturnNonstaticRef(true, 0); // ok
constexpr int InternalReturnJunk(int n) {
return MaybeReturnJunk(true, n); // expected-note {{read of variable whose lifetime has ended}}
}
constexpr int n3 = InternalReturnJunk(0); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'InternalReturnJunk(0)'}}
constexpr int LToR(int &n) { return n; }
constexpr int GrabCallersArgument(bool which, int a, int b) {
return LToR(which ? b : a);
}
static_assert(GrabCallersArgument(false, 1, 2) == 1, "");
static_assert(GrabCallersArgument(true, 4, 8) == 8, "");
}
namespace Pointers {
constexpr int f(int n, const int *a, const int *b, const int *c) {
return n == 0 ? 0 : *a + f(n-1, b, c, a);
}
const int x = 1, y = 10, z = 100;
static_assert(f(23, &x, &y, &z) == 788, "");
constexpr int g(int n, int a, int b, int c) {
return f(n, &a, &b, &c);
}
static_assert(g(23, x, y, z) == 788, "");
}
namespace FunctionPointers {
constexpr int Double(int n) { return 2 * n; }
constexpr int Triple(int n) { return 3 * n; }
constexpr int Twice(int (*F)(int), int n) { return F(F(n)); }
constexpr int Quadruple(int n) { return Twice(Double, n); }
constexpr auto Select(int n) -> int (*)(int) {
return n == 2 ? &Double : n == 3 ? &Triple : n == 4 ? &Quadruple : 0;
}
constexpr int Apply(int (*F)(int), int n) { return F(n); } // expected-note {{subexpression}}
static_assert(1 + Apply(Select(4), 5) + Apply(Select(3), 7) == 42, "");
constexpr int Invalid = Apply(Select(0), 0); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'Apply(0, 0)'}}
}
namespace PointerComparison {
int x, y;
static_assert(&x == &y, "false"); // expected-error {{false}}
static_assert(&x != &y, "");
constexpr bool g1 = &x == &y;
constexpr bool g2 = &x != &y;
constexpr bool g3 = &x <= &y; // expected-error {{must be initialized by a constant expression}}
constexpr bool g4 = &x >= &y; // expected-error {{must be initialized by a constant expression}}
constexpr bool g5 = &x < &y; // expected-error {{must be initialized by a constant expression}}
constexpr bool g6 = &x > &y; // expected-error {{must be initialized by a constant expression}}
struct S { int x, y; } s;
static_assert(&s.x == &s.y, "false"); // expected-error {{false}}
static_assert(&s.x != &s.y, "");
static_assert(&s.x <= &s.y, "");
static_assert(&s.x >= &s.y, "false"); // expected-error {{false}}
static_assert(&s.x < &s.y, "");
static_assert(&s.x > &s.y, "false"); // expected-error {{false}}
static_assert(0 == &y, "false"); // expected-error {{false}}
static_assert(0 != &y, "");
constexpr bool n3 = 0 <= &y; // expected-error {{must be initialized by a constant expression}}
constexpr bool n4 = 0 >= &y; // expected-error {{must be initialized by a constant expression}}
constexpr bool n5 = 0 < &y; // expected-error {{must be initialized by a constant expression}}
constexpr bool n6 = 0 > &y; // expected-error {{must be initialized by a constant expression}}
static_assert(&x == 0, "false"); // expected-error {{false}}
static_assert(&x != 0, "");
constexpr bool n9 = &x <= 0; // expected-error {{must be initialized by a constant expression}}
constexpr bool n10 = &x >= 0; // expected-error {{must be initialized by a constant expression}}
constexpr bool n11 = &x < 0; // expected-error {{must be initialized by a constant expression}}
constexpr bool n12 = &x > 0; // expected-error {{must be initialized by a constant expression}}
static_assert(&x == &x, "");
static_assert(&x != &x, "false"); // expected-error {{false}}
static_assert(&x <= &x, "");
static_assert(&x >= &x, "");
static_assert(&x < &x, "false"); // expected-error {{false}}
static_assert(&x > &x, "false"); // expected-error {{false}}
constexpr S* sptr = &s;
constexpr bool dyncast = sptr == dynamic_cast<S*>(sptr); // expected-error {{constant expression}} expected-note {{dynamic_cast}}
struct U {};
struct Str {
int a : dynamic_cast<S*>(sptr) == dynamic_cast<S*>(sptr); // \
expected-warning {{not an integral constant expression}} \
expected-note {{dynamic_cast is not allowed in a constant expression}}
int b : reinterpret_cast<S*>(sptr) == reinterpret_cast<S*>(sptr); // \
expected-warning {{not an integral constant expression}} \
expected-note {{reinterpret_cast is not allowed in a constant expression}}
int c : (S*)(long)(sptr) == (S*)(long)(sptr); // \
expected-warning {{not an integral constant expression}} \
expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
int d : (S*)(42) == (S*)(42); // \
expected-warning {{not an integral constant expression}} \
expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
int e : (Str*)(sptr) == (Str*)(sptr); // \
expected-warning {{not an integral constant expression}} \
expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
int f : &(U&)(*sptr) == &(U&)(*sptr); // \
expected-warning {{not an integral constant expression}} \
expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
int g : (S*)(void*)(sptr) == sptr; // \
expected-warning {{not an integral constant expression}} \
expected-note {{cast from 'void *' is not allowed in a constant expression}}
};
extern char externalvar[];
constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}}
constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be initialized by a constant expression}} expected-warning {{unspecified}}
static_assert(0 != "foo", "");
}
namespace MaterializeTemporary {
constexpr int f(const int &r) { return r; }
constexpr int n = f(1);
constexpr bool same(const int &a, const int &b) { return &a == &b; }
constexpr bool sameTemporary(const int &n) { return same(n, n); }
static_assert(n, "");
static_assert(!same(4, 4), "");
static_assert(same(n, n), "");
static_assert(sameTemporary(9), "");
struct A { int &&r; };
struct B { A &&a1; A &&a2; };
constexpr B b1 { { 1 }, { 2 } }; // expected-note {{temporary created here}}
static_assert(&b1.a1 != &b1.a2, "");
static_assert(&b1.a1.r != &b1.a2.r, ""); // expected-error {{constant expression}} expected-note {{outside the expression that created the temporary}}
constexpr B &&b2 { { 3 }, { 4 } }; // expected-note {{temporary created here}}
static_assert(&b1 != &b2, "");
static_assert(&b1.a1 != &b2.a1, ""); // expected-error {{constant expression}} expected-note {{outside the expression that created the temporary}}
constexpr thread_local B b3 { { 1 }, { 2 } }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
void foo() {
constexpr static B b1 { { 1 }, { 2 } }; // ok
constexpr thread_local B b2 { { 1 }, { 2 } }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
constexpr B b3 { { 1 }, { 2 } }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
}
constexpr B &&b4 = ((1, 2), 3, 4, B { {10}, {{20}} }); // expected-warning 4{{unused}}
static_assert(&b4 != &b2, "");
// Proposed DR: copy-elision doesn't trigger lifetime extension.
constexpr B b5 = B{ {0}, {0} }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
namespace NestedNonStatic {
// Proposed DR: for a reference constant expression to refer to a static
// storage duration temporary, that temporary must itself be initialized
// by a constant expression (a core constant expression is not enough).
struct A { int &&r; };
struct B { A &&a; };
constexpr B a = { A{0} }; // ok
constexpr B b = { A(A{0}) }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
}
namespace FakeInitList {
struct init_list_3_ints { const int (&x)[3]; };
struct init_list_2_init_list_3_ints { const init_list_3_ints (&x)[2]; };
constexpr init_list_2_init_list_3_ints ils = { { { { 1, 2, 3 } }, { { 4, 5, 6 } } } };
}
}
constexpr int strcmp_ce(const char *p, const char *q) {
return (!*p || *p != *q) ? *p - *q : strcmp_ce(p+1, q+1);
}
namespace StringLiteral {
template<typename Char>
constexpr int MangleChars(const Char *p) {
return *p + 3 * (*p ? MangleChars(p+1) : 0);
}
static_assert(MangleChars("constexpr!") == 1768383, "");
static_assert(MangleChars(u8"constexpr!") == 1768383, "");
static_assert(MangleChars(L"constexpr!") == 1768383, "");
static_assert(MangleChars(u"constexpr!") == 1768383, "");
static_assert(MangleChars(U"constexpr!") == 1768383, "");
constexpr char c0 = "nought index"[0];
constexpr char c1 = "nice index"[10];
constexpr char c2 = "nasty index"[12]; // expected-error {{must be initialized by a constant expression}} expected-warning {{is past the end}} expected-note {{read of dereferenced one-past-the-end pointer}}
constexpr char c3 = "negative index"[-1]; // expected-error {{must be initialized by a constant expression}} expected-warning {{is before the beginning}} expected-note {{cannot refer to element -1 of array of 15 elements}}
constexpr char c4 = ((char*)(int*)"no reinterpret_casts allowed")[14]; // expected-error {{must be initialized by a constant expression}} expected-note {{cast that performs the conversions of a reinterpret_cast}}
constexpr const char *p = "test" + 2;
static_assert(*p == 's', "");
constexpr const char *max_iter(const char *a, const char *b) {
return *a < *b ? b : a;
}
constexpr const char *max_element(const char *a, const char *b) {
return (a+1 >= b) ? a : max_iter(a, max_element(a+1, b));
}
constexpr char str[] = "the quick brown fox jumped over the lazy dog";
constexpr const char *max = max_element(begin(str), end(str));
static_assert(*max == 'z', "");
static_assert(max == str + 38, "");
static_assert(strcmp_ce("hello world", "hello world") == 0, "");
static_assert(strcmp_ce("hello world", "hello clang") > 0, "");
static_assert(strcmp_ce("constexpr", "test") < 0, "");
static_assert(strcmp_ce("", " ") < 0, "");
struct S {
int n : "foo"[4]; // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
};
struct T {
char c[6];
constexpr T() : c{"foo"} {}
};
constexpr T t;
static_assert(t.c[0] == 'f', "");
static_assert(t.c[1] == 'o', "");
static_assert(t.c[2] == 'o', "");
static_assert(t.c[3] == 0, "");
static_assert(t.c[4] == 0, "");
static_assert(t.c[5] == 0, "");
static_assert(t.c[6] == 0, ""); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
struct U {
wchar_t chars[6];
int n;
} constexpr u = { { L"test" }, 0 };
static_assert(u.chars[2] == L's', "");
struct V {
char c[4];
constexpr V() : c("hi!") {}
};
static_assert(V().c[1] == "i"[0], "");
namespace Parens {
constexpr unsigned char a[] = ("foo"), b[] = {"foo"}, c[] = {("foo")},
d[4] = ("foo"), e[5] = {"foo"}, f[6] = {("foo")};
static_assert(a[0] == 'f', "");
static_assert(b[1] == 'o', "");
static_assert(c[2] == 'o', "");
static_assert(d[0] == 'f', "");
static_assert(e[1] == 'o', "");
static_assert(f[2] == 'o', "");
static_assert(f[5] == 0, "");
static_assert(f[6] == 0, ""); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
}
}
namespace Array {
template<typename Iter>
constexpr auto Sum(Iter begin, Iter end) -> decltype(+*begin) {
return begin == end ? 0 : *begin + Sum(begin+1, end);
}
constexpr int xs[] = { 1, 2, 3, 4, 5 };
constexpr int ys[] = { 5, 4, 3, 2, 1 };
constexpr int sum_xs = Sum(begin(xs), end(xs));
static_assert(sum_xs == 15, "");
constexpr int ZipFoldR(int (*F)(int x, int y, int c), int n,
const int *xs, const int *ys, int c) {
return n ? F(
*xs, // expected-note {{read of dereferenced one-past-the-end pointer}}
*ys,
ZipFoldR(F, n-1, xs+1, ys+1, c)) // \
expected-note {{in call to 'ZipFoldR(&SubMul, 2, &xs[4], &ys[4], 1)'}} \
expected-note {{in call to 'ZipFoldR(&SubMul, 1, &xs[5], &ys[5], 1)'}}
: c;
}
constexpr int MulAdd(int x, int y, int c) { return x * y + c; }
constexpr int InnerProduct = ZipFoldR(MulAdd, 5, xs, ys, 0);
static_assert(InnerProduct == 35, "");
constexpr int SubMul(int x, int y, int c) { return (x - y) * c; }
constexpr int DiffProd = ZipFoldR(SubMul, 2, xs+3, ys+3, 1);
static_assert(DiffProd == 8, "");
static_assert(ZipFoldR(SubMul, 3, xs+3, ys+3, 1), ""); // \
expected-error {{constant expression}} \
expected-note {{in call to 'ZipFoldR(&SubMul, 3, &xs[3], &ys[3], 1)'}}
constexpr const int *p = xs + 3;
constexpr int xs4 = p[1]; // ok
constexpr int xs5 = p[2]; // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
constexpr int xs6 = p[3]; // expected-error {{constant expression}} expected-note {{cannot refer to element 6}}
constexpr int xs0 = p[-3]; // ok
constexpr int xs_1 = p[-4]; // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
constexpr int zs[2][2][2][2] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
static_assert(zs[0][0][0][0] == 1, "");
static_assert(zs[1][1][1][1] == 16, "");
static_assert(zs[0][0][0][2] == 3, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
static_assert((&zs[0][0][0][2])[-1] == 2, "");
static_assert(**(**(zs + 1) + 1) == 11, "");
static_assert(*(&(&(*(*&(&zs[2] - 1)[0] + 2 - 2))[2])[-1][-1] + 1) == 11, ""); // expected-error {{constant expression}} expected-note {{cannot refer to element -1 of array of 2 elements in a constant expression}}
static_assert(*(&(&(*(*&(&zs[2] - 1)[0] + 2 - 2))[2])[-1][2] - 2) == 11, "");
constexpr int err_zs_1_2_0_0 = zs[1][2][0][0]; // expected-error {{constant expression}} expected-note {{cannot access array element of pointer past the end}}
constexpr int fail(const int &p) {
return (&p)[64]; // expected-note {{cannot refer to element 64 of array of 2 elements}}
}
static_assert(fail(*(&(&(*(*&(&zs[2] - 1)[0] + 2 - 2))[2])[-1][2] - 2)) == 11, ""); // \
expected-error {{static_assert expression is not an integral constant expression}} \
expected-note {{in call to 'fail(zs[1][0][1][0])'}}
constexpr int arr[40] = { 1, 2, 3, [8] = 4 }; // expected-warning {{C99 feature}}
constexpr int SumNonzero(const int *p) {
return *p + (*p ? SumNonzero(p+1) : 0);
}
constexpr int CountZero(const int *p, const int *q) {
return p == q ? 0 : (*p == 0) + CountZero(p+1, q);
}
static_assert(SumNonzero(arr) == 6, "");
static_assert(CountZero(arr, arr + 40) == 36, "");
struct ArrayElem {
constexpr ArrayElem() : n(0) {}
int n;
constexpr int f() const { return n; }
};
struct ArrayRVal {
constexpr ArrayRVal() {}
ArrayElem elems[10];
};
static_assert(ArrayRVal().elems[3].f() == 0, "");
constexpr int selfref[2][2][2] = {
selfref[1][1][1] + 1, selfref[0][0][0] + 1,
selfref[1][0][1] + 1, selfref[0][1][0] + 1,
selfref[1][0][0] + 1, selfref[0][1][1] + 1 };
static_assert(selfref[0][0][0] == 1, "");
static_assert(selfref[0][0][1] == 2, "");
static_assert(selfref[0][1][0] == 1, "");
static_assert(selfref[0][1][1] == 2, "");
static_assert(selfref[1][0][0] == 1, "");
static_assert(selfref[1][0][1] == 3, "");
static_assert(selfref[1][1][0] == 0, "");
static_assert(selfref[1][1][1] == 0, "");
struct TrivialDefCtor { int n; };
typedef TrivialDefCtor TDCArray[2][2];
static_assert(TDCArray{}[1][1].n == 0, "");
struct NonAggregateTDC : TrivialDefCtor {};
typedef NonAggregateTDC NATDCArray[2][2];
static_assert(NATDCArray{}[1][1].n == 0, "");
}
namespace DependentValues {
struct I { int n; typedef I V[10]; };
I::V x, y;
int g();
template<bool B, typename T> struct S : T {
int k;
void f() {
I::V &cells = B ? x : y;
I &i = cells[k];
switch (i.n) {}
// FIXME: We should be able to diagnose this.
constexpr int n = g();
constexpr int m = this->g(); // ok, could be constexpr
}
};
}
namespace Class {
struct A { constexpr A(int a, int b) : k(a + b) {} int k; };
constexpr int fn(const A &a) { return a.k; }
static_assert(fn(A(4,5)) == 9, "");
struct B { int n; int m; } constexpr b = { 0, b.n };
struct C {
constexpr C(C *this_) : m(42), n(this_->m) {} // ok
int m, n;
};
struct D {
C c;
constexpr D() : c(&c) {}
};
static_assert(D().c.n == 42, "");
struct E {
constexpr E() : p(&p) {}
void *p;
};
constexpr const E &e1 = E();
// This is a constant expression if we elide the copy constructor call, and
// is not a constant expression if we don't! But we do, so it is.
constexpr E e2 = E();
static_assert(e2.p == &e2.p, "");
constexpr E e3;
static_assert(e3.p == &e3.p, "");
extern const class F f;
struct F {
constexpr F() : p(&f.p) {}
const void *p;
};
constexpr F f;
struct G {
struct T {
constexpr T(T *p) : u1(), u2(p) {}
union U1 {
constexpr U1() {}
int a, b = 42;
} u1;
union U2 {
constexpr U2(T *p) : c(p->u1.b) {}
int c, d;
} u2;
} t;
constexpr G() : t(&t) {}
} constexpr g;
static_assert(g.t.u1.a == 42, ""); // expected-error {{constant expression}} expected-note {{read of member 'a' of union with active member 'b'}}
static_assert(g.t.u1.b == 42, "");
static_assert(g.t.u2.c == 42, "");
static_assert(g.t.u2.d == 42, ""); // expected-error {{constant expression}} expected-note {{read of member 'd' of union with active member 'c'}}
struct S {
int a, b;
const S *p;
double d;
const char *q;
constexpr S(int n, const S *p) : a(5), b(n), p(p), d(n), q("hello") {}
};
S global(43, &global);
static_assert(S(15, &global).b == 15, "");
constexpr bool CheckS(const S &s) {
return s.a == 5 && s.b == 27 && s.p == &global && s.d == 27. && s.q[3] == 'l';
}
static_assert(CheckS(S(27, &global)), "");
struct Arr {
char arr[3];
constexpr Arr() : arr{'x', 'y', 'z'} {}
};
constexpr int hash(Arr &&a) {
return a.arr[0] + a.arr[1] * 0x100 + a.arr[2] * 0x10000;
}
constexpr int k = hash(Arr());
static_assert(k == 0x007a7978, "");
struct AggregateInit {
const char &c;
int n;
double d;
int arr[5];
void *p;
};
constexpr AggregateInit agg1 = { "hello"[0] };
static_assert(strcmp_ce(&agg1.c, "hello") == 0, "");
static_assert(agg1.n == 0, "");
static_assert(agg1.d == 0.0, "");
static_assert(agg1.arr[-1] == 0, ""); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
static_assert(agg1.arr[0] == 0, "");
static_assert(agg1.arr[4] == 0, "");
static_assert(agg1.arr[5] == 0, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end}}
static_assert(agg1.p == nullptr, "");
static constexpr const unsigned char uc[] = { "foo" };
static_assert(uc[0] == 'f', "");
static_assert(uc[3] == 0, "");
namespace SimpleDerivedClass {
struct B {
constexpr B(int n) : a(n) {}
int a;
};
struct D : B {
constexpr D(int n) : B(n) {}
};
constexpr D d(3);
static_assert(d.a == 3, "");
}
struct Bottom { constexpr Bottom() {} };
struct Base : Bottom {
constexpr Base(int a = 42, const char *b = "test") : a(a), b(b) {}
int a;
const char *b;
};
struct Base2 : Bottom {
constexpr Base2(const int &r) : r(r) {}
int q = 123;
const int &r;
};
struct Derived : Base, Base2 {
constexpr Derived() : Base(76), Base2(a) {}
int c = r + b[1];
};
constexpr bool operator==(const Base &a, const Base &b) {
return a.a == b.a && strcmp_ce(a.b, b.b) == 0;
}
constexpr Base base;
constexpr Base base2(76);
constexpr Derived derived;
static_assert(derived.a == 76, "");
static_assert(derived.b[2] == 's', "");
static_assert(derived.c == 76 + 'e', "");
static_assert(derived.q == 123, "");
static_assert(derived.r == 76, "");
static_assert(&derived.r == &derived.a, "");
static_assert(!(derived == base), "");
static_assert(derived == base2, "");
constexpr Bottom &bot1 = (Base&)derived;
constexpr Bottom &bot2 = (Base2&)derived;
static_assert(&bot1 != &bot2, "");
constexpr Bottom *pb1 = (Base*)&derived;
constexpr Bottom *pb2 = (Base2*)&derived;
static_assert(&pb1 != &pb2, "");
static_assert(pb1 == &bot1, "");
static_assert(pb2 == &bot2, "");
constexpr Base2 &fail = (Base2&)bot1; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'const Class::Derived' to type 'Class::Base2'}}
constexpr Base &fail2 = (Base&)*pb2; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'const Class::Derived' to type 'Class::Base'}}
constexpr Base2 &ok2 = (Base2&)bot2;
static_assert(&ok2 == &derived, "");
constexpr Base2 *pfail = (Base2*)pb1; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'const Class::Derived' to type 'Class::Base2'}}
constexpr Base *pfail2 = (Base*)&bot2; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'const Class::Derived' to type 'Class::Base'}}
constexpr Base2 *pok2 = (Base2*)pb2;
static_assert(pok2 == &derived, "");
static_assert(&ok2 == pok2, "");
static_assert((Base2*)(Derived*)(Base*)pb1 == pok2, "");
static_assert((Derived*)(Base*)pb1 == (Derived*)pok2, "");
// Core issue 903: we do not perform constant evaluation when checking for a
// null pointer in C++11. Just check for an integer literal with value 0.
constexpr Base *nullB = 42 - 6 * 7; // expected-error {{cannot initialize a variable of type 'Class::Base *const' with an rvalue of type 'int'}}
constexpr Base *nullB1 = 0;
static_assert((Bottom*)nullB == 0, "");
static_assert((Derived*)nullB == 0, "");
static_assert((void*)(Bottom*)nullB == (void*)(Derived*)nullB, "");
Base *nullB2 = '\0'; // expected-error {{cannot initialize a variable of type 'Class::Base *' with an rvalue of type 'char'}}
Base *nullB3 = (0);
Base *nullB4 = false; // expected-error {{cannot initialize a variable of type 'Class::Base *' with an rvalue of type 'bool'}}
Base *nullB5 = ((0ULL));
Base *nullB6 = 0.; // expected-error {{cannot initialize a variable of type 'Class::Base *' with an rvalue of type 'double'}}
enum Null { kNull };
Base *nullB7 = kNull; // expected-error {{cannot initialize a variable of type 'Class::Base *' with an rvalue of type 'Class::Null'}}
static_assert(nullB1 == (1 - 1), ""); // expected-error {{comparison between pointer and integer}}
namespace ConversionOperators {
struct T {
constexpr T(int n) : k(5*n - 3) {}
constexpr operator int() const { return k; }
int k;
};
struct S {
constexpr S(int n) : k(2*n + 1) {}
constexpr operator int() const { return k; }
constexpr operator T() const { return T(k); }
int k;
};
constexpr bool check(T a, T b) { return a == b.k; }
static_assert(S(5) == 11, "");
static_assert(check(S(5), 11), "");
namespace PR14171 {
struct X {
constexpr (operator int)() const { return 0; }
};
static_assert(X() == 0, "");
}
}
struct This {
constexpr int f() const { return 0; }
static constexpr int g() { return 0; }
void h() {
constexpr int x = f(); // expected-error {{must be initialized by a constant}}
// expected-note@-1 {{implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function}}
constexpr int y = this->f(); // expected-error {{must be initialized by a constant}}
// expected-note-re@-1 {{{{^}}use of 'this' pointer}}
constexpr int z = g();
static_assert(z == 0, "");
}
};
}
namespace Temporaries {
struct S {
constexpr S() {}
constexpr int f() const;
constexpr int g() const;
};
struct T : S {
constexpr T(int n) : S(), n(n) {}
int n;
};
constexpr int S::f() const {
return static_cast<const T*>(this)->n; // expected-note {{cannot cast}}
}
constexpr int S::g() const {
// FIXME: Better diagnostic for this.
return this->*(int(S::*))&T::n; // expected-note {{subexpression}}
}
// The T temporary is implicitly cast to an S subobject, but we can recover the
// T full-object via a base-to-derived cast, or a derived-to-base-casted member
// pointer.
static_assert(S().f(), ""); // expected-error {{constant expression}} expected-note {{in call to '&Temporaries::S()->f()'}}
static_assert(S().g(), ""); // expected-error {{constant expression}} expected-note {{in call to '&Temporaries::S()->g()'}}
static_assert(T(3).f() == 3, "");
static_assert(T(4).g() == 4, "");
constexpr int f(const S &s) {
return static_cast<const T&>(s).n;
}
constexpr int n = f(T(5));
static_assert(f(T(5)) == 5, "");
constexpr bool b(int n) { return &n; }
static_assert(b(0), "");
struct NonLiteral {
NonLiteral();
int f();
};
constexpr int k = NonLiteral().f(); // expected-error {{constant expression}} expected-note {{non-literal type 'Temporaries::NonLiteral'}}
}
namespace Union {
union U {
int a;
int b;
};
constexpr U u[4] = { { .a = 0 }, { .b = 1 }, { .a = 2 }, { .b = 3 } }; // expected-warning 4{{C99 feature}}
static_assert(u[0].a == 0, "");
static_assert(u[0].b, ""); // expected-error {{constant expression}} expected-note {{read of member 'b' of union with active member 'a'}}
static_assert(u[1].b == 1, "");
static_assert((&u[1].b)[1] == 2, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
static_assert(*(&(u[1].b) + 1 + 1) == 3, ""); // expected-error {{constant expression}} expected-note {{cannot refer to element 2 of non-array object}}
static_assert((&(u[1]) + 1 + 1)->b == 3, "");
constexpr U v = {};
static_assert(v.a == 0, "");
union Empty {};
constexpr Empty e = {};
// Make sure we handle trivial copy constructors for unions.
constexpr U x = {42};
constexpr U y = x;
static_assert(y.a == 42, "");
static_assert(y.b == 42, ""); // expected-error {{constant expression}} expected-note {{'b' of union with active member 'a'}}
}
namespace MemberPointer {
struct A {
constexpr A(int n) : n(n) {}
int n;
constexpr int f() const { return n + 3; }
};
constexpr A a(7);
static_assert(A(5).*&A::n == 5, "");
static_assert((&a)->*&A::n == 7, "");
static_assert((A(8).*&A::f)() == 11, "");
static_assert(((&a)->*&A::f)() == 10, "");
struct B : A {
constexpr B(int n, int m) : A(n), m(m) {}
int m;
constexpr int g() const { return n + m + 1; }
};
constexpr B b(9, 13);
static_assert(B(4, 11).*&A::n == 4, "");
static_assert(B(4, 11).*&B::m == 11, "");
static_assert(B(4, 11).*(int(A::*))&B::m == 11, "");
static_assert((&b)->*&A::n == 9, "");
static_assert((&b)->*&B::m == 13, "");
static_assert((&b)->*(int(A::*))&B::m == 13, "");
static_assert((B(4, 11).*&A::f)() == 7, "");
static_assert((B(4, 11).*&B::g)() == 16, "");
static_assert((B(4, 11).*(int(A::*)()const)&B::g)() == 16, "");
static_assert(((&b)->*&A::f)() == 12, "");
static_assert(((&b)->*&B::g)() == 23, "");
static_assert(((&b)->*(int(A::*)()const)&B::g)() == 23, "");
struct S {
constexpr S(int m, int n, int (S::*pf)() const, int S::*pn) :
m(m), n(n), pf(pf), pn(pn) {}
constexpr S() : m(), n(), pf(&S::f), pn(&S::n) {}
constexpr int f() const { return this->*pn; }
virtual int g() const;
int m, n;
int (S::*pf)() const;
int S::*pn;
};
constexpr int S::*pm = &S::m;
constexpr int S::*pn = &S::n;
constexpr int (S::*pf)() const = &S::f;
constexpr int (S::*pg)() const = &S::g;
constexpr S s(2, 5, &S::f, &S::m);
static_assert((s.*&S::f)() == 2, "");
static_assert((s.*s.pf)() == 2, "");
static_assert(pf == &S::f, "");
static_assert(pf == s.*&S::pf, "");
static_assert(pm == &S::m, "");
static_assert(pm != pn, "");
static_assert(s.pn != pn, "");
static_assert(s.pn == pm, "");
static_assert(pg != nullptr, "");
static_assert(pf != nullptr, "");
static_assert((int S::*)nullptr == nullptr, "");
static_assert(pg == pg, ""); // expected-error {{constant expression}} expected-note {{comparison of pointer to virtual member function 'g' has unspecified value}}
static_assert(pf != pg, ""); // expected-error {{constant expression}} expected-note {{comparison of pointer to virtual member function 'g' has unspecified value}}
template<int n> struct T : T<n-1> {};
template<> struct T<0> { int n; };
template<> struct T<30> : T<29> { int m; };
T<17> t17;
T<30> t30;
constexpr int (T<10>::*deepn) = &T<0>::n;
static_assert(&(t17.*deepn) == &t17.n, "");
static_assert(deepn == &T<2>::n, "");
constexpr int (T<15>::*deepm) = (int(T<10>::*))&T<30>::m;
constexpr int *pbad = &(t17.*deepm); // expected-error {{constant expression}}
static_assert(&(t30.*deepm) == &t30.m, "");
static_assert(deepm == &T<50>::m, "");
static_assert(deepm != deepn, "");
constexpr T<5> *p17_5 = &t17;
constexpr T<13> *p17_13 = (T<13>*)p17_5;
constexpr T<23> *p17_23 = (T<23>*)p17_13; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'T<17>' to type 'T<23>'}}
static_assert(&(p17_5->*(int(T<3>::*))deepn) == &t17.n, "");
static_assert(&(p17_13->*deepn) == &t17.n, "");
constexpr int *pbad2 = &(p17_13->*(int(T<9>::*))deepm); // expected-error {{constant expression}}
constexpr T<5> *p30_5 = &t30;
constexpr T<23> *p30_23 = (T<23>*)p30_5;
constexpr T<13> *p30_13 = p30_23;
static_assert(&(p30_5->*(int(T<3>::*))deepn) == &t30.n, "");
static_assert(&(p30_13->*deepn) == &t30.n, "");
static_assert(&(p30_23->*deepn) == &t30.n, "");
static_assert(&(p30_5->*(int(T<2>::*))deepm) == &t30.m, "");
static_assert(&(((T<17>*)p30_13)->*deepm) == &t30.m, "");
static_assert(&(p30_23->*deepm) == &t30.m, "");
struct Base { int n; };
template<int N> struct Mid : Base {};
struct Derived : Mid<0>, Mid<1> {};
static_assert(&Mid<0>::n == &Mid<1>::n, "");
static_assert((int Derived::*)(int Mid<0>::*)&Mid<0>::n !=
(int Derived::*)(int Mid<1>::*)&Mid<1>::n, "");
static_assert(&Mid<0>::n == (int Mid<0>::*)&Base::n, "");
}
namespace ArrayBaseDerived {
struct Base {
constexpr Base() {}
int n = 0;
};
struct Derived : Base {
constexpr Derived() {}
constexpr const int *f() const { return &n; }
};
constexpr Derived a[10];
constexpr Derived *pd3 = const_cast<Derived*>(&a[3]);
constexpr Base *pb3 = const_cast<Derived*>(&a[3]);
static_assert(pb3 == pd3, "");
// pb3 does not point to an array element.
constexpr Base *pb4 = pb3 + 1; // ok, one-past-the-end pointer.
constexpr int pb4n = pb4->n; // expected-error {{constant expression}} expected-note {{cannot access field of pointer past the end}}
constexpr Base *err_pb5 = pb3 + 2; // expected-error {{constant expression}} expected-note {{cannot refer to element 2}} expected-note {{here}}
constexpr int err_pb5n = err_pb5->n; // expected-error {{constant expression}} expected-note {{initializer of 'err_pb5' is not a constant expression}}
constexpr Base *err_pb2 = pb3 - 1; // expected-error {{constant expression}} expected-note {{cannot refer to element -1}} expected-note {{here}}
constexpr int err_pb2n = err_pb2->n; // expected-error {{constant expression}} expected-note {{initializer of 'err_pb2'}}
constexpr Base *pb3a = pb4 - 1;
// pb4 does not point to a Derived.
constexpr Derived *err_pd4 = (Derived*)pb4; // expected-error {{constant expression}} expected-note {{cannot access derived class of pointer past the end}}
constexpr Derived *pd3a = (Derived*)pb3a;
constexpr int pd3n = pd3a->n;
// pd3a still points to the Derived array.
constexpr Derived *pd6 = pd3a + 3;
static_assert(pd6 == &a[6], "");
constexpr Derived *pd9 = pd6 + 3;
constexpr Derived *pd10 = pd6 + 4;
constexpr int pd9n = pd9->n; // ok
constexpr int err_pd10n = pd10->n; // expected-error {{constant expression}} expected-note {{cannot access base class of pointer past the end}}
constexpr int pd0n = pd10[-10].n;
constexpr int err_pdminus1n = pd10[-11].n; // expected-error {{constant expression}} expected-note {{cannot refer to element -1 of}}
constexpr Base *pb9 = pd9;
constexpr const int *(Base::*pfb)() const =
static_cast<const int *(Base::*)() const>(&Derived::f);
static_assert((pb9->*pfb)() == &a[9].n, "");
}
namespace Complex {
class complex {
int re, im;
public:
constexpr complex(int re = 0, int im = 0) : re(re), im(im) {}
constexpr complex(const complex &o) : re(o.re), im(o.im) {}
constexpr complex operator-() const { return complex(-re, -im); }
friend constexpr complex operator+(const complex &l, const complex &r) {
return complex(l.re + r.re, l.im + r.im);
}
friend constexpr complex operator-(const complex &l, const complex &r) {
return l + -r;
}
friend constexpr complex operator*(const complex &l, const complex &r) {
return complex(l.re * r.re - l.im * r.im, l.re * r.im + l.im * r.re);
}
friend constexpr bool operator==(const complex &l, const complex &r) {
return l.re == r.re && l.im == r.im;
}
constexpr bool operator!=(const complex &r) const {
return re != r.re || im != r.im;
}
constexpr int real() const { return re; }
constexpr int imag() const { return im; }
};
constexpr complex i = complex(0, 1);
constexpr complex k = (3 + 4*i) * (6 - 4*i);
static_assert(complex(1,0).real() == 1, "");
static_assert(complex(1,0).imag() == 0, "");
static_assert(((complex)1).imag() == 0, "");
static_assert(k.real() == 34, "");
static_assert(k.imag() == 12, "");
static_assert(k - 34 == 12*i, "");
static_assert((complex)1 == complex(1), "");
static_assert((complex)1 != complex(0, 1), "");
static_assert(complex(1) == complex(1), "");
static_assert(complex(1) != complex(0, 1), "");
constexpr complex makeComplex(int re, int im) { return complex(re, im); }
static_assert(makeComplex(1,0) == complex(1), "");
static_assert(makeComplex(1,0) != complex(0, 1), "");
class complex_wrap : public complex {
public:
constexpr complex_wrap(int re, int im = 0) : complex(re, im) {}
constexpr complex_wrap(const complex_wrap &o) : complex(o) {}
};
static_assert((complex_wrap)1 == complex(1), "");
static_assert((complex)1 != complex_wrap(0, 1), "");
static_assert(complex(1) == complex_wrap(1), "");
static_assert(complex_wrap(1) != complex(0, 1), "");
constexpr complex_wrap makeComplexWrap(int re, int im) {
return complex_wrap(re, im);
}
static_assert(makeComplexWrap(1,0) == complex(1), "");
static_assert(makeComplexWrap(1,0) != complex(0, 1), "");
}
namespace PR11595 {
struct A { constexpr bool operator==(int x) const { return true; } };
struct B { B(); A& x; };
static_assert(B().x == 3, ""); // expected-error {{constant expression}} expected-note {{non-literal type 'PR11595::B' cannot be used in a constant expression}}
constexpr bool f(int k) { // expected-error {{constexpr function never produces a constant expression}}
return B().x == k; // expected-note {{non-literal type 'PR11595::B' cannot be used in a constant expression}}
}
}
namespace ExprWithCleanups {
struct A { A(); ~A(); int get(); };
constexpr int get(bool FromA) { return FromA ? A().get() : 1; }
constexpr int n = get(false);
}
namespace Volatile {
volatile constexpr int n1 = 0; // expected-note {{here}}
volatile const int n2 = 0; // expected-note {{here}}
int n3 = 37; // expected-note {{declared here}}
constexpr int m1 = n1; // expected-error {{constant expression}} expected-note {{read of volatile-qualified type 'const volatile int'}}
constexpr int m2 = n2; // expected-error {{constant expression}} expected-note {{read of volatile-qualified type 'const volatile int'}}
constexpr int m1b = const_cast<const int&>(n1); // expected-error {{constant expression}} expected-note {{read of volatile object 'n1'}}
constexpr int m2b = const_cast<const int&>(n2); // expected-error {{constant expression}} expected-note {{read of volatile object 'n2'}}
struct T { int n; };
const T t = { 42 }; // expected-note {{declared here}}
constexpr int f(volatile int &&r) {
return r; // expected-note {{read of volatile-qualified type 'volatile int'}}
}
constexpr int g(volatile int &&r) {
return const_cast<int&>(r); // expected-note {{read of volatile temporary is not allowed in a constant expression}}
}
struct S {
int j : f(0); // expected-error {{constant expression}} expected-note {{in call to 'f(0)'}}
int k : g(0); // expected-error {{constant expression}} expected-note {{temporary created here}} expected-note {{in call to 'g(0)'}}
int l : n3; // expected-error {{constant expression}} expected-note {{read of non-const variable}}
int m : t.n; // expected-error {{constant expression}} expected-note {{read of non-constexpr variable}}
};
}
namespace ExternConstexpr {
extern constexpr int n = 0;
extern constexpr int m; // expected-error {{constexpr variable declaration must be a definition}}
void f() {
extern constexpr int i; // expected-error {{constexpr variable declaration must be a definition}}
constexpr int j = 0;
constexpr int k; // expected-error {{default initialization of an object of const type}}
}
}
namespace ComplexConstexpr {
constexpr _Complex float test1 = {};
constexpr _Complex float test2 = {1};
constexpr _Complex double test3 = {1,2};
constexpr _Complex int test4 = {4};
constexpr _Complex int test5 = 4;
constexpr _Complex int test6 = {5,6};
typedef _Complex float fcomplex;
constexpr fcomplex test7 = fcomplex();
constexpr const double &t2r = __real test3;
constexpr const double &t2i = __imag test3;
static_assert(&t2r + 1 == &t2i, "");
static_assert(t2r == 1.0, "");
static_assert(t2i == 2.0, "");
constexpr const double *t2p = &t2r;
static_assert(t2p[-1] == 0.0, ""); // expected-error {{constant expr}} expected-note {{cannot refer to element -1 of array of 2 elements}}
static_assert(t2p[0] == 1.0, "");
static_assert(t2p[1] == 2.0, "");
static_assert(t2p[2] == 0.0, ""); // expected-error {{constant expr}} expected-note {{one-past-the-end pointer}}
static_assert(t2p[3] == 0.0, ""); // expected-error {{constant expr}} expected-note {{cannot refer to element 3 of array of 2 elements}}
constexpr _Complex float *p = 0;
constexpr float pr = __real *p; // expected-error {{constant expr}} expected-note {{cannot access real component of null}}
constexpr float pi = __imag *p; // expected-error {{constant expr}} expected-note {{cannot access imaginary component of null}}
constexpr const _Complex double *q = &test3 + 1;
constexpr double qr = __real *q; // expected-error {{constant expr}} expected-note {{cannot access real component of pointer past the end}}
constexpr double qi = __imag *q; // expected-error {{constant expr}} expected-note {{cannot access imaginary component of pointer past the end}}
static_assert(__real test6 == 5, "");
static_assert(__imag test6 == 6, "");
static_assert(&__imag test6 == &__real test6 + 1, "");
}
// _Atomic(T) is exactly like T for the purposes of constant expression
// evaluation..
namespace Atomic {
constexpr _Atomic int n = 3;
struct S { _Atomic(double) d; };
constexpr S s = { 0.5 };
constexpr double d1 = s.d;
constexpr double d2 = n;
constexpr _Atomic double d3 = n;
constexpr _Atomic(int) n2 = d3;
static_assert(d1 == 0.5, "");
static_assert(d3 == 3.0, "");
namespace PR16056 {
struct TestVar {
_Atomic(int) value;
constexpr TestVar(int value) : value(value) {}
};
constexpr TestVar testVar{-1};
static_assert(testVar.value == -1, "");
}
}
namespace InstantiateCaseStmt {
template<int x> constexpr int f() { return x; }
template<int x> int g(int c) { switch(c) { case f<x>(): return 1; } return 0; }
int gg(int c) { return g<4>(c); }
}
namespace ConvertedConstantExpr {
extern int &m;
extern int &n;
constexpr int k = 4;
int &m = const_cast<int&>(k);
// If we have nothing more interesting to say, ensure we don't produce a
// useless note and instead just point to the non-constant subexpression.
enum class E {
em = m,
en = n, // expected-error {{not a constant expression}}
eo = (m +
n // expected-error {{not a constant expression}}
),
eq = reinterpret_cast<int>((int*)0) // expected-error {{not a constant expression}} expected-note {{reinterpret_cast}}
};
}
namespace IndirectField {
struct S {
struct { // expected-warning {{GNU extension}}
union { // expected-warning {{declared in an anonymous struct}}
struct { // expected-warning {{GNU extension}} expected-warning {{declared in an anonymous union}}
int a;
int b;
};
int c;
};
int d;
};
union {
int e;
int f;
};
constexpr S(int a, int b, int d, int e) : a(a), b(b), d(d), e(e) {}
constexpr S(int c, int d, int f) : c(c), d(d), f(f) {}
};
constexpr S s1(1, 2, 3, 4);
constexpr S s2(5, 6, 7);
// FIXME: The diagnostics here do a very poor job of explaining which unnamed
// member is active and which is requested.
static_assert(s1.a == 1, "");
static_assert(s1.b == 2, "");
static_assert(s1.c == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
static_assert(s1.d == 3, "");
static_assert(s1.e == 4, "");
static_assert(s1.f == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
static_assert(s2.a == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
static_assert(s2.b == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
static_assert(s2.c == 5, "");
static_assert(s2.d == 6, "");
static_assert(s2.e == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
static_assert(s2.f == 7, "");
}
// DR1405: don't allow reading mutable members in constant expressions.
namespace MutableMembers {
struct MM {
mutable int n; // expected-note 3{{declared here}}
} constexpr mm = { 4 };
constexpr int mmn = mm.n; // expected-error {{constant expression}} expected-note {{read of mutable member 'n' is not allowed in a constant expression}}
int x = (mm.n = 1, 3);
constexpr int mmn2 = mm.n; // expected-error {{constant expression}} expected-note {{read of mutable member 'n' is not allowed in a constant expression}}
// Here's one reason why allowing this would be a disaster...
template<int n> struct Id { int k = n; };
int f() {
constexpr MM m = { 0 };
++m.n;
return Id<m.n>().k; // expected-error {{not a constant expression}} expected-note {{read of mutable member 'n' is not allowed in a constant expression}}
}
struct A { int n; };
struct B { mutable A a; }; // expected-note {{here}}
struct C { B b; };
constexpr C c[3] = {};
constexpr int k = c[1].b.a.n; // expected-error {{constant expression}} expected-note {{mutable}}
struct D { int x; mutable int y; }; // expected-note {{here}}
constexpr D d1 = { 1, 2 };
int l = ++d1.y;
constexpr D d2 = d1; // expected-error {{constant}} expected-note {{mutable}} expected-note {{in call}}
struct E {
union {
int a;
mutable int b; // expected-note {{here}}
};
};
constexpr E e1 = {{1}};
constexpr E e2 = e1; // expected-error {{constant}} expected-note {{mutable}} expected-note {{in call}}
struct F {
union U { };
mutable U u;
struct X { };
mutable X x;
struct Y : X { X x; U u; };
mutable Y y;
int n;
};
// This is OK; we don't actually read any mutable state here.
constexpr F f1 = {};
constexpr F f2 = f1;
struct G {
struct X {};
union U { X a; };
mutable U u; // expected-note {{here}}
};
constexpr G g1 = {};
constexpr G g2 = g1; // expected-error {{constant}} expected-note {{mutable}} expected-note {{in call}}
constexpr G::U gu1 = {};
constexpr G::U gu2 = gu1;
union H {
mutable G::X gx; // expected-note {{here}}
};
constexpr H h1 = {};
constexpr H h2 = h1; // expected-error {{constant}} expected-note {{mutable}} expected-note {{in call}}
}
namespace Fold {
// This macro forces its argument to be constant-folded, even if it's not
// otherwise a constant expression.
#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
constexpr int n = (int)(char*)123; // expected-error {{constant expression}} expected-note {{reinterpret_cast}}
constexpr int m = fold((int)(char*)123); // ok
static_assert(m == 123, "");
#undef fold
}
namespace DR1454 {
constexpr const int &f(const int &n) { return n; }
constexpr int k1 = f(0); // ok
struct Wrap {
const int &value;
};
constexpr const Wrap &g(const Wrap &w) { return w; }
constexpr int k2 = g({0}).value; // ok
// The temporary here has static storage duration, so we can bind a constexpr
// reference to it.
constexpr const int &i = 1;
constexpr const int j = i;
static_assert(j == 1, "");
// The temporary here is not const, so it can't be read outside the expression
// in which it was created (per the C++14 rules, which we use to avoid a C++11
// defect).
constexpr int &&k = 1; // expected-note {{temporary created here}}
constexpr const int l = k; // expected-error {{constant expression}} expected-note {{read of temporary}}
void f() {
// The temporary here has automatic storage duration, so we can't bind a
// constexpr reference to it.
constexpr const int &i = 1; // expected-error {{constant expression}} expected-note 2{{temporary}}
}
}
namespace RecursiveOpaqueExpr {
template<typename Iter>
constexpr auto LastNonzero(Iter p, Iter q) -> decltype(+*p) {
return p != q ? (LastNonzero(p+1, q) ?: *p) : 0; // expected-warning {{GNU}}
}
constexpr int arr1[] = { 1, 0, 0, 3, 0, 2, 0, 4, 0, 0 };
static_assert(LastNonzero(begin(arr1), end(arr1)) == 4, "");
constexpr int arr2[] = { 1, 0, 0, 3, 0, 2, 0, 4, 0, 5 };
static_assert(LastNonzero(begin(arr2), end(arr2)) == 5, "");
constexpr int arr3[] = {
1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static_assert(LastNonzero(begin(arr3), end(arr3)) == 2, "");
}
namespace VLASizeof {
void f(int k) {
int arr[k]; // expected-warning {{C99}}
constexpr int n = 1 +
sizeof(arr) // expected-error {{constant expression}}
* 3;
}
}
namespace CompoundLiteral {
// FIXME:
// We don't model the semantics of this correctly: the compound literal is
// represented as a prvalue in the AST, but actually behaves like an lvalue.
// We treat the compound literal as a temporary and refuse to produce a
// pointer to it. This is OK: we're not required to treat this as a constant
// in C++, and in C we model compound literals as lvalues.
constexpr int *p = (int*)(int[1]){0}; // expected-warning {{C99}} expected-error {{constant expression}} expected-note 2{{temporary}}
}
namespace Vector {
typedef int __attribute__((vector_size(16))) VI4;
constexpr VI4 f(int n) {
return VI4 { n * 3, n + 4, n - 5, n / 6 };
}
constexpr auto v1 = f(10);
typedef double __attribute__((vector_size(32))) VD4;
constexpr VD4 g(int n) {
return (VD4) { n / 2.0, n + 1.5, n - 5.4, n * 0.9 }; // expected-warning {{C99}}
}
constexpr auto v2 = g(4);
}
// PR12626, redux
namespace InvalidClasses {
void test0() {
struct X; // expected-note {{forward declaration}}
struct Y { bool b; X x; }; // expected-error {{field has incomplete type}}
Y y;
auto& b = y.b;
}
}
namespace NamespaceAlias {
constexpr int f() {
namespace NS = NamespaceAlias; // expected-warning {{use of this statement in a constexpr function is a C++14 extension}}
return &NS::f != nullptr;
}
}
// Constructors can be implicitly constexpr, even for a non-literal type.
namespace ImplicitConstexpr {
struct Q { Q() = default; Q(const Q&) = default; Q(Q&&) = default; ~Q(); }; // expected-note 3{{here}}
struct R { constexpr R() noexcept; constexpr R(const R&) noexcept; constexpr R(R&&) noexcept; ~R() noexcept; };
struct S { R r; }; // expected-note 3{{here}}
struct T { T(const T&) noexcept; T(T &&) noexcept; ~T() noexcept; };
struct U { T t; }; // expected-note 3{{here}}
static_assert(!__is_literal_type(Q), "");
static_assert(!__is_literal_type(R), "");
static_assert(!__is_literal_type(S), "");
static_assert(!__is_literal_type(T), "");
static_assert(!__is_literal_type(U), "");
struct Test {
friend Q::Q() noexcept; // expected-error {{follows constexpr}}
friend Q::Q(Q&&) noexcept; // expected-error {{follows constexpr}}
friend Q::Q(const Q&) noexcept; // expected-error {{follows constexpr}}
friend S::S() noexcept; // expected-error {{follows constexpr}}
friend S::S(S&&) noexcept; // expected-error {{follows constexpr}}
friend S::S(const S&) noexcept; // expected-error {{follows constexpr}}
friend constexpr U::U() noexcept; // expected-error {{follows non-constexpr}}
friend constexpr U::U(U&&) noexcept; // expected-error {{follows non-constexpr}}
friend constexpr U::U(const U&) noexcept; // expected-error {{follows non-constexpr}}
};
}
// Indirectly test that an implicit lvalue to xvalue conversion performed for
// an NRVO move operation isn't implemented as CK_LValueToRValue.
namespace PR12826 {
struct Foo {};
constexpr Foo id(Foo x) { return x; }
constexpr Foo res(id(Foo()));
}
namespace PR13273 {
struct U {
int t;
U() = default;
};
struct S : U {
S() = default;
};
// S's default constructor isn't constexpr, because U's default constructor
// doesn't initialize 't', but it's trivial, so value-initialization doesn't
// actually call it.
static_assert(S{}.t == 0, "");
}
namespace PR12670 {
struct S {
constexpr S(int a0) : m(a0) {}
constexpr S() : m(6) {}
int m;
};
constexpr S x[3] = { {4}, 5 };
static_assert(x[0].m == 4, "");
static_assert(x[1].m == 5, "");
static_assert(x[2].m == 6, "");
}
// Indirectly test that an implicit lvalue-to-rvalue conversion is performed
// when a conditional operator has one argument of type void and where the other
// is a glvalue of class type.
namespace ConditionalLValToRVal {
struct A {
constexpr A(int a) : v(a) {}
int v;
};
constexpr A f(const A &a) {
return a.v == 0 ? throw a : a;
}
constexpr A a(4);
static_assert(f(a).v == 4, "");
}
namespace TLS {
__thread int n;
int m;
constexpr bool b = &n == &n;
constexpr int *p = &n; // expected-error{{constexpr variable 'p' must be initialized by a constant expression}}
constexpr int *f() { return &n; }
constexpr int *q = f(); // expected-error{{constexpr variable 'q' must be initialized by a constant expression}}
constexpr bool c = f() == f();
constexpr int *g() { return &m; }
constexpr int *r = g();
}
namespace Void {
constexpr void f() { return; } // expected-error{{constexpr function's return type 'void' is not a literal type}}
void assert_failed(const char *msg, const char *file, int line); // expected-note {{declared here}}
#define ASSERT(expr) ((expr) ? static_cast<void>(0) : assert_failed(#expr, __FILE__, __LINE__))
template<typename T, size_t S>
constexpr T get(T (&a)[S], size_t k) {
return ASSERT(k > 0 && k < S), a[k]; // expected-note{{non-constexpr function 'assert_failed'}}
}
#undef ASSERT
template int get(int (&a)[4], size_t);
constexpr int arr[] = { 4, 1, 2, 3, 4 };
static_assert(get(arr, 1) == 1, "");
static_assert(get(arr, 4) == 4, "");
static_assert(get(arr, 0) == 4, ""); // expected-error{{not an integral constant expression}} \
// expected-note{{in call to 'get(arr, 0)'}}
}
namespace std { struct type_info; }
namespace TypeId {
struct A { virtual ~A(); };
A f();
A &g();
constexpr auto &x = typeid(f());
constexpr auto &y = typeid(g()); // expected-error{{constant expression}} \
// expected-note{{typeid applied to expression of polymorphic type 'TypeId::A' is not allowed in a constant expression}} \
// expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
}
namespace PR14203 {
struct duration {
constexpr duration() {}
constexpr operator int() const { return 0; }
};
template<typename T> void f() {
// If we want to evaluate this at the point of the template definition, we
// need to trigger the implicit definition of the move constructor at that
// point.
// FIXME: C++ does not permit us to implicitly define it at the appropriate
// times, since it is only allowed to be implicitly defined when it is
// odr-used.
constexpr duration d = duration();
}
// FIXME: It's unclear whether this is valid. On the one hand, we're not
// allowed to generate a move constructor. On the other hand, if we did,
// this would be a constant expression. For now, we generate a move
// constructor here.
int n = sizeof(short{duration(duration())});
}
namespace ArrayEltInit {
struct A {
constexpr A() : p(&p) {}
void *p;
};
constexpr A a[10];
static_assert(a[0].p == &a[0].p, "");
static_assert(a[9].p == &a[9].p, "");
static_assert(a[0].p != &a[9].p, "");
static_assert(a[9].p != &a[0].p, "");
constexpr A b[10] = {};
static_assert(b[0].p == &b[0].p, "");
static_assert(b[9].p == &b[9].p, "");
static_assert(b[0].p != &b[9].p, "");
static_assert(b[9].p != &b[0].p, "");
}
namespace PR15884 {
struct S {};
constexpr S f() { return {}; }
constexpr S *p = &f();
// expected-error@-1 {{taking the address of a temporary}}
// expected-error@-2 {{constexpr variable 'p' must be initialized by a constant expression}}
// expected-note@-3 {{pointer to temporary is not a constant expression}}
// expected-note@-4 {{temporary created here}}
}
namespace AfterError {
// FIXME: Suppress the 'no return statements' diagnostic if the body is invalid.
constexpr int error() { // expected-error {{no return statement}}
return foobar; // expected-error {{undeclared identifier}}
}
constexpr int k = error(); // expected-error {{must be initialized by a constant expression}}
}
namespace std {
typedef decltype(sizeof(int)) size_t;
template <class _E>
class initializer_list
{
const _E* __begin_;
size_t __size_;
constexpr 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;
constexpr initializer_list() : __begin_(nullptr), __size_(0) {}
constexpr size_t size() const {return __size_;}
constexpr const _E* begin() const {return __begin_;}
constexpr const _E* end() const {return __begin_ + __size_;}
};
}
namespace InitializerList {
constexpr int sum(const int *b, const int *e) {
return b != e ? *b + sum(b+1, e) : 0;
}
constexpr int sum(std::initializer_list<int> ints) {
return sum(ints.begin(), ints.end());
}
static_assert(sum({1, 2, 3, 4, 5}) == 15, "");
static_assert(*std::initializer_list<int>{1, 2, 3}.begin() == 1, "");
static_assert(std::initializer_list<int>{1, 2, 3}.begin()[2] == 3, "");
}
namespace StmtExpr {
struct A { int k; };
void f() {
static_assert(({ const int x = 5; x * 3; }) == 15, ""); // expected-warning {{extension}}
constexpr auto a = ({ A(); }); // expected-warning {{extension}}
}
constexpr int g(int k) {
return ({ // expected-warning {{extension}}
const int x = k;
x * x;
});
}
static_assert(g(123) == 15129, "");
constexpr int h() { // expected-error {{never produces a constant}}
return ({ // expected-warning {{extension}}
return 0; // expected-note {{not supported}}
1;
});
}
}
namespace VirtualFromBase {
struct S1 {
virtual int f() const;
};
struct S2 {
virtual int f();
};
template <typename T> struct X : T {
constexpr X() {}
double d = 0.0;
constexpr int f() { return sizeof(T); } // expected-warning {{will not be implicitly 'const' in C++14}}
};
// Virtual f(), not OK.
constexpr X<X<S1>> xxs1;
constexpr X<S1> *p = const_cast<X<X<S1>>*>(&xxs1);
static_assert(p->f() == sizeof(X<S1>), ""); // expected-error {{constant expression}} expected-note {{virtual function call}}
// Non-virtual f(), OK.
constexpr X<X<S2>> xxs2;
constexpr X<S2> *q = const_cast<X<X<S2>>*>(&xxs2);
static_assert(q->f() == sizeof(S2), "");
}
namespace ConstexprConstructorRecovery {
class X {
public:
enum E : short {
headers = 0x1,
middlefile = 0x2,
choices = 0x4
};
constexpr X() noexcept {};
protected:
E val{0}; // expected-error {{cannot initialize a member subobject of type 'ConstexprConstructorRecovery::X::E' with an rvalue of type 'int'}}
};
constexpr X x{};
}
namespace Lifetime {
void f() {
constexpr int &n = n; // expected-error {{constant expression}} expected-note {{use of reference outside its lifetime}} expected-warning {{not yet bound to a value}}
constexpr int m = m; // expected-error {{constant expression}} expected-note {{read of object outside its lifetime}}
}
constexpr int &get(int &&n) { return n; }
struct S {
int &&r; // expected-note 2{{declared here}}
int &s;
int t;
constexpr S() : r(0), s(get(0)), t(r) {} // expected-warning {{temporary}}
constexpr S(int) : r(0), s(get(0)), t(s) {} // expected-warning {{temporary}} expected-note {{read of object outside its lifetime}}
};
constexpr int k1 = S().t; // ok, int is lifetime-extended to end of constructor
constexpr int k2 = S(0).t; // expected-error {{constant expression}} expected-note {{in call}}
}
namespace Bitfields {
struct A {
bool b : 1;
unsigned u : 5;
int n : 5;
bool b2 : 3;
unsigned u2 : 74; // expected-warning {{exceeds the size of its type}}
int n2 : 81; // expected-warning {{exceeds the size of its type}}
};
constexpr A a = { false, 33, 31, false, 0xffffffff, 0x7fffffff }; // expected-warning 2{{truncation}}
static_assert(a.b == 0 && a.u == 1 && a.n == -1 && a.b2 == 0 &&
a.u2 + 1 == 0 && a.n2 == 0x7fffffff,
"bad truncation of bitfield values");
struct B {
int n : 3;
constexpr B(int k) : n(k) {}
};
static_assert(B(3).n == 3, "");
static_assert(B(4).n == -4, "");
static_assert(B(7).n == -1, "");
static_assert(B(8).n == 0, "");
static_assert(B(-1).n == -1, "");
static_assert(B(-8889).n == -1, "");
namespace PR16755 {
struct X {
int x : 1;
constexpr static int f(int x) {
return X{x}.x;
}
};
static_assert(X::f(3) == -1, "3 should truncate to -1");
}
}
namespace ZeroSizeTypes {
constexpr int (*p1)[0] = 0, (*p2)[0] = 0;
constexpr int k = p2 - p1;
// expected-error@-1 {{constexpr variable 'k' must be initialized by a constant expression}}
// expected-note@-2 {{subtraction of pointers to type 'int [0]' of zero size}}
int arr[5][0];
constexpr int f() { // expected-error {{never produces a constant expression}}
return &arr[3] - &arr[0]; // expected-note {{subtraction of pointers to type 'int [0]' of zero size}}
}
}
namespace BadDefaultInit {
template<int N> struct X { static const int n = N; };
struct A {
int k = // expected-error {{cannot use defaulted default constructor of 'A' within the class outside of member functions because 'k' has an initializer}}
X<A().k>::n; // expected-error {{not a constant expression}} expected-note {{implicit default constructor for 'BadDefaultInit::A' first required here}}
};
// FIXME: The "constexpr constructor must initialize all members" diagnostic
// here is bogus (we discard the k(k) initializer because the parameter 'k'
// has been marked invalid).
struct B { // expected-note 2{{candidate}}
constexpr B( // expected-error {{must initialize all members}} expected-note {{candidate}}
int k = X<B().k>::n) : // expected-error {{no matching constructor}}
k(k) {}
int k; // expected-note {{not initialized}}
};
}
namespace NeverConstantTwoWays {
// If we see something non-constant but foldable followed by something
// non-constant and not foldable, we want the first diagnostic, not the
// second.
constexpr int f(int n) { // expected-error {{never produces a constant expression}}
return (int *)(long)&n == &n ? // expected-note {{reinterpret_cast}}
1 / 0 : // expected-warning {{division by zero}}
0;
}
// FIXME: We should diagnose the cast to long here, not the division by zero.
constexpr int n = // expected-error {{must be initialized by a constant expression}}
(int *)(long)&n == &n ?
1 / 0 : // expected-warning {{division by zero}} expected-note {{division by zero}}
0;
}
namespace PR17800 {
struct A {
constexpr int operator()() const { return 0; }
};
template <typename ...T> constexpr int sink(T ...) {
return 0;
}
template <int ...N> constexpr int run() {
return sink(A()() + N ...);
}
constexpr int k = run<1, 2, 3>();
}
namespace BuiltinStrlen {
constexpr const char *a = "foo\0quux";
constexpr char b[] = "foo\0quux";
constexpr int f() { return 'u'; }
constexpr char c[] = { 'f', 'o', 'o', 0, 'q', f(), 'u', 'x', 0 };
static_assert(__builtin_strlen("foo") == 3, "");
static_assert(__builtin_strlen("foo\0quux") == 3, "");
static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
constexpr bool check(const char *p) {
return __builtin_strlen(p) == 3 &&
__builtin_strlen(p + 1) == 2 &&
__builtin_strlen(p + 2) == 1 &&
__builtin_strlen(p + 3) == 0 &&
__builtin_strlen(p + 4) == 4 &&
__builtin_strlen(p + 5) == 3 &&
__builtin_strlen(p + 6) == 2 &&
__builtin_strlen(p + 7) == 1 &&
__builtin_strlen(p + 8) == 0;
}
static_assert(check(a), "");
static_assert(check(b), "");
static_assert(check(c), "");
constexpr int over1 = __builtin_strlen(a + 9); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
constexpr int over2 = __builtin_strlen(b + 9); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
constexpr int over3 = __builtin_strlen(c + 9); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
constexpr int under1 = __builtin_strlen(a - 1); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
constexpr int under2 = __builtin_strlen(b - 1); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
constexpr int under3 = __builtin_strlen(c - 1); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
// FIXME: The diagnostic here could be better.
constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.
constexpr int bad = __builtin_strlen(d); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
}
namespace PR19010 {
struct Empty {};
struct Empty2 : Empty {};
struct Test : Empty2 {
constexpr Test() {}
Empty2 array[2];
};
void test() { constexpr Test t; }
}
void PR21327(int a, int b) {
static_assert(&a + 1 != &b, ""); // expected-error {{constant expression}}
}
namespace EmptyClass {
struct E1 {} e1;
union E2 {} e2; // expected-note {{here}}
struct E3 : E1 {} e3;
// The defaulted copy constructor for an empty class does not read any
// members. The defaulted copy constructor for an empty union reads the
// object representation.
constexpr E1 e1b(e1);
constexpr E2 e2b(e2); // expected-error {{constant expression}} expected-note{{read of non-const}} expected-note {{in call}}
constexpr E3 e3b(e3);
}
namespace PR21786 {
extern void (*start[])();
extern void (*end[])();
static_assert(&start != &end, ""); // expected-error {{constant expression}}
static_assert(&start != nullptr, "");
struct Foo;
struct Bar {
static const Foo x;
static const Foo y;
};
static_assert(&Bar::x != nullptr, "");
static_assert(&Bar::x != &Bar::y, "");
}
namespace PR21859 {
constexpr int Fun() { return; } // expected-error {{non-void constexpr function 'Fun' should return a value}}
constexpr int Var = Fun(); // expected-error {{constexpr variable 'Var' must be initialized by a constant expression}}
}
struct InvalidRedef {
int f; // expected-note{{previous definition is here}}
constexpr int f(void); // expected-error{{redefinition of 'f'}} expected-warning{{will not be implicitly 'const'}}
};
namespace PR17938 {
template <typename T> constexpr T const &f(T const &x) { return x; }
struct X {};
struct Y : X {};
struct Z : Y { constexpr Z() {} };
static constexpr auto z = f(Z());
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/ms-friend-lookup.cpp
|
// RUN: %clang_cc1 %s -triple i686-pc-win32 -std=c++11 -Wmicrosoft -fms-compatibility -verify
// RUN: not %clang_cc1 %s -triple i686-pc-win32 -std=c++11 -Wmicrosoft -fms-compatibility -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
struct X;
namespace name_at_tu_scope {
struct Y {
friend struct X; // expected-warning-re {{unqualified friend declaration {{.*}} is a Microsoft extension}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:"::"
};
}
namespace enclosing_friend_decl {
struct B;
namespace ns {
struct A {
friend struct B; // expected-warning-re {{unqualified friend declaration {{.*}} is a Microsoft extension}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:"enclosing_friend_decl::"
protected:
A();
};
}
struct B {
static void f() { ns::A x; }
};
}
namespace enclosing_friend_qualified {
struct B;
namespace ns {
struct A {
friend struct enclosing_friend_qualified::B; // Adding name specifiers fixes it.
protected:
A();
};
}
struct B {
static void f() { ns::A x; }
};
}
namespace enclosing_friend_no_tag {
struct B;
namespace ns {
struct A {
friend B; // Removing the tag decl fixes it.
protected:
A();
};
}
struct B {
static void f() { ns::A x; }
};
}
namespace enclosing_friend_func {
void f();
namespace ns {
struct A {
// Amusingly, in MSVC, this declares ns::f(), and doesn't find the outer f().
friend void f();
protected:
A(); // expected-note {{declared protected here}}
};
}
void f() { ns::A x; } // expected-error {{calling a protected constructor of class 'enclosing_friend_func::ns::A'}}
}
namespace test_nns_fixit_hint {
namespace name1 {
namespace name2 {
struct X;
struct name2;
namespace name3 {
struct Y {
friend struct X; // expected-warning-re {{unqualified friend declaration {{.*}} is a Microsoft extension}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:"name1::name2::"
};
}
}
}
}
// A friend declaration injects a forward declaration into the nearest enclosing
// non-member scope.
namespace friend_as_a_forward_decl {
class A {
class Nested {
friend class B;
B *b;
};
B *b;
};
B *global_b;
void f() {
class Local {
friend class Z;
Z *b;
};
Z *b;
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-reinterpret-base-class.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -triple %itanium_abi_triple -verify -Wreinterpret-base-class -Wno-unused-volatile-lvalue %s
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify -Wreinterpret-base-class -Wno-unused-volatile-lvalue %s
// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -triple %itanium_abi_triple -fdiagnostics-parseable-fixits -Wreinterpret-base-class -Wno-unused-volatile-lvalue %s 2>&1 | FileCheck %s
// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -triple %ms_abi_triple -fdiagnostics-parseable-fixits -Wreinterpret-base-class -Wno-unused-volatile-lvalue %s 2>&1 | FileCheck %s
// PR 13824
class A {
};
class DA : public A {
};
class DDA : public DA {
};
class DAo : protected A {
};
class DAi : private A {
};
class DVA : public virtual A {
};
class DDVA : public virtual DA {
};
class DMA : public virtual A, public virtual DA { //expected-warning{{direct base 'A' is inaccessible due to ambiguity:\n class DMA -> class A\n class DMA -> class DA -> class A}}
};
class B;
struct C {
// Do not fail on incompletely-defined classes.
decltype(reinterpret_cast<C *>(0)) foo;
decltype(reinterpret_cast<A *>((C *) 0)) bar;
decltype(reinterpret_cast<C *>((A *) 0)) baz;
};
void reinterpret_not_defined_class(B *b, C *c) {
// Should not fail if class has no definition.
(void)*reinterpret_cast<C *>(b);
(void)*reinterpret_cast<B *>(c);
(void)reinterpret_cast<C &>(*b);
(void)reinterpret_cast<B &>(*c);
}
// Do not fail on erroneous classes with fields of incompletely-defined types.
// Base class is malformed.
namespace BaseMalformed {
struct A; // expected-note {{forward declaration of 'BaseMalformed::A'}}
struct B {
A a; // expected-error {{field has incomplete type 'BaseMalformed::A'}}
};
struct C : public B {} c;
B *b = reinterpret_cast<B *>(&c);
} // end anonymous namespace
// Child class is malformed.
namespace ChildMalformed {
struct A; // expected-note {{forward declaration of 'ChildMalformed::A'}}
struct B {};
struct C : public B {
A a; // expected-error {{field has incomplete type 'ChildMalformed::A'}}
} c;
B *b = reinterpret_cast<B *>(&c);
} // end anonymous namespace
// Base class outside upcast base-chain is malformed.
namespace BaseBaseMalformed {
struct A; // expected-note {{forward declaration of 'BaseBaseMalformed::A'}}
struct Y {};
struct X { A a; }; // expected-error {{field has incomplete type 'BaseBaseMalformed::A'}}
struct B : Y, X {};
struct C : B {} c;
B *p = reinterpret_cast<B*>(&c);
}
namespace InheritanceMalformed {
struct A; // expected-note {{forward declaration of 'InheritanceMalformed::A'}}
struct B : A {}; // expected-error {{base class has incomplete type}}
struct C : B {} c;
B *p = reinterpret_cast<B*>(&c);
}
// Virtual base class outside upcast base-chain is malformed.
namespace VBaseMalformed{
struct A; // expected-note {{forward declaration of 'VBaseMalformed::A'}}
struct X { A a; }; // expected-error {{field has incomplete type 'VBaseMalformed::A'}}
struct B : public virtual X {};
struct C : B {} c;
B *p = reinterpret_cast<B*>(&c);
}
void reinterpret_not_updowncast(A *pa, const A *pca, A &a, const A &ca) {
(void)*reinterpret_cast<C *>(pa);
(void)*reinterpret_cast<const C *>(pa);
(void)*reinterpret_cast<volatile C *>(pa);
(void)*reinterpret_cast<const volatile C *>(pa);
(void)*reinterpret_cast<const C *>(pca);
(void)*reinterpret_cast<const volatile C *>(pca);
(void)reinterpret_cast<C &>(a);
(void)reinterpret_cast<const C &>(a);
(void)reinterpret_cast<volatile C &>(a);
(void)reinterpret_cast<const volatile C &>(a);
(void)reinterpret_cast<const C &>(ca);
(void)reinterpret_cast<const volatile C &>(ca);
}
void reinterpret_pointer_downcast(A *a, const A *ca) {
(void)*reinterpret_cast<DA *>(a);
(void)*reinterpret_cast<const DA *>(a);
(void)*reinterpret_cast<volatile DA *>(a);
(void)*reinterpret_cast<const volatile DA *>(a);
(void)*reinterpret_cast<const DA *>(ca);
(void)*reinterpret_cast<const volatile DA *>(ca);
(void)*reinterpret_cast<DDA *>(a);
(void)*reinterpret_cast<DAo *>(a);
(void)*reinterpret_cast<DAi *>(a);
// expected-warning@+2 {{'reinterpret_cast' to class 'DVA *' from its virtual base 'A *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)*reinterpret_cast<DVA *>(a);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:26}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' to class 'DDVA *' from its virtual base 'A *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)*reinterpret_cast<DDVA *>(a);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:26}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' to class 'DMA *' from its virtual base 'A *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)*reinterpret_cast<DMA *>(a);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:26}:"static_cast"
}
void reinterpret_reference_downcast(A a, A &ra, const A &cra) {
(void)reinterpret_cast<DA &>(a);
(void)reinterpret_cast<const DA &>(a);
(void)reinterpret_cast<volatile DA &>(a);
(void)reinterpret_cast<const volatile DA &>(a);
(void)reinterpret_cast<DA &>(ra);
(void)reinterpret_cast<const DA &>(ra);
(void)reinterpret_cast<volatile DA &>(ra);
(void)reinterpret_cast<const volatile DA &>(ra);
(void)reinterpret_cast<const DA &>(cra);
(void)reinterpret_cast<const volatile DA &>(cra);
(void)reinterpret_cast<DDA &>(a);
(void)reinterpret_cast<DAo &>(a);
(void)reinterpret_cast<DAi &>(a);
// expected-warning@+2 {{'reinterpret_cast' to class 'DVA &' from its virtual base 'A' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)reinterpret_cast<DVA &>(a);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' to class 'DDVA &' from its virtual base 'A' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)reinterpret_cast<DDVA &>(a);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' to class 'DMA &' from its virtual base 'A' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)reinterpret_cast<DMA &>(a);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
}
void reinterpret_pointer_upcast(DA *da, const DA *cda, DDA *dda, DAo *dao,
DAi *dai, DVA *dva, DDVA *ddva, DMA *dma) {
(void)*reinterpret_cast<A *>(da);
(void)*reinterpret_cast<const A *>(da);
(void)*reinterpret_cast<volatile A *>(da);
(void)*reinterpret_cast<const volatile A *>(da);
(void)*reinterpret_cast<const A *>(cda);
(void)*reinterpret_cast<const volatile A *>(cda);
(void)*reinterpret_cast<A *>(dda);
(void)*reinterpret_cast<DA *>(dda);
(void)*reinterpret_cast<A *>(dao);
(void)*reinterpret_cast<A *>(dai);
// expected-warning@+2 {{'reinterpret_cast' from class 'DVA *' to its virtual base 'A *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)*reinterpret_cast<A *>(dva);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:26}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'DDVA *' to its virtual base 'A *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)*reinterpret_cast<A *>(ddva);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:26}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'DDVA *' to its virtual base 'DA *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)*reinterpret_cast<DA *>(ddva);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:26}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'DMA *' to its virtual base 'A *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)*reinterpret_cast<A *>(dma);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:26}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'DMA *' to its virtual base 'DA *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)*reinterpret_cast<DA *>(dma);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:26}:"static_cast"
}
void reinterpret_reference_upcast(DA &da, const DA &cda, DDA &dda, DAo &dao,
DAi &dai, DVA &dva, DDVA &ddva, DMA &dma) {
(void)reinterpret_cast<A &>(da);
(void)reinterpret_cast<const A &>(da);
(void)reinterpret_cast<volatile A &>(da);
(void)reinterpret_cast<const volatile A &>(da);
(void)reinterpret_cast<const A &>(cda);
(void)reinterpret_cast<const volatile A &>(cda);
(void)reinterpret_cast<A &>(dda);
(void)reinterpret_cast<DA &>(dda);
(void)reinterpret_cast<A &>(dao);
(void)reinterpret_cast<A &>(dai);
// expected-warning@+2 {{'reinterpret_cast' from class 'DVA' to its virtual base 'A &' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<A &>(dva);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'DDVA' to its virtual base 'A &' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<A &>(ddva);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'DDVA' to its virtual base 'DA &' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<DA &>(ddva);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'DMA' to its virtual base 'A &' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<A &>(dma);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'DMA' to its virtual base 'DA &' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<DA &>(dma);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
}
struct E {
int x;
};
class F : public E {
virtual int foo() { return x; }
};
class G : public F {
};
class H : public E, public A {
};
class I : virtual public F {
};
typedef const F * K;
typedef volatile K L;
void different_subobject_downcast(E *e, F *f, A *a) {
// expected-warning@+2 {{'reinterpret_cast' to class 'F *' from its base at non-zero offset 'E *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)reinterpret_cast<F *>(e);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' to class 'G *' from its base at non-zero offset 'E *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)reinterpret_cast<G *>(e);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
(void)reinterpret_cast<H *>(e);
// expected-warning@+2 {{'reinterpret_cast' to class 'I *' from its virtual base 'E *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)reinterpret_cast<I *>(e);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
(void)reinterpret_cast<G *>(f);
// expected-warning@+2 {{'reinterpret_cast' to class 'I *' from its virtual base 'F *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)reinterpret_cast<I *>(f);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
#ifdef MSABI
// In MS ABI mode, A is at non-zero offset in H.
// expected-warning@+3 {{'reinterpret_cast' to class 'H *' from its base at non-zero offset 'A *' behaves differently from 'static_cast'}}
// expected-note@+2 {{use 'static_cast'}}
#endif
(void)reinterpret_cast<H *>(a);
// expected-warning@+2 {{'reinterpret_cast' to class 'L' (aka 'const F *volatile') from its base at non-zero offset 'E *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while downcasting}}
(void)reinterpret_cast<L>(e);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
}
void different_subobject_upcast(F *f, G *g, H *h, I *i) {
// expected-warning@+2 {{'reinterpret_cast' from class 'F *' to its base at non-zero offset 'E *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<E *>(f);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
(void)reinterpret_cast<F *>(g);
// expected-warning@+2 {{'reinterpret_cast' from class 'G *' to its base at non-zero offset 'E *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<E *>(g);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
(void)reinterpret_cast<E *>(h);
#ifdef MSABI
// In MS ABI mode, A is at non-zero offset in H.
// expected-warning@+3 {{'reinterpret_cast' from class 'H *' to its base at non-zero offset 'A *' behaves differently from 'static_cast'}}
// expected-note@+2 {{use 'static_cast'}}
#endif
(void)reinterpret_cast<A *>(h);
// expected-warning@+2 {{'reinterpret_cast' from class 'I *' to its virtual base 'F *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<F *>(i);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
// expected-warning@+2 {{'reinterpret_cast' from class 'I *' to its virtual base 'E *' behaves differently from 'static_cast'}}
// expected-note@+1 {{use 'static_cast' to adjust the pointer correctly while upcasting}}
(void)reinterpret_cast<E *>(i);
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:25}:"static_cast"
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/operator-arrow-temporary.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// PR9615
struct Resource {
void doit();
};
template<int x> struct Lock {
~Lock() { int a[x]; } // expected-error {{declared as an array with a negative size}}
Resource* operator->() { return 0; }
};
struct Accessor {
Lock<-1> operator->();
};
// Make sure we try to instantiate the destructor for Lock here
void f() { Accessor acc; acc->doit(); } // expected-note {{requested here}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR9461.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// Don't crash.
template<typename,typename=int,typename=int>struct basic_string;
typedef basic_string<char> string;
template<typename aT,typename,typename oc>
struct basic_string
{
int us;
basic_string(const aT*,const oc&a=int());
int _S_construct();
int _S_construct(int);
_S_construct(); // expected-error {{requires}}
};
template<typename _CharT,typename _Traits,typename _Alloc>
basic_string<_CharT,_Traits,_Alloc>::basic_string(const _CharT* c,const _Alloc&)
:us(_S_construct)
{string a(c);}
struct runtime_error{runtime_error(string);};
struct system_error:runtime_error{ // expected-note {{to match}}
system_error():time_error("" // expected-error 3 {{expected}} expected-note {{to match}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/class-names.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class C { };
C c;
void D(int);
class D {};
void foo()
{
D(5);
class D d;
}
class D; // expected-note {{previous use is here}}
enum D; // expected-error {{use of 'D' with tag type that does not match previous declaration}}
class A * A;
class A * a2;
void bar()
{
A = 0;
}
void C(int);
void bar2()
{
C(17);
}
extern int B;
class B;
class B {};
int B;
enum E { e1_val };
E e1;
void E(int);
void bar3() {
E(17);
}
enum E e2;
enum E2 { E2 };
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/sourceranges.cpp
|
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
template<class T>
class P {
public:
P(T* t) {}
};
namespace foo {
class A { public: A() {} };
enum B {};
typedef int C;
}
// CHECK: VarDecl {{0x[0-9a-fA-F]+}} <line:16:1, col:36> col:15 ImplicitConstrArray 'foo::A [2]'
static foo::A ImplicitConstrArray[2];
int main() {
// CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::A *'
P<foo::A> p14 = new foo::A;
// CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::B *'
P<foo::B> p24 = new foo::B;
// CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::C *'
P<foo::C> pr4 = new foo::C;
}
foo::A getName() {
// CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:10, col:17> 'foo::A'
return foo::A();
}
void destruct(foo::A *a1, foo::A *a2, P<int> *p1) {
// CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:8> '<bound member function type>' ->~A
a1->~A();
// CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:16> '<bound member function type>' ->~A
a2->foo::A::~A();
// CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:13> '<bound member function type>' ->~P
p1->~P<int>();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/linkage-spec.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fsyntax-only -verify -Wretained-language-linkage -DW_RETAINED_LANGUAGE_LINKAGE %s
extern "C" {
extern "C" void f(int);
}
extern "C++" {
extern "C++" int& g(int);
float& g();
}
double& g(double);
void test(int x, double d) {
f(x);
float &f1 = g();
int& i1 = g(x);
double& d1 = g(d);
}
extern "C" int foo;
extern "C" int foo;
extern "C" const int bar;
extern "C" int const bar;
// <rdar://problem/6895431>
extern "C" struct bar d;
extern struct bar e;
extern "C++" {
namespace N0 {
struct X0 {
int foo(int x) { return x; }
};
}
}
// PR5430
namespace pr5430 {
extern "C" void func(void);
}
using namespace pr5430;
extern "C" void pr5430::func(void) { }
// PR5405
int f2(char *)
{
return 0;
}
extern "C"
{
int f2(int)
{
return f2((char *)0);
}
}
namespace PR5405 {
int f2b(char *) {
return 0;
}
extern "C" {
int f2b(int) {
return f2b((char *)0); // ok
}
}
}
// PR6991
extern "C" typedef int (*PutcFunc_t)(int);
// PR7859
extern "C" void pr7859_a(int) {} // expected-note {{previous definition}}
extern "C" void pr7859_a(int) {} // expected-error {{redefinition}}
extern "C" void pr7859_b() {} // expected-note {{previous definition}}
extern "C" void pr7859_b(int) {} // expected-error {{conflicting}}
extern "C" void pr7859_c(short) {} // expected-note {{previous definition}}
extern "C" void pr7859_c(int) {} // expected-error {{conflicting}}
// <rdar://problem/8318976>
extern "C" {
struct s0 {
private:
s0();
s0(const s0 &);
};
}
//PR7754
extern "C++" template <class T> int pr7754(T param);
namespace N {
int value;
}
extern "C++" using N::value;
// PR7076
extern "C" const char *Version_string = "2.9";
extern "C" {
extern const char *Version_string2 = "2.9";
}
namespace PR9162 {
extern "C" {
typedef struct _ArtsSink ArtsSink;
struct _ArtsSink {
int sink;
};
}
int arts_sink_get_type()
{
return sizeof(ArtsSink);
}
}
namespace pr14958 {
namespace js { extern int ObjectClass; }
extern "C" {
namespace js {}
}
int js::ObjectClass;
}
extern "C" void PR16167; // expected-error {{variable has incomplete type 'void'}}
extern void PR16167_0; // expected-error {{variable has incomplete type 'void'}}
// PR7927
enum T_7927 {
E_7927
};
extern "C" void f_pr7927(int);
namespace {
extern "C" void f_pr7927(int);
void foo_pr7927() {
f_pr7927(E_7927);
f_pr7927(0);
::f_pr7927(E_7927);
::f_pr7927(0);
}
}
void bar_pr7927() {
f_pr7927(E_7927);
f_pr7927(0);
::f_pr7927(E_7927);
::f_pr7927(0);
}
namespace PR17337 {
extern "C++" {
class Foo;
extern "C" int bar3(Foo *y);
class Foo {
int x;
friend int bar3(Foo *y);
#ifdef W_RETAINED_LANGUAGE_LINKAGE
// expected-note@-5 {{previous declaration is here}}
// expected-warning@-3 {{retaining previous language linkage}}
#endif
};
extern "C" int bar3(Foo *y) {
return y->x;
}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/MicrosoftCompatibilityNoExceptions.cpp
|
// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility
// expected-no-diagnostics
// PR13153
namespace std {}
class type_info {};
void f() {
(void)typeid(int);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/__null.cpp
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -Wno-null-conversion -fsyntax-only -verify
// RUN: %clang_cc1 -triple i686-unknown-unknown %s -Wno-null-conversion -fsyntax-only -verify
void f() {
int* i = __null;
i = __null;
int i2 = __null;
// Verify statically that __null is the right size
int a[sizeof(typeof(__null)) == sizeof(void*)? 1 : -1];
// Verify that null is evaluated as 0.
int b[__null ? -1 : 1];
}
struct A {};
void g() {
(void)(0 ? __null : A()); // expected-error {{non-pointer operand type 'A' incompatible with NULL}}
(void)(0 ? A(): __null); // expected-error {{non-pointer operand type 'A' incompatible with NULL}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/invalid-template-specifier.cpp
|
// RUN: %clang_cc1 %s -verify -fsyntax-only
// PR4809
// This test is primarily checking that this doesn't crash, not the particular
// diagnostics.
const template basic_istream<char>; // expected-error {{expected unqualified-id}}
namespace S {}
template <class X> class Y {
void x() { S::template y<char>(1); } // expected-error {{does not refer to a template}} \
// expected-error {{unqualified-id}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/i-c-e-cxx.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
// C++-specific tests for integral constant expressions.
const int c = 10;
int ar[c];
struct X0 {
static const int value = static_cast<int>(4.0);
};
void f() {
if (const int value = 17) {
int array[value];
}
}
int a() {
const int t=t; // expected-note {{declared here}} expected-note {{read of object outside its lifetime}}
switch(1) { // expected-warning {{no case matching constant switch condition '1'}}
case t:; // expected-error {{not an integral constant expression}} expected-note {{initializer of 't' is not a constant expression}}
}
}
// PR6206: out-of-line definitions are legit
namespace pr6206 {
class Foo {
public:
static const int kBar;
};
const int Foo::kBar = 20;
char Test() {
char str[Foo::kBar];
str[0] = '0';
return str[0];
}
}
// PR6373: default arguments don't count.
void pr6373(const unsigned x = 0) {
unsigned max = 80 / x;
}
// rdar://9204520
namespace rdar9204520 {
struct A {
static const int B = int(0.75 * 1000 * 1000); // expected-warning {{not a constant expression; folding it to a constant is a GNU extension}}
};
int foo() { return A::B; }
}
// PR11040
const int x = 10;
int* y = reinterpret_cast<const char&>(x); // expected-error {{cannot initialize}}
// This isn't an integral constant expression, but make sure it folds anyway.
struct PR8836 { char _; long long a; }; // expected-warning {{long long}}
int PR8836test[(__typeof(sizeof(int)))&reinterpret_cast<const volatile char&>((((PR8836*)0)->a))]; // expected-warning {{folded to constant array as an extension}} expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
const int nonconst = 1.0; // expected-note {{declared here}}
int arr[nonconst]; // expected-warning {{folded to constant array as an extension}} expected-note {{initializer of 'nonconst' is not a constant expression}}
const int castfloat = static_cast<int>(1.0);
int arr2[castfloat]; // ok
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/alignof.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
// rdar://13784901
struct S0 {
int x;
static const int test0 = __alignof__(x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
static const int test1 = __alignof__(S0::x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
};
struct S1; // expected-note 6 {{forward declaration}}
extern S1 s1;
const int test3 = __alignof__(s1); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
struct S2 {
S2();
S1 &s;
int x;
int test4 = __alignof__(x); // ok
int test5 = __alignof__(s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
};
const int test6 = __alignof__(S2::x);
const int test7 = __alignof__(S2::s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
// Arguably, these should fail like the S1 cases do: the alignment of
// 's2.x' should depend on the alignment of both x-within-S2 and
// s2-within-S3 and thus require 'S3' to be complete. If we start
// doing the appropriate recursive walk to do that, we should make
// sure that these cases don't explode.
struct S3 {
S2 s2;
static const int test8 = __alignof__(s2.x);
static const int test9 = __alignof__(s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
auto test10() -> char(&)[__alignof__(s2.x)];
static const int test11 = __alignof__(S3::s2.x);
static const int test12 = __alignof__(S3::s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
auto test13() -> char(&)[__alignof__(s2.x)];
};
// Same reasoning as S3.
struct S4 {
union {
int x;
};
static const int test0 = __alignof__(x);
static const int test1 = __alignof__(S0::x);
auto test2() -> char(&)[__alignof__(x)];
};
// Regression test for asking for the alignment of a field within an invalid
// record.
struct S5 {
S1 s; // expected-error {{incomplete type}}
int x;
};
const int test8 = __alignof__(S5::x);
long long int test14[2];
static_assert(alignof(test14) == 8, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
// PR19992
static_assert(alignof(int[]) == alignof(int), ""); // ok
namespace alignof_array_expr {
alignas(32) extern int n[];
static_assert(alignof(n) == 32, ""); // expected-warning {{GNU extension}}
template<int> struct S {
static int a[];
};
template<int N> int S<N>::a[N];
// ok, does not complete type of S<-1>::a
static_assert(alignof(S<-1>::a) == alignof(int), ""); // expected-warning {{GNU extension}}
}
template <typename T> void n(T) {
alignas(T) int T1;
char k[__alignof__(T1)];
static_assert(sizeof(k) == alignof(long long), "");
}
template void n(long long);
namespace PR22042 {
template <typename T>
void Fun(T A) {
typedef int __attribute__((__aligned__(A))) T1; // expected-error {{requested alignment is dependent but declaration is not dependent}}
int k1[__alignof__(T1)];
}
template <int N>
struct S {
typedef __attribute__((aligned(N))) int Field[sizeof(N)]; // expected-error {{requested alignment is dependent but declaration is not dependent}}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-cast-align.cpp
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s
// Simple casts.
void test0(char *P) {
char *a; short *b; int *c;
a = (char*) P;
a = static_cast<char*>(P);
a = reinterpret_cast<char*>(P);
typedef char *CharPtr;
a = CharPtr(P);
b = (short*) P; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}}
b = reinterpret_cast<short*>(P);
typedef short *ShortPtr;
b = ShortPtr(P); // expected-warning {{cast from 'char *' to 'ShortPtr' (aka 'short *') increases required alignment from 1 to 2}}
c = (int*) P; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}}
c = reinterpret_cast<int*>(P);
typedef int *IntPtr;
c = IntPtr(P); // expected-warning {{cast from 'char *' to 'IntPtr' (aka 'int *') increases required alignment from 1 to 4}}
}
// Casts from void* are a special case.
void test1(void *P) {
char *a; short *b; int *c;
a = (char*) P;
a = static_cast<char*>(P);
a = reinterpret_cast<char*>(P);
typedef char *CharPtr;
a = CharPtr(P);
b = (short*) P;
b = static_cast<short*>(P);
b = reinterpret_cast<short*>(P);
typedef short *ShortPtr;
b = ShortPtr(P);
c = (int*) P;
c = static_cast<int*>(P);
c = reinterpret_cast<int*>(P);
typedef int *IntPtr;
c = IntPtr(P);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/literal-type.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
static_assert(__is_literal(int), "fail");
static_assert(__is_literal_type(int), "fail"); // alternate spelling for GCC
static_assert(__is_literal(void*), "fail");
enum E { E1 };
static_assert(__is_literal(E), "fail");
static_assert(__is_literal(decltype(E1)), "fail");
typedef int IAR[10];
static_assert(__is_literal(IAR), "fail");
typedef int Vector __attribute__((vector_size(16)));
typedef int VectorExt __attribute__((ext_vector_type(4)));
static_assert(__is_literal(Vector), "fail");
static_assert(__is_literal(VectorExt), "fail");
// C++0x [basic.types]p10:
// A type is a literal type if it is:
// [...]
// -- a class type that has all of the following properties:
// -- it has a trivial destructor
// -- every constructor call and full-expression in the
// brace-or-equal-initializers for non-static data members (if an) is
// a constant expression,
// -- it is an aggregate type or has at least one constexpr constructor
// or constructor template that is not a copy or move constructor, and
// [DR1452 adds class types with trivial default constructors to
// this list]
// -- it has all non-static data members and base classes of literal
// types
struct Empty {};
struct LiteralType {
int x;
E e;
IAR arr;
Empty empty;
int method();
};
struct HasDtor { ~HasDtor(); };
class NonAggregate { int x; };
struct NonLiteral { NonLiteral(); };
struct HasNonLiteralBase : NonLiteral {};
struct HasNonLiteralMember { HasDtor x; };
static_assert(__is_literal(Empty), "fail");
static_assert(__is_literal(LiteralType), "fail");
static_assert(__is_literal(NonAggregate), "fail");
static_assert(!__is_literal(NonLiteral), "fail");
static_assert(!__is_literal(HasDtor), "fail");
static_assert(!__is_literal(HasNonLiteralBase), "fail");
static_assert(!__is_literal(HasNonLiteralMember), "fail");
// DR1361 removes the brace-or-equal-initializer bullet so that we can allow:
extern int f(); // expected-note {{here}}
struct HasNonConstExprMemInit {
int x = f(); // expected-note {{non-constexpr function}}
constexpr HasNonConstExprMemInit() {} // expected-error {{never produces a constant expression}}
constexpr HasNonConstExprMemInit(int y) : x(y) {} // ok
};
static_assert(__is_literal(HasNonConstExprMemInit), "fail");
class HasConstExprCtor {
int x;
public:
constexpr HasConstExprCtor(int x) : x(x) {}
};
template <typename T> class HasConstExprCtorTemplate {
T x;
public:
template <typename U> constexpr HasConstExprCtorTemplate(U y) : x(y) {}
};
template <typename T> class HasConstExprCtorT {
constexpr HasConstExprCtorT(T) {}
};
static_assert(__is_literal(HasConstExprCtor), "fail");
static_assert(__is_literal(HasConstExprCtorTemplate<int>), "fail");
static_assert(__is_literal(HasConstExprCtorT<NonLiteral>), "fail");
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/ambiguous-builtin-unary-operator.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
struct A {
operator int&();
operator long*& ();
};
struct B {
operator long&();
operator int*& ();
};
struct C : B, A { };
void test(C c) {
++c; // expected-error {{use of overloaded operator '++' is ambiguous}}\
// expected-note {{built-in candidate operator++(int &)}} \
// expected-note {{built-in candidate operator++(long &)}} \
// expected-note {{built-in candidate operator++(long *&)}} \
// expected-note {{built-in candidate operator++(int *&)}}
}
struct A1 { operator volatile int&(); };
struct B1 { operator volatile long&(); };
struct C1 : B1, A1 { };
void test(C1 c) {
++c; // expected-error {{use of overloaded operator '++' is ambiguous}} \
// expected-note {{built-in candidate operator++(volatile int &)}} \
// expected-note {{built-in candidate operator++(volatile long &)}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/init-priority-attr.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class Two {
private:
int i, j, k;
public:
static int count;
Two( int ii, int jj ) { i = ii; j = jj; k = count++; };
Two( void ) { i = 0; j = 0; k = count++; };
int eye( void ) { return i; };
int jay( void ) { return j; };
int kay( void ) { return k; };
};
extern Two foo;
extern Two goo;
extern Two coo[];
extern Two koo[];
Two foo __attribute__((init_priority(101))) ( 5, 6 );
Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); // expected-error {{'init_priority' attribute takes one argument}}
Two coo[2] __attribute__((init_priority(3))); // expected-error {{init_priority attribute requires integer constant between 101 and 65535 inclusive}}
Two koo[4] __attribute__((init_priority(1.13))); // expected-error {{'init_priority' attribute requires an integer constant}}
Two func() __attribute__((init_priority(1001))); // expected-error {{'init_priority' attribute only applies to variables}}
int i __attribute__((init_priority(1001))); // expected-error {{can only use 'init_priority' attribute on file-scope definitions of objects of class type}}
int main() {
Two foo __attribute__((init_priority(1001))); // expected-error {{can only use 'init_priority' attribute on file-scope definitions of objects of class type}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/dllexport-pr22591.cpp
|
// RUN: %clang_cc1 -triple i686-windows-gnu -fms-extensions -verify -std=c++03 %s
// RUN: %clang_cc1 -triple i686-windows-gnu -fms-extensions -verify -std=c++11 %s
// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -verify -std=c++03 -DERROR %s
// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -verify -std=c++11 %s
#ifndef ERROR
// expected-no-diagnostics
#endif
struct NonCopyable {
private:
#ifdef ERROR
// expected-note@+2{{declared private here}}
#endif
NonCopyable();
};
#ifdef ERROR
// expected-error@+4{{field of type 'NonCopyable' has private default constructor}}
// expected-note@+3{{implicit default constructor for 'S' first required here}}
// expected-note@+2{{due to 'S' being dllexported; try compiling in C++11 mode}}
#endif
struct __declspec(dllexport) S {
NonCopyable member;
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-dangling-field.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wdangling-field -verify -std=c++11 %s
struct X {
X(int);
};
struct Y {
operator X*();
operator X&();
};
struct S {
int &x, *y; // expected-note {{reference member declared here}} \
// expected-note {{pointer member declared here}}
S(int i)
: x(i), // expected-warning {{binding reference member 'x' to stack allocated parameter 'i'}}
y(&i) {} // expected-warning {{initializing pointer member 'y' with the stack address of parameter 'i'}}
S(int &i) : x(i), y(&i) {} // no-warning: reference parameter
S(int *i) : x(*i), y(i) {} // no-warning: pointer parameter
};
struct S2 {
const X &x; // expected-note {{reference member declared here}}
S2(int i) : x(i) {} // expected-warning {{binding reference member 'x' to a temporary}}
};
struct S3 {
X &x1, *x2;
S3(Y y) : x1(y), x2(y) {} // no-warning: conversion operator
};
template <typename T> struct S4 {
T x; // expected-note {{reference member declared here}}
S4(int i) : x(i) {} // expected-warning {{binding reference member 'x' to stack allocated parameter 'i'}}
};
template struct S4<int>; // no warning from this instantiation
template struct S4<int&>; // expected-note {{in instantiation}}
struct S5 {
const X &x; // expected-note {{here}}
};
S5 s5 = { 0 }; // ok, lifetime-extended
struct S6 {
S5 s5; // expected-note {{here}}
S6() : s5 { 0 } {} // expected-warning {{binding reference subobject of member 's5' to a temporary}}
};
struct S7 : S5 {
S7() : S5 { 0 } {} // expected-warning {{binding reference member 'x' to a temporary}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx11-crashes.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify %s
// rdar://12240916 stack overflow.
namespace rdar12240916 {
struct S2 {
S2(const S2&);
S2();
};
struct S { // expected-note {{not complete}}
S x; // expected-error {{incomplete type}}
S2 y;
};
S foo() {
S s;
return s;
}
struct S3; // expected-note {{forward declaration}}
struct S4 {
S3 x; // expected-error {{incomplete type}}
S2 y;
};
struct S3 {
S4 x;
S2 y;
};
S4 foo2() {
S4 s;
return s;
}
}
// rdar://12542261 stack overflow.
namespace rdar12542261 {
template <class _Tp>
struct check_complete
{
static_assert(sizeof(_Tp) > 0, "Type must be complete.");
};
template<class _Rp>
class function // expected-note 2 {{candidate}}
{
public:
template<class _Fp>
function(_Fp, typename check_complete<_Fp>::type* = 0); // expected-note {{candidate}}
};
void foobar()
{
auto LeftCanvas = new Canvas(); // expected-error {{unknown type name}}
function<void()> m_OnChange = [&, LeftCanvas]() { }; // expected-error {{no viable conversion}}
}
}
namespace b6981007 {
struct S {}; // expected-note 3{{candidate}}
void f() {
S s(1, 2, 3); // expected-error {{no matching}}
for (auto x : s) {
// We used to attempt to evaluate the initializer of this variable,
// and crash because it has an undeduced type.
const int &n(x);
}
}
}
namespace incorrect_auto_type_deduction_for_typo {
struct S {
template <typename T> S(T t) {
(void)sizeof(t);
(void)new auto(t);
}
};
void Foo(S);
void test(int some_number) { // expected-note {{'some_number' declared here}}
auto x = sum_number; // expected-error {{use of undeclared identifier 'sum_number'; did you mean 'some_number'?}}
auto lambda = [x] {};
Foo(lambda);
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/storage-class.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
extern const int PR6495a = 42;
extern int PR6495b = 42; // expected-warning{{'extern' variable has an initializer}}
extern const int PR6495c[] = {42,43,44};
extern struct Test1 {}; // expected-warning {{'extern' is not permitted on a declaration of a type}}
extern "C" struct Test0 { int x; }; // no warning
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/virtual-function-in-union.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
union x {
virtual void f(); // expected-error {{unions cannot have virtual functions}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/switch-implicit-fallthrough-cxx98.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wimplicit-fallthrough %s
// XFAIL: *
// NOTE: This test is marked XFAIL until we come up with a good language design
// for a worfklow to use this warning outside of C++11.
int fallthrough(int n) {
switch (n / 10) {
if (n - 1) {
n = 100;
} else if (n - 2) {
n = 101;
} else if (n - 3) {
n = 102;
}
case -1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
;
case 0: {// expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
}
case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
n += 100 ;
case 3: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
if (n > 0)
n += 200;
case 4: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
if (n < 0)
;
case 5: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
switch (n) {
case 111:
break;
case 112:
break;
case 113:
break ;
}
case 6: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
n += 300;
}
switch (n / 30) {
case 11:
case 12: // no warning here, intended fall-through, no statement between labels
n += 1600;
}
switch (n / 40) {
case 13:
if (n % 2 == 0) {
return 1;
} else {
return 2;
}
case 15: // no warning here, there's no fall-through
n += 3200;
}
switch (n / 50) {
case 17: {
if (n % 2 == 0) {
return 1;
} else {
return 2;
}
}
case 19: { // no warning here, there's no fall-through
n += 6400;
return 3;
}
case 21: { // no warning here, there's no fall-through
break;
}
case 23: // no warning here, there's no fall-through
n += 128000;
break;
case 25: // no warning here, there's no fall-through
break;
}
return n;
}
class ClassWithDtor {
public:
~ClassWithDtor() {}
};
void fallthrough2(int n) {
switch (n) {
case 0:
{
ClassWithDtor temp;
break;
}
default: // no warning here, there's no fall-through
break;
}
}
#define MY_SWITCH(X, Y, Z, U, V) switch (X) { case Y: Z; case U: V; }
#define MY_SWITCH2(X, Y, Z) switch (X) { Y; Z; }
#define MY_CASE(X, Y) case X: Y
#define MY_CASE2(X, Y, U, V) case X: Y; case U: V
int fallthrough_macro1(int n) {
MY_SWITCH(n, 13, n *= 2, 14, break) // expected-warning{{unannotated fall-through between switch labels}}
switch (n + 1) {
MY_CASE(33, n += 2);
MY_CASE(44, break); // expected-warning{{unannotated fall-through between switch labels}}
MY_CASE(55, n += 3);
}
switch (n + 3) {
MY_CASE(333, return 333);
MY_CASE2(444, n += 44, 4444, break); // expected-warning{{unannotated fall-through between switch labels}}
MY_CASE(555, n += 33);
}
MY_SWITCH2(n + 4, MY_CASE(17, n *= 3), MY_CASE(19, break)) // expected-warning{{unannotated fall-through between switch labels}}
MY_SWITCH2(n + 5, MY_CASE(21, break), MY_CASE2(23, n *= 7, 25, break)) // expected-warning{{unannotated fall-through between switch labels}}
return n;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/new-delete-0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple=i686-pc-linux-gnu -std=c++11
using size_t = decltype(sizeof(0));
struct noreturn_t {} constexpr noreturn = {};
void *operator new [[noreturn]] (size_t, noreturn_t);
void operator delete [[noreturn]] (void*, noreturn_t);
void good_news()
{
auto p = new int[2][[]];
auto q = new int[[]][2];
auto r = new int*[[]][2][[]];
auto s = new (int(*[[]])[2][[]]);
}
void bad_news(int *ip)
{
// attribute-specifiers can go almost anywhere in a new-type-id...
auto r = new int[[]{return 1;}()][2]; // expected-error {{expected ']'}}
auto s = new int*[[]{return 1;}()][2]; // expected-error {{expected ']'}}
// ... but not here:
auto t = new (int(*)[[]]); // expected-error {{an attribute list cannot appear here}}
auto u = new (int(*)[[]{return 1;}()][2]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} \
expected-error {{variably modified type}} \
expected-error {{a lambda expression may not appear inside of a constant expression}}
}
void good_deletes()
{
delete [&]{ return (int*)0; }();
}
void bad_deletes()
{
// 'delete []' is always array delete, per [expr.delete]p1.
// FIXME: Give a better diagnostic.
delete []{ return (int*)0; }(); // expected-error {{expected expression}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/friend-out-of-line.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// <rdar://problem/10204947>
namespace N {
class X;
};
class N::X {
template<typename T> friend const T& f(const X&);
friend const int& g(const X&);
friend class Y;
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-bool-conversion.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace BooleanFalse {
int* j = false; // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
void foo(int* i, int *j=(false)) // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
{
foo(false); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
foo((int*)false); // no-warning: explicit cast
foo(0); // no-warning: not a bool, even though its convertible to bool
foo(false == true); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
foo((42 + 24) < 32); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
const bool kFlag = false;
foo(kFlag); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
}
char f(struct Undefined*);
double f(...);
// Ensure that when using false in metaprogramming machinery its conversion
// isn't flagged.
template <int N> struct S {};
S<sizeof(f(false))> s;
}
namespace Function {
void f1();
struct S {
static void f2();
};
extern void f3() __attribute__((weak_import));
struct S2 {
static void f4() __attribute__((weak_import));
};
bool f5();
bool f6(int);
void bar() {
bool b;
b = f1; // expected-warning {{address of function 'f1' will always evaluate to 'true'}} \
expected-note {{prefix with the address-of operator to silence this warning}}
if (f1) {} // expected-warning {{address of function 'f1' will always evaluate to 'true'}} \
expected-note {{prefix with the address-of operator to silence this warning}}
b = S::f2; // expected-warning {{address of function 'S::f2' will always evaluate to 'true'}} \
expected-note {{prefix with the address-of operator to silence this warning}}
if (S::f2) {} // expected-warning {{address of function 'S::f2' will always evaluate to 'true'}} \
expected-note {{prefix with the address-of operator to silence this warning}}
b = f5; // expected-warning {{address of function 'f5' will always evaluate to 'true'}} \
expected-note {{prefix with the address-of operator to silence this warning}} \
expected-note {{suffix with parentheses to turn this into a function call}}
b = f6; // expected-warning {{address of function 'f6' will always evaluate to 'true'}} \
expected-note {{prefix with the address-of operator to silence this warning}}
// implicit casts of weakly imported symbols are ok:
b = f3;
if (f3) {}
b = S2::f4;
if (S2::f4) {}
}
}
namespace Array {
#define GetValue(ptr) ((ptr) ? ptr[0] : 0)
extern int a[] __attribute__((weak));
int b[] = {8,13,21};
struct {
int x[10];
} c;
const char str[] = "text";
void ignore() {
if (a) {}
if (a) {}
(void)GetValue(b);
}
void test() {
if (b) {}
// expected-warning@-1{{address of array 'b' will always evaluate to 'true'}}
if (b) {}
// expected-warning@-1{{address of array 'b' will always evaluate to 'true'}}
if (c.x) {}
// expected-warning@-1{{address of array 'c.x' will always evaluate to 'true'}}
if (str) {}
// expected-warning@-1{{address of array 'str' will always evaluate to 'true'}}
}
}
namespace Pointer {
extern int a __attribute__((weak));
int b;
static int c;
class S {
public:
static int a;
int b;
};
void ignored() {
if (&a) {}
}
void test() {
S s;
if (&b) {}
// expected-warning@-1{{address of 'b' will always evaluate to 'true'}}
if (&c) {}
// expected-warning@-1{{address of 'c' will always evaluate to 'true'}}
if (&s.a) {}
// expected-warning@-1{{address of 's.a' will always evaluate to 'true'}}
if (&s.b) {}
// expected-warning@-1{{address of 's.b' will always evaluate to 'true'}}
if (&S::a) {}
// expected-warning@-1{{address of 'S::a' will always evaluate to 'true'}}
}
}
namespace macros {
#define assert(x) if (x) {}
#define zero_on_null(x) ((x) ? *(x) : 0)
int array[5];
void fun();
int x;
void test() {
assert(array);
assert(array && "expecting null pointer");
// expected-warning@-1{{address of array 'array' will always evaluate to 'true'}}
assert(fun);
assert(fun && "expecting null pointer");
// expected-warning@-1{{address of function 'fun' will always evaluate to 'true'}}
// expected-note@-2 {{prefix with the address-of operator to silence this warning}}
// TODO: warn on assert(&x) while not warning on zero_on_null(&x)
zero_on_null(&x);
assert(zero_on_null(&x));
assert(&x);
assert(&x && "expecting null pointer");
// expected-warning@-1{{address of 'x' will always evaluate to 'true'}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx1y-sized-deallocation.cpp
|
// RUN: %clang_cc1 -std=c++1y -verify %s -fsized-deallocation -fexceptions -fcxx-exceptions
using size_t = decltype(sizeof(0));
void operator delete(void *, size_t) noexcept; // expected-note {{'operator delete' declared here}}
void operator delete[](void *, size_t) noexcept;
void f(void *p, void *q) {
// OK, implicitly declared.
operator delete(p, 8);
operator delete[](q, 12);
static_assert(noexcept(operator delete(p, 8)), "");
static_assert(noexcept(operator delete[](q, 12)), "");
}
void *operator new(size_t bad, size_t idea);
struct S { S() { throw 0; } };
void g() {
new (123) S; // expected-error {{'new' expression with placement arguments refers to non-placement 'operator delete'}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/struct-class-redecl.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
class X; // expected-note 2{{here}}
typedef struct X * X_t; // expected-warning{{previously declared}}
union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
template<typename T> struct Y; // expected-note{{did you mean class here?}}
template<class U> class Y { }; // expected-warning{{previously declared}}
template <typename>
struct Z {
struct Z { // expected-error{{member 'Z' has the same name as its class}}
};
};
class A;
class A; // expected-note{{previous use is here}}
struct A; // expected-warning{{struct 'A' was previously declared as a class}}
class B; // expected-note{{did you mean struct here?}}
class B; // expected-note{{previous use is here}}\
// expected-note{{did you mean struct here?}}
struct B; // expected-warning{{struct 'B' was previously declared as a class}}
struct B {}; // expected-warning{{'B' defined as a struct here but previously declared as a class}}
class C; // expected-note{{previous use is here}}
struct C; // expected-warning{{struct 'C' was previously declared as a class}}\
// expected-note{{previous use is here}}\
// expected-note{{did you mean class here?}}
class C; // expected-warning{{class 'C' was previously declared as a struct}}\
// expected-note{{previous use is here}}
struct C; // expected-warning{{struct 'C' was previously declared as a class}}\
// expected-note{{did you mean class here?}}
class C {}; // expected-warning{{'C' defined as a class here but previously declared as a struct}}
struct D {}; // expected-note{{previous definition is here}}\
// expected-note{{previous use is here}}
class D {}; // expected-error{{redefinition of 'D'}}
struct D;
class D; // expected-warning{{class 'D' was previously declared as a struct}}\
// expected-note{{did you mean struct here?}}
class E;
class E;
class E {};
class E;
struct F;
struct F;
struct F {};
struct F;
template<class U> class G; // expected-note{{previous use is here}}\
// expected-note{{did you mean struct here?}}
template<class U> struct G; // expected-warning{{struct template 'G' was previously declared as a class template}}
template<class U> struct G {}; // expected-warning{{'G' defined as a struct template here but previously declared as a class template}}
/*
*** 'X' messages ***
CHECK: warning: struct 'X' was previously declared as a class
CHECK: {{^}}typedef struct X * X_t;
CHECK: {{^}} ^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class X;
CHECK: {{^}} ^{{$}}
CHECK: error: use of 'X' with tag type that does not match previous declaration
CHECK: {{^}}union X { int x; float y; };
CHECK: {{^}}^~~~~{{$}}
CHECK: {{^}}class{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class X;
CHECK: {{^}} ^{{$}}
*** 'Y' messages ***
CHECK: warning: 'Y' defined as a class template here but
previously declared as a struct template
CHECK: {{^}}template<class U> class Y { };
CHECK: {{^}} ^{{$}}
CHECK: note: did you mean class here?
CHECK: {{^}}template<typename T> struct Y;
CHECK: {{^}} ^~~~~~{{$}}
CHECK: {{^}} class{{$}}
*** 'A' messages ***
CHECK: warning: struct 'A' was previously declared as a class
CHECK: {{^}}struct A;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class A;
CHECK: {{^}} ^{{$}}
*** 'B' messages ***
CHECK: warning: struct 'B' was previously declared as a class
CHECK: {{^}}struct B;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class B;
CHECK: {{^}} ^{{$}}
CHECK: 'B' defined as a struct here but previously declared as a class
CHECK: {{^}}struct B {};
CHECK: {{^}}^{{$}}
CHECK: note: did you mean struct here?
CHECK: {{^}}class B;
CHECK: {{^}}^~~~~{{$}}
CHECK: {{^}}struct{{$}}
CHECK: note: did you mean struct here?
CHECK: {{^}}class B;
CHECK: {{^}}^~~~~{{$}}
CHECK: {{^}}struct{{$}}
*** 'C' messages ***
CHECK: warning: struct 'C' was previously declared as a class
CHECK: {{^}}struct C;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class C;
CHECK: {{^}} ^{{$}}
CHECK: warning: class 'C' was previously declared as a struct
CHECK: {{^}}class C;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}struct C;
CHECK: {{^}} ^{{$}}
CHECK: warning: struct 'C' was previously declared as a class
CHECK: {{^}}struct C;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class C;
CHECK: {{^}} ^{{$}}
CHECK: warning: 'C' defined as a class here but previously declared as a struct
CHECK: {{^}}class C {};
CHECK: {{^}}^{{$}}
CHECK: note: did you mean class here?
CHECK: {{^}}struct C;
CHECK: {{^}}^~~~~~{{$}}
CHECK: {{^}}class{{$}}
CHECK: note: did you mean class here?
CHECK: {{^}}struct C;
CHECK: {{^}}^~~~~~{{$}}
CHECK: {{^}}class{{$}}
*** 'D' messages ***
CHECK: error: redefinition of 'D'
CHECK: {{^}}class D {};
CHECK: {{^}} ^{{$}}
CHECK: note: previous definition is here
CHECK: {{^}}struct D {};
CHECK: {{^}} ^{{$}}
CHECK: warning: class 'D' was previously declared as a struct
CHECK: {{^}}class D;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}struct D {};
CHECK: {{^}} ^{{$}}
CHECK: note: did you mean struct here?
CHECK: {{^}}class D;
CHECK: {{^}}^~~~~{{$}}
CHECK: {{^}}struct{{$}}
*** 'E' messages ***
*** 'F' messages ***
*** 'G' messages ***
CHECK: warning: struct template 'G' was previously declared as a class template
CHECK: {{^}}template<class U> struct G;
CHECK: {{^}} ^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}template<class U> class G;
CHECK: {{^}} ^{{$}}
CHECK: warning: 'G' defined as a struct template here but previously declared as a class template
CHECK: {{^}}template<class U> struct G {};
CHECK: {{^}} ^{{$}}
CHECK: note: did you mean struct here?
CHECK: {{^}}template<class U> class G;
CHECK: {{^}} ^~~~~
CHECK: {{^}} struct
*/
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/static-data-member.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -w %s
struct ABC {
static double a;
static double b;
static double c;
static double d;
static double e;
static double f;
};
double ABC::a = 1.0;
extern double ABC::b = 1.0; // expected-error {{static data member definition cannot specify a storage class}}
static double ABC::c = 1.0; // expected-error {{'static' can only be specified inside the class definition}}
__private_extern__ double ABC::d = 1.0; // expected-error {{static data member definition cannot specify a storage class}}
auto double ABC::e = 1.0; // expected-error {{static data member definition cannot specify a storage class}}
register double ABC::f = 1.0; // expected-error {{static data member definition cannot specify a storage class}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/ms_struct.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple i686-apple-darwin9 -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple armv7-apple-darwin9 -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -DTEST_FOR_ERROR -verify -triple armv7-apple-darwin9 -std=c++11 %s
#pragma ms_struct on
struct A {
unsigned long a:4;
unsigned char b;
};
struct B : public A {
#ifdef TEST_FOR_ERROR
// expected-error@-2 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
#else
// expected-warning@-4 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
#endif
unsigned long c:16;
int d;
B();
};
static_assert(__builtin_offsetof(B, d) == 12,
"We can't allocate the bitfield into the padding under ms_struct");
// rdar://16178895
struct C {
#ifdef TEST_FOR_ERROR
// expected-error@-2 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
#else
// expected-warning@-4 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
#endif
virtual void foo();
long long n;
};
static_assert(__builtin_offsetof(C, n) == 8,
"long long field in ms_struct should be 8-byte aligned");
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/qualified-names-diag.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace foo {
namespace wibble {
struct x { int y; };
namespace bar {
namespace wonka {
struct x {
struct y { };
};
}
}
}
}
namespace bar {
typedef int y;
struct incomplete; // expected-note{{forward declaration of 'bar::incomplete'}}
}
void test() {
foo::wibble::x a;
::bar::y b;
a + b; // expected-error{{invalid operands to binary expression ('foo::wibble::x' and '::bar::y' (aka 'int'))}}
::foo::wibble::bar::wonka::x::y c;
c + b; // expected-error{{invalid operands to binary expression ('::foo::wibble::bar::wonka::x::y' and '::bar::y' (aka 'int'))}}
(void)sizeof(bar::incomplete); // expected-error{{invalid application of 'sizeof' to an incomplete type 'bar::incomplete'}}
}
int ::foo::wibble::bar::wonka::x::y::* ptrmem;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-unused-filescoped.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++11 %s
#ifdef HEADER
static void headerstatic() {} // expected-warning{{unused}}
static inline void headerstaticinline() {}
namespace {
void headeranon() {} // expected-warning{{unused}}
inline void headerinlineanon() {}
}
namespace test7
{
template<typename T>
static inline void foo(T) { }
// This should not emit an unused-function warning since it inherits
// the static storage type from the base template.
template<>
inline void foo(int) { }
// Partial specialization
template<typename T, typename U>
static inline void bar(T, U) { }
template<typename U>
inline void bar(int, U) { }
template<>
inline void bar(int, int) { }
};
namespace pr19713 {
#if __cplusplus >= 201103L
static constexpr int constexpr1() { return 1; }
constexpr int constexpr2() { return 2; }
#endif
}
#else
#define HEADER
#include "warn-unused-filescoped.cpp"
static void f1(); // expected-warning{{unused}}
namespace {
void f2(); // expected-warning{{unused}}
void f3() { } // expected-warning{{unused}}
struct S {
void m1() { } // expected-warning{{unused}}
void m2(); // expected-warning{{unused}}
void m3();
S(const S&);
void operator=(const S&);
};
template <typename T>
struct TS {
void m();
};
template <> void TS<int>::m() { } // expected-warning{{unused}}
template <typename T>
void tf() { }
template <> void tf<int>() { } // expected-warning{{unused}}
struct VS {
virtual void vm() { }
};
struct SVS : public VS {
void vm() { }
};
}
void S::m3() { } // expected-warning{{unused}}
static inline void f4() { } // expected-warning{{unused}}
const unsigned int cx = 0; // expected-warning{{unused}}
const unsigned int cy = 0;
int f5() { return cy; }
static int x1; // expected-warning{{unused}}
namespace {
int x2; // expected-warning{{unused}}
struct S2 {
static int x; // expected-warning{{unused}}
};
template <typename T>
struct TS2 {
static int x;
};
template <> int TS2<int>::x; // expected-warning{{unused}}
}
namespace PR8841 {
// Ensure that friends of class templates are considered to have a dependent
// context and not marked unused.
namespace {
template <typename T> struct X {
friend bool operator==(const X&, const X&) { return false; }
};
}
template <typename T> void template_test(X<T> x) {
(void)(x == x);
}
void test() {
X<int> x;
template_test(x);
}
}
namespace test4 {
namespace { struct A {}; }
void test(A a); // expected-warning {{unused function}}
extern "C" void test4(A a);
}
namespace rdar8733476 {
static void foo() { } // expected-warning {{not needed and will not be emitted}}
template <int>
void bar() {
foo();
}
}
namespace test5 {
static int n = 0;
static int &r = n;
int f(int &);
int k = f(r);
// FIXME: We should produce warnings for both of these.
static const int m = n;
int x = sizeof(m);
static const double d = 0.0; // expected-warning{{not needed and will not be emitted}}
int y = sizeof(d);
}
namespace unused_nested {
class outer {
void func1();
struct {
void func2() {
}
} x;
};
}
namespace unused {
struct {
void func() { // expected-warning {{unused member function}}
}
} x; // expected-warning {{unused variable}}
}
namespace test6 {
typedef struct {
void bar();
} A;
typedef struct {
void bar(); // expected-warning {{unused member function 'bar'}}
} *B;
struct C {
void bar();
};
}
namespace pr14776 {
namespace {
struct X {};
}
X a = X(); // expected-warning {{unused variable 'a'}}
auto b = X(); // expected-warning {{unused variable 'b'}}
}
namespace UndefinedInternalStaticMember {
namespace {
struct X {
static const unsigned x = 3;
int y[x];
};
}
}
namespace test8 {
static void func();
void bar() { void func() __attribute__((used)); }
static void func() {}
}
namespace pr19713 {
#if __cplusplus >= 201103L
// FIXME: We should warn on both of these.
static constexpr int constexpr3() { return 1; } // expected-warning {{unused}}
constexpr int constexpr4() { return 2; }
#endif
}
#endif
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/copy-assignment.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct A {
};
struct ConvertibleToA {
operator A();
};
struct ConvertibleToConstA {
operator const A();
};
struct B {
B& operator=(B&); // expected-note 4 {{candidate function}}
};
struct ConvertibleToB {
operator B();
};
struct ConvertibleToBref {
operator B&();
};
struct ConvertibleToConstB {
operator const B();
};
struct ConvertibleToConstBref {
operator const B&();
};
struct C {
int operator=(int); // expected-note{{candidate function}}
long operator=(long); // expected-note{{candidate function}}
int operator+=(int); // expected-note{{candidate function}}
int operator+=(long); // expected-note{{candidate function}}
};
struct D {
D& operator+=(const D &);
};
struct ConvertibleToInt {
operator int();
};
void test() {
A a, na;
const A constA = A();
ConvertibleToA convertibleToA;
ConvertibleToConstA convertibleToConstA;
B b, nb;
const B constB = B();
ConvertibleToB convertibleToB;
ConvertibleToBref convertibleToBref;
ConvertibleToConstB convertibleToConstB;
ConvertibleToConstBref convertibleToConstBref;
C c, nc;
const C constC = C();
D d, nd;
const D constD = D();
ConvertibleToInt convertibleToInt;
na = a;
na = constA;
na = convertibleToA;
na = convertibleToConstA;
na += a; // expected-error{{no viable overloaded '+='}}
nb = b;
nb = constB; // expected-error{{no viable overloaded '='}}
nb = convertibleToB; // expected-error{{no viable overloaded '='}}
nb = convertibleToBref;
nb = convertibleToConstB; // expected-error{{no viable overloaded '='}}
nb = convertibleToConstBref; // expected-error{{no viable overloaded '='}}
nc = c;
nc = constC;
nc = 1;
nc = 1L;
nc = 1.0; // expected-error{{use of overloaded operator '=' is ambiguous}}
nc += 1;
nc += 1L;
nc += 1.0; // expected-error{{use of overloaded operator '+=' is ambiguous}}
nd = d;
nd += d;
nd += constD;
int i;
i = convertibleToInt;
i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}}
}
// <rdar://problem/8315440>: Don't crash
namespace test1 {
template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}}
A(UndeclaredType n) : X(n) {} // expected-error {{unknown type name 'UndeclaredType'}}
};
template<typename T> class B : public A<T> {
virtual void foo() {}
};
extern template class A<char>;
extern template class B<char>;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR10243.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
struct S; // expected-note 4{{forward declaration of 'S'}}
struct T0 {
S s; // expected-error{{field has incomplete type 'S'}}
T0() = default;
};
struct T1 {
S s; // expected-error{{field has incomplete type 'S'}}
T1(const T1&) = default;
};
struct T2 {
S s; // expected-error{{field has incomplete type 'S'}}
T2& operator=(const T2&) = default;
};
struct T3 {
S s; // expected-error{{field has incomplete type 'S'}}
~T3() = default;
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-weakref.cpp
|
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify -std=c++11 %s
// GCC will accept anything as the argument of weakref. Should we
// check for an existing decl?
static int a1() __attribute__((weakref ("foo")));
static int a2() __attribute__((weakref, alias ("foo")));
static int a3 __attribute__((weakref ("foo")));
static int a4 __attribute__((weakref, alias ("foo")));
// gcc rejects, clang accepts
static int a5 __attribute__((alias ("foo"), weakref));
// this is pointless, but accepted by gcc. We reject it.
static int a6 __attribute__((weakref)); //expected-error {{weakref declaration of 'a6' must also have an alias attribute}}
// gcc warns, clang rejects
void f(void) {
static int a __attribute__((weakref ("v2"))); // expected-error {{declaration of 'a' must be in a global context}}
}
// both gcc and clang reject
class c {
static int a __attribute__((weakref ("v2"))); // expected-error {{declaration of 'a' must be in a global context}}
static int b() __attribute__((weakref ("f3"))); // expected-error {{declaration of 'b' must be in a global context}}
};
int a7() __attribute__((weakref ("f1"))); // expected-error {{weakref declaration must have internal linkage}}
int a8 __attribute__((weakref ("v1"))); // expected-error {{weakref declaration must have internal linkage}}
// gcc accepts this
int a9 __attribute__((weakref)); // expected-error {{weakref declaration of 'a9' must also have an alias attribute}}
static int a10();
int a10() __attribute__((weakref ("foo")));
static int v __attribute__((weakref(a1), alias("foo"))); // expected-error {{'weakref' attribute requires a string}}
__attribute__((weakref ("foo"))) auto a11 = 1; // expected-error {{weakref declaration must have internal linkage}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-cleanup-gcc.cpp
|
// RUN: %clang_cc1 %s -verify -fsyntax-only -Wgcc-compat
namespace N {
void c1(int *a) {}
}
void c2(int *a) {}
template <typename Ty>
void c3(Ty *a) {}
void t3() {
int v1 __attribute__((cleanup(N::c1))); // expected-warning {{GCC does not allow the 'cleanup' attribute argument to be anything other than a simple identifier}}
int v2 __attribute__((cleanup(c2)));
int v3 __attribute__((cleanup(c3<int>))); // expected-warning {{GCC does not allow the 'cleanup' attribute argument to be anything other than a simple identifier}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/switch-implicit-fallthrough-blocks.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 -Wimplicit-fallthrough %s
void fallthrough_in_blocks() {
void (^block)() = ^{
int x = 0;
switch (x) {
case 0:
x++;
[[clang::fallthrough]]; // no diagnostics
case 1:
x++;
default: // \
expected-warning{{unannotated fall-through between switch labels}} \
expected-note{{insert 'break;' to avoid fall-through}}
break;
}
};
block();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/bitfield-layout.cpp
|
// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-apple-darwin10
#define CHECK_SIZE(name, size) extern int name##1[sizeof(name) == size ? 1 : -1];
#define CHECK_ALIGN(name, size) extern int name##2[__alignof(name) == size ? 1 : -1];
// Simple tests.
struct Test1 {
char c : 9; // expected-warning {{size of bit-field 'c' (9 bits) exceeds the size of its type; value will be truncated to 8 bits}}
};
CHECK_SIZE(Test1, 2);
CHECK_ALIGN(Test1, 1);
struct Test2 {
char c : 16; // expected-warning {{size of bit-field 'c' (16 bits) exceeds the size of its type; value will be truncated to 8 bits}}
};
CHECK_SIZE(Test2, 2);
CHECK_ALIGN(Test2, 2);
struct Test3 {
char c : 32; // expected-warning {{size of bit-field 'c' (32 bits) exceeds the size of its type; value will be truncated to 8 bits}}
};
CHECK_SIZE(Test3, 4);
CHECK_ALIGN(Test3, 4);
struct Test4 {
char c : 64; // expected-warning {{size of bit-field 'c' (64 bits) exceeds the size of its type; value will be truncated to 8 bits}}
};
CHECK_SIZE(Test4, 8);
CHECK_ALIGN(Test4, 8);
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/uninit-variables.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only -fcxx-exceptions %s -verify -std=c++1y
// Stub out types for 'typeid' to work.
namespace std { class type_info {}; }
int test1_aux(int &x);
int test1() {
int x;
test1_aux(x);
return x; // no-warning
}
int test2_aux() {
int x;
int &y = x;
return x; // no-warning
}
// Don't warn on unevaluated contexts.
void unevaluated_tests() {
int x;
(void)sizeof(x);
(void)typeid(x);
}
// Warn for glvalue arguments to typeid whose type is polymorphic.
struct A { virtual ~A() {} };
void polymorphic_test() {
A *a; // expected-note{{initialize the variable 'a' to silence this warning}}
(void)typeid(*a); // expected-warning{{variable 'a' is uninitialized when used here}}
}
// Handle cases where the CFG may constant fold some branches, thus
// mitigating the need for some path-sensitivity in the analysis.
unsigned test3_aux();
unsigned test3() {
unsigned x = 0;
const bool flag = true;
if (flag && (x = test3_aux()) == 0) {
return x;
}
return x;
}
unsigned test3_b() {
unsigned x ;
const bool flag = true;
if (flag && (x = test3_aux()) == 0) {
x = 1;
}
return x; // no-warning
}
unsigned test3_c() {
unsigned x; // expected-note{{initialize the variable 'x' to silence this warning}}
const bool flag = false;
if (flag && (x = test3_aux()) == 0) {
x = 1;
}
return x; // expected-warning{{variable 'x' is uninitialized when used here}}
}
enum test4_A {
test4_A_a, test_4_A_b
};
test4_A test4() {
test4_A a; // expected-note{{variable 'a' is declared here}}
return a; // expected-warning{{variable 'a' is uninitialized when used here}}
}
// Test variables getting invalidated by function calls with reference arguments
// *AND* there are multiple invalidated arguments.
void test5_aux(int &, int &);
int test5() {
int x, y;
test5_aux(x, y);
return x + y; // no-warning
}
// This test previously crashed Sema.
class Rdar9188004A {
public:
virtual ~Rdar9188004A();
};
template< typename T > class Rdar9188004B : public Rdar9188004A {
virtual double *foo(Rdar9188004B *next) const {
double *values = next->foo(0);
try {
}
catch(double e) {
values[0] = e;
}
return 0;
}
};
class Rdar9188004C : public Rdar9188004B<Rdar9188004A> {
virtual void bar(void) const;
};
void Rdar9188004C::bar(void) const {}
// Don't warn about uninitialized variables in unreachable code.
void PR9625() {
if (false) {
int x;
(void)static_cast<float>(x); // no-warning
}
}
// Don't warn about variables declared in "catch"
void RDar9251392_bar(const char *msg);
void RDar9251392() {
try {
throw "hi";
}
catch (const char* msg) {
RDar9251392_bar(msg); // no-warning
}
}
// Test handling of "no-op" casts.
void test_noop_cast()
{
int x = 1;
int y = (int&)x; // no-warning
}
void test_noop_cast2() {
int x; // expected-note {{initialize the variable 'x' to silence this warning}}
int y = (int&)x; // expected-warning {{uninitialized when used here}}
}
// Test handling of bit casts.
void test_bitcasts() {
int x = 1;
int y = (float &)x; // no-warning
}
void test_bitcasts_2() {
int x; // expected-note {{initialize the variable 'x' to silence this warning}}
int y = (float &)x; // expected-warning {{uninitialized when used here}}
}
void consume_const_ref(const int &n);
int test_const_ref() {
int n; // expected-note {{variable}}
consume_const_ref(n);
return n; // expected-warning {{uninitialized when used here}}
}
// Don't crash here.
auto PR19996 = [a=0]{int t; return a;};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-unavailable.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
int &foo(int); // expected-note {{candidate}}
double &foo(double); // expected-note {{candidate}}
void foo(...) __attribute__((__unavailable__)); // expected-note {{candidate function}} \
// expected-note{{'foo' has been explicitly marked unavailable here}}
void bar(...) __attribute__((__unavailable__)); // expected-note 2{{explicitly marked unavailable}}
void test_foo(short* sp) {
int &ir = foo(1);
double &dr = foo(1.0);
foo(sp); // expected-error{{call to unavailable function 'foo'}}
void (*fp)(...) = &bar; // expected-error{{'bar' is unavailable}}
void (*fp2)(...) = bar; // expected-error{{'bar' is unavailable}}
int &(*fp3)(int) = foo;
void (*fp4)(...) = foo; // expected-error{{'foo' is unavailable}}
}
namespace radar9046492 {
// rdar://9046492
#define FOO __attribute__((unavailable("not available - replaced")))
void foo() FOO; // expected-note {{candidate function has been explicitly made unavailable}}
void bar() {
foo(); // expected-error {{call to unavailable function 'foo': not available - replaced}}
}
}
void unavail(short* sp) __attribute__((__unavailable__));
void unavail(short* sp) {
// No complains inside an unavailable function.
int &ir = foo(1);
double &dr = foo(1.0);
foo(sp);
foo();
}
// Show that delayed processing of 'unavailable' is the same
// delayed process for 'deprecated'.
// <rdar://problem/12241361> and <rdar://problem/15584219>
enum DeprecatedEnum { DE_A, DE_B } __attribute__((deprecated)); // expected-note {{'DeprecatedEnum' has been explicitly marked deprecated here}}
__attribute__((deprecated)) typedef enum DeprecatedEnum DeprecatedEnum;
typedef enum DeprecatedEnum AnotherDeprecatedEnum; // expected-warning {{'DeprecatedEnum' is deprecated}}
__attribute__((deprecated))
DeprecatedEnum testDeprecated(DeprecatedEnum X) { return X; }
enum UnavailableEnum { UE_A, UE_B } __attribute__((unavailable)); // expected-note {{'UnavailableEnum' has been explicitly marked unavailable here}}
__attribute__((unavailable)) typedef enum UnavailableEnum UnavailableEnum;
typedef enum UnavailableEnum AnotherUnavailableEnum; // expected-error {{'UnavailableEnum' is unavailable}}
__attribute__((unavailable))
UnavailableEnum testUnavailable(UnavailableEnum X) { return X; }
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/static-initializers.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
int f() {
return 10;
}
void g() {
static int a = f();
}
static int b = f();
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/generalized-deprecated.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -fms-extensions -Wno-deprecated %s
// NOTE: use -Wno-deprecated to avoid cluttering the output with deprecated
// warnings
[[deprecated("1")]] int function_1();
// expected-warning@-1 {{use of the 'deprecated' attribute is a C++14 extension}}
[[gnu::deprecated("3")]] int function_3();
int __attribute__ (( deprecated("2") )) function_2();
__declspec(deprecated("4")) int function_4();
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/shift.cpp
|
// RUN: %clang_cc1 -Wall -Wshift-sign-overflow -ffreestanding -fsyntax-only -verify %s
#include <limits.h>
#define WORD_BIT (sizeof(int) * CHAR_BIT)
template <int N> void f() {
(void)(N << 30); // expected-warning {{bits to represent, but 'int' only has}}
(void)(30 << N); // expected-warning {{bits to represent, but 'int' only has}}
}
void test() {
f<30>(); // expected-note {{instantiation}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/virtuals.cpp
|
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 %s
class A {
virtual void f();
virtual void g() = 0; // expected-note{{unimplemented pure virtual method 'g' in 'A'}}
void h() = 0; // expected-error {{'h' is not virtual and cannot be declared pure}}
void i() = 1; // expected-error {{initializer on function does not look like a pure-specifier}}
void j() = 0u; // expected-error {{initializer on function does not look like a pure-specifier}}
void k();
public:
A(int);
};
virtual void A::k() { } // expected-error{{'virtual' can only be specified inside the class definition}}
class B : public A {
// Needs to recognize that overridden function is virtual.
void g() = 0;
// Needs to recognize that function does not override.
void g(int) = 0; // expected-error{{'g' is not virtual and cannot be declared pure}}
};
// Needs to recognize invalid uses of abstract classes.
A fn(A) // expected-error{{parameter type 'A' is an abstract class}} \
// expected-error{{return type 'A' is an abstract class}}
{
A a; // expected-error{{variable type 'A' is an abstract class}}
(void)static_cast<A>(0); // expected-error{{allocating an object of abstract class type 'A'}}
try {
} catch(A) { // expected-error{{variable type 'A' is an abstract class}}
}
}
namespace rdar9670557 {
typedef int func(int);
func *a();
struct X {
virtual func f = 0;
virtual func (g) = 0;
func *h = 0;
};
}
namespace pr8264 {
struct Test {
virtual virtual void func(); // expected-warning {{duplicate 'virtual' declaration specifier}}
};
}
namespace VirtualFriend {
// DR (filed but no number yet): reject meaningless pure-specifier on a friend declaration.
struct A { virtual int f(); };
struct B { friend int A::f() = 0; }; // expected-error {{friend declaration cannot have a pure-specifier}}
struct C {
virtual int f();
friend int C::f() = 0; // expected-error {{friend declaration cannot have a pure-specifier}}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
|
// RUN: %clang_cc1 -std=c++0x -fsyntax-only -fexceptions -verify %s
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 objects {
struct X1 { X1(int); };
struct X2 { explicit X2(int); }; // expected-note {{constructor declared here}}
template <int N>
struct A {
A() { static_assert(N == 0, ""); }
A(int, double) { static_assert(N == 1, ""); }
};
template <int N>
struct F {
F() { static_assert(N == 0, ""); }
F(int, double) { static_assert(N == 1, ""); }
F(std::initializer_list<int>) { static_assert(N == 3, ""); }
};
template <int N>
struct D {
D(std::initializer_list<int>) { static_assert(N == 0, ""); } // expected-note 1 {{candidate}}
D(std::initializer_list<double>) { static_assert(N == 1, ""); } // expected-note 1 {{candidate}}
};
template <int N>
struct E {
E(int, int) { static_assert(N == 0, ""); }
E(X1, int) { static_assert(N == 1, ""); }
};
void overload_resolution() {
{ A<0> a{}; }
{ A<0> a = {}; }
{ A<1> a{1, 1.0}; }
{ A<1> a = {1, 1.0}; }
{ F<0> f{}; }
{ F<0> f = {}; }
// Narrowing conversions don't affect viability. The next two choose
// the initializer_list constructor.
{ F<3> f{1, 1.0}; } // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
{ F<3> f = {1, 1.0}; } // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
{ F<3> f{1, 2, 3, 4, 5, 6, 7, 8}; }
{ F<3> f = {1, 2, 3, 4, 5, 6, 7, 8}; }
{ F<3> f{1, 2, 3, 4, 5, 6, 7, 8}; }
{ F<3> f{1, 2}; }
{ D<0> d{1, 2, 3}; }
{ D<1> d{1.0, 2.0, 3.0}; }
{ D<-1> d{1, 2.0}; } // expected-error {{ambiguous}}
{ E<0> e{1, 2}; }
}
void explicit_implicit() {
{ X1 x{0}; }
{ X1 x = {0}; }
{ X2 x{0}; }
{ X2 x = {0}; } // expected-error {{constructor is explicit}}
}
struct C {
C();
C(int, double);
C(int, int);
int operator[](C);
};
C function_call() {
void takes_C(C);
takes_C({1, 1.0});
C c;
c[{1, 1.0}];
return {1, 1.0};
}
void inline_init() {
(void) C{1, 1.0};
(void) new C{1, 1.0};
(void) A<1>{1, 1.0};
(void) new A<1>{1, 1.0};
}
struct B { // expected-note 2 {{candidate constructor}}
B(C, int, C); // expected-note {{candidate constructor not viable: cannot convert initializer list argument to 'objects::C'}}
};
void nested_init() {
B b1{{1, 1.0}, 2, {3, 4}};
B b2{{1, 1.0, 4}, 2, {3, 4}}; // expected-error {{no matching constructor for initialization of 'objects::B'}}
}
void overloaded_call() {
one ov1(B); // expected-note {{not viable: cannot convert initializer list}}
two ov1(C); // expected-note {{not viable: cannot convert initializer list}}
static_assert(sizeof(ov1({})) == sizeof(two), "bad overload");
static_assert(sizeof(ov1({1, 2})) == sizeof(two), "bad overload");
static_assert(sizeof(ov1({{1, 1.0}, 2, {3, 4}})) == sizeof(one), "bad overload");
ov1({1}); // expected-error {{no matching function}}
one ov2(int);
two ov2(F<3>);
// expected-warning@+1 {{braces around scalar initializer}}
static_assert(sizeof(ov2({1})) == sizeof(one), "bad overload"); // list -> int ranks as identity
static_assert(sizeof(ov2({1, 2, 3})) == sizeof(two), "bad overload"); // list -> F only viable
}
struct G { // expected-note 6 {{not viable}}
// This is not an initializer-list constructor.
template<typename ...T>
G(std::initializer_list<int>, T ...); // expected-note 3 {{not viable}}
};
struct H { // expected-note 6 {{not viable}}
explicit H(int, int); // expected-note 3 {{not viable}} expected-note {{declared here}}
H(int, void*); // expected-note 3 {{not viable}}
};
void edge_cases() {
// invalid (the first phase only considers init-list ctors)
// (for the second phase, no constructor is viable)
G g1{1, 2, 3}; // expected-error {{no matching constructor}}
(void) new G{1, 2, 3}; // expected-error {{no matching constructor}}
(void) G{1, 2, 3} // expected-error {{no matching constructor}}
// valid (T deduced to <>).
G g2({1, 2, 3});
(void) new G({1, 2, 3});
(void) G({1, 2, 3});
// invalid
H h1({1, 2}); // expected-error {{no matching constructor}}
(void) new H({1, 2}); // expected-error {{no matching constructor}}
// FIXME: Bad diagnostic, mentions void type instead of init list.
(void) H({1, 2}); // expected-error {{no matching conversion}}
// valid (by copy constructor).
H h2({1, nullptr});
(void) new H({1, nullptr});
(void) H({1, nullptr});
// valid
H h3{1, 2};
(void) new H{1, 2};
(void) H{1, 2};
}
struct memberinit {
H h1{1, nullptr};
H h2 = {1, nullptr};
H h3{1, 1};
H h4 = {1, 1}; // expected-error {{constructor is explicit}}
};
}
namespace PR12092 {
struct S {
S(const char*);
};
struct V {
template<typename T> V(T, T);
void f(std::initializer_list<S>);
void f(const V &);
};
void g() {
extern V s;
s.f({"foo", "bar"});
}
}
namespace PR12117 {
struct A { A(int); };
struct B { B(A); } b{{0}}; //FIXME: non-conformant. Temporary fix until standard resolution.
// expected- error {{call to constructor of 'struct B' is ambiguous}} \
// expected- note 2{{candidate is the implicit}} \
// expected- note {{candidate constructor}}
struct C { C(int); } c{0};
}
namespace PR12167 {
template<int N> struct string {};
struct X {
X(const char v);
template<typename T> bool operator()(T) const;
};
template<int N, class Comparator> bool g(const string<N>& s, Comparator cmp) {
return cmp(s);
}
template<int N> bool f(const string<N> &s) {
return g(s, X{'x'});
}
bool s = f(string<1>());
}
namespace PR12257_PR12241 {
struct command_pair
{
command_pair(int, int);
};
struct command_map
{
command_map(std::initializer_list<command_pair>);
};
struct generator_pair
{
generator_pair(const command_map);
};
// 5 levels: init list, gen_pair, command_map, init list, command_pair
const std::initializer_list<generator_pair> x = {{{{{3, 4}}}}};
// 4 levels: init list, gen_pair, command_map via init list, command_pair
const std::initializer_list<generator_pair> y = {{{{1, 2}}}};
}
namespace PR12120 {
struct A { explicit A(int); A(float); }; // expected-note {{declared here}}
A a = { 0 }; // expected-error {{constructor is explicit}}
struct B { explicit B(short); B(long); }; // expected-note 2 {{candidate}}
B b = { 0 }; // expected-error {{ambiguous}}
}
namespace PR12498 {
class ArrayRef; // expected-note{{forward declaration}}
struct C {
void foo(const ArrayRef&); // expected-note{{passing argument to parameter here}}
};
static void bar(C* c)
{
c->foo({ nullptr, 1 }); // expected-error{{initialization of incomplete type 'const PR12498::ArrayRef'}}
}
}
namespace explicit_default {
struct A {
explicit A(); // expected-note{{here}}
};
A a {}; // ok
// This is copy-list-initialization, and we choose an explicit constructor
// (even though we do so via value-initialization), so the initialization is
// ill-formed.
A b = {}; // expected-error{{chosen constructor is explicit}}
}
namespace init_list_default {
struct A {
A(std::initializer_list<int>);
};
A a {}; // calls initializer list constructor
struct B {
B();
B(std::initializer_list<int>) = delete;
};
B b {}; // calls default constructor
}
// PR13470, <rdar://problem/11974632>
namespace PR13470 {
struct W {
explicit W(int); // expected-note {{here}}
};
struct X {
X(const X&) = delete; // expected-note 3 {{here}}
X(int);
};
template<typename T, typename Fn> void call(Fn f) {
f({1}); // expected-error {{constructor is explicit}}
f(T{1}); // expected-error {{call to deleted constructor}}
}
void ref_w(const W &); // expected-note 2 {{not viable}}
void call_ref_w() {
ref_w({1}); // expected-error {{no matching function}}
ref_w(W{1});
call<W>(ref_w); // expected-note {{instantiation of}}
}
void ref_x(const X &);
void call_ref_x() {
ref_x({1});
ref_x(X{1});
call<X>(ref_x); // ok
}
void val_x(X); // expected-note 2 {{parameter}}
void call_val_x() {
val_x({1});
val_x(X{1}); // expected-error {{call to deleted constructor}}
call<X>(val_x); // expected-note {{instantiation of}}
}
template<typename T>
struct Y {
X x{1};
void f() { X x{1}; }
void h() {
ref_w({1}); // expected-error {{no matching function}}
ref_w(W{1});
ref_x({1});
ref_x(X{1});
val_x({1});
val_x(X{1}); // expected-error {{call to deleted constructor}}
}
Y() {}
Y(int) : x{1} {}
};
Y<int> yi;
Y<int> yi2(0);
void g() {
yi.f();
yi.h(); // ok, all diagnostics produced in template definition
}
}
namespace PR19729 {
struct A {
A(int);
A(const A&) = delete;
};
struct B {
void *operator new(std::size_t, A);
};
B *p = new ({123}) B;
}
namespace PR11410 {
struct A {
A() = delete; // expected-note 2{{deleted here}}
A(int);
};
A a[3] = {
{1}, {2}
}; // expected-error {{call to deleted constructor}} \
expected-note {{in implicit initialization of array element 2 with omitted initializer}}
struct B {
A a; // expected-note {{in implicit initialization of field 'a'}}
} b = {
}; // expected-error {{call to deleted constructor}}
struct C {
C(int = 0); // expected-note 2{{candidate}}
C(float = 0); // expected-note 2{{candidate}}
};
C c[3] = {
0, 1
}; // expected-error {{ambiguous}} expected-note {{in implicit initialization of array element 2}}
C c2[3] = {
[0] = 1, [2] = 3
}; // expected-error {{ambiguous}} expected-note {{in implicit initialization of array element 1}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/PR21679.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
int w = z.; // expected-error {{use of undeclared identifier 'z'}} \
// expected-error {{expected unqualified-id}}
int x = { y[ // expected-error {{use of undeclared identifier 'y'}} \
// expected-note {{to match this '['}} \
// expected-note {{to match this '{'}} \
// expected-error {{expected ';' after top level declarator}}
// The errors below all occur on the last line of the file, so splitting them
// among multiple lines doesn't work.
// expected-error {{expected expression}} expected-error {{expected ']'}} expected-error {{expected '}'}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/delete-mismatch.h
|
// Header for PCH test delete.cpp
namespace pch_test {
struct X {
int *a;
X();
X(int);
X(bool)
: a(new int[1]) { } // expected-note{{allocated with 'new[]' here}}
~X()
{
delete a; // expected-warning{{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:9}:"[]"
}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/primary-base.cpp
|
// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify %s
// expected-no-diagnostics
class A { virtual void f(); };
class B : virtual A { };
class C : B { };
// Since A is already a primary base class, C should be the primary base class
// of F.
class F : virtual A, virtual C { };
int sa[sizeof(F) == sizeof(A) ? 1 : -1];
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/attr-sentinel.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
void f(int, ...) __attribute__((sentinel));
void g() {
f(1, 2, __null);
}
typedef __typeof__(sizeof(int)) size_t;
struct S {
S(int,...) __attribute__((sentinel)); // expected-note {{marked sentinel}}
void a(int,...) __attribute__((sentinel)); // expected-note {{marked sentinel}}
void* operator new(size_t,...) __attribute__((sentinel)); // expected-note {{marked sentinel}}
void operator()(int,...) __attribute__((sentinel)); // expected-note {{marked sentinel}}
};
void class_test() {
S s(1,2,3); // expected-warning {{missing sentinel in function call}}
S* s2 = new (1,2,3) S(1, __null); // expected-warning {{missing sentinel in function call}}
s2->a(1,2,3); // expected-warning {{missing sentinel in function call}}
s(1,2,3); // expected-warning {{missing sentinel in function call}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/flexible-array-test.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// pr7029
template <class Key, class T> struct QMap
{
void insert(const Key &, const T &);
T v;
};
template <class Key, class T>
void QMap<Key, T>::insert(const Key &, const T &avalue)
{
v = avalue;
}
struct Rec {
union { // expected-warning-re {{variable sized type '{{.*}}' not at the end of a struct or class is a GNU extension}}
int u0[];
};
int x;
} rec;
struct inotify_event
{
int wd;
// clang doesn't like '[]':
// cannot initialize a parameter of type 'void *' with an rvalue of type 'char (*)[]'
char name [];
};
void foo()
{
inotify_event event;
inotify_event* ptr = &event;
inotify_event event1 = *ptr;
*ptr = event;
QMap<int, inotify_event> eventForId;
eventForId.insert(ptr->wd, *ptr);
}
struct S {
virtual void foo();
};
struct X {
int blah;
S strings[];
};
S a, b = a;
S f(X &x) {
a = b;
return x.strings[0];
}
class A {
int s;
char c[];
};
union B {
int s;
char c[];
};
namespace rdar9065507 {
struct StorageBase {
long ref_count;
unsigned size;
unsigned capacity;
};
struct Storage : StorageBase {
int data[];
};
struct VirtStorage : virtual StorageBase {
int data[]; // expected-error {{flexible array member 'data' not allowed in struct which has a virtual base class}}
};
}
struct NonTrivDtor { ~NonTrivDtor(); };
// FIXME: It's not clear whether we should disallow examples like this. GCC accepts.
struct FlexNonTrivDtor {
int n;
NonTrivDtor ntd[]; // expected-error {{flexible array member 'ntd' of type 'NonTrivDtor []' with non-trivial destruction}}
~FlexNonTrivDtor() {
for (int i = n; i != 0; --i)
ntd[i-1].~NonTrivDtor();
}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/dcl_ambig_res.cpp
|
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
// PR13819
// REQUIRES: LP64
// [dcl.ambig.res]p1:
struct S {
S(int);
void bar();
};
int returns_an_int();
void foo(double a)
{
S w(int(a)); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
w(17);
S x1(int()); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
x1(&returns_an_int);
S y((int)a);
y.bar();
S z = int(a);
z.bar();
}
// [dcl.ambig.res]p3:
char *p;
void *operator new(__SIZE_TYPE__, int);
void foo3() {
const int x = 63;
new (int(*p)) int; //new-placement expression
new (int(*[x])); //new type-id
}
// [dcl.ambig.res]p4:
template <class T> // expected-note{{here}}
struct S4 {
T *p;
};
S4<int()> x; //type-id
S4<int(1)> y; // expected-error{{must be a type}}
// [dcl.ambig.res]p5:
void foo5()
{
(void)sizeof(int(1)); //expression
(void)sizeof(int()); // expected-error{{function type}}
}
// [dcl.ambig.res]p6:
void foo6()
{
(void)(int(1)); //expression
(void)(int())1; // expected-error{{to 'int ()'}}
}
// [dcl.ambig.res]p7:
class C7 { };
void f7(int(C7)) { } // expected-note{{candidate}}
int g7(C7);
void foo7() {
f7(1); // expected-error{{no matching function}}
f7(g7); //OK
}
void h7(int *(C7[10])) { } // expected-note{{previous}}
void h7(int *(*_fp)(C7 _parm[10])) { } // expected-error{{redefinition}}
struct S5 {
static bool const value = false;
};
int foo8() {
int v(int(S5::value)); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}} expected-error{{parameter declarator cannot be qualified}}
}
template<typename T>
void rdar8739801( void (T::*)( void ) __attribute__((unused)) );
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cv-unqual-rvalues.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// PR7463: Make sure that when we have an rvalue, it does not have
// cv-qualified non-class type.
template <typename T_> void g (T_&); // expected-note 7{{not viable}}
template<const int X> void h() {
g(X); // expected-error{{no matching function for call to 'g'}}
}
template<typename T, T X> void h2() {
g(X); // expected-error{{no matching function for call to 'g'}}
}
void a(__builtin_va_list x) {
g(__builtin_va_arg(x, const int)); // expected-error{{no matching function for call to 'g'}}
g((const int)0); // expected-error{{no matching function for call to 'g'}}
typedef const int cint;
g(cint(0)); // expected-error{{no matching function for call to 'g'}}
g(static_cast<const int>(1)); // expected-error{{no matching function for call to 'g'}}
g(reinterpret_cast<int *const>(0)); // expected-error{{no matching function for call to 'g'}}
h<0>();
h2<const int, 0>(); // expected-note{{instantiation of}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/enable_if.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify %s
typedef int (*fp)(int);
int surrogate(int);
struct X {
X() = default; // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
X(const X&) = default; // expected-note{{candidate constructor not viable: no known conversion from 'bool' to 'const X' for 1st argument}}
X(bool b) __attribute__((enable_if(b, "chosen when 'b' is true"))); // expected-note{{candidate disabled: chosen when 'b' is true}}
void f(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero")));
void f(int n) __attribute__((enable_if(n == 1, "chosen when 'n' is one"))); // expected-note{{member declaration nearly matches}} expected-note{{candidate disabled: chosen when 'n' is one}}
static void s(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); // expected-note2{{candidate disabled: chosen when 'n' is zero}}
void conflict(int n) __attribute__((enable_if(n+n == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}}
void conflict(int n) __attribute__((enable_if(n*2 == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}}
operator long() __attribute__((enable_if(true, "chosen on your platform")));
operator int() __attribute__((enable_if(false, "chosen on other platform")));
operator fp() __attribute__((enable_if(false, "never enabled"))) { return surrogate; } // expected-note{{conversion candidate of type 'int (*)(int)'}} // FIXME: the message is not displayed
};
void X::f(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))) // expected-note{{member declaration nearly matches}} expected-note{{candidate disabled: chosen when 'n' is zero}}
{
}
void X::f(int n) __attribute__((enable_if(n == 2, "chosen when 'n' is two"))) // expected-error{{out-of-line definition of 'f' does not match any declaration in 'X'}} expected-note{{candidate disabled: chosen when 'n' is two}}
{
}
X x1(true);
X x2(false); // expected-error{{no matching constructor for initialization of 'X'}}
__attribute__((deprecated)) constexpr int old() { return 0; } // expected-note2{{'old' has been explicitly marked deprecated here}}
void deprec1(int i) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}}
void deprec2(int i) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}}
void overloaded(int);
void overloaded(long);
struct Nothing { };
template<typename T> void typedep(T t) __attribute__((enable_if(t, ""))); // expected-note{{candidate disabled:}} expected-error{{value of type 'Nothing' is not contextually convertible to 'bool'}}
template<int N> void valuedep() __attribute__((enable_if(N == 1, "")));
// FIXME: we skip potential constant expression evaluation on value dependent
// enable-if expressions
int not_constexpr();
template<int N> void valuedep() __attribute__((enable_if(N == not_constexpr(), "")));
template <typename T> void instantiationdep() __attribute__((enable_if(sizeof(sizeof(T)) != 0, "")));
void test() {
X x;
x.f(0);
x.f(1);
x.f(2); // no error, suppressed by erroneous out-of-line definition
x.f(3); // expected-error{{no matching member function for call to 'f'}}
x.s(0);
x.s(1); // expected-error{{no matching member function for call to 's'}}
X::s(0);
X::s(1); // expected-error{{no matching member function for call to 's'}}
x.conflict(5); // expected-error{{call to member function 'conflict' is ambiguous}}
deprec2(0);
overloaded(x);
int i = x(1); // expected-error{{no matching function for call to object of type 'X'}}
Nothing n;
typedep(0); // expected-error{{no matching function for call to 'typedep'}}
typedep(1);
typedep(n); // expected-note{{in instantiation of function template specialization 'typedep<Nothing>' requested here}}
}
template <typename T> class C {
void f() __attribute__((enable_if(T::expr == 0, ""))) {}
void g() { f(); }
};
int fn3(bool b) __attribute__((enable_if(b, "")));
template <class T> void test3() {
fn3(sizeof(T) == 1);
}
// FIXME: issue an error (without instantiation) because ::h(T()) is not
// convertible to bool, because return types aren't overloadable.
void h(int);
template <typename T> void outer() {
void local_function() __attribute__((enable_if(::h(T()), "")));
local_function();
};
namespace PR20988 {
struct Integer {
Integer(int);
};
int fn1(const Integer &) __attribute__((enable_if(true, "")));
template <class T> void test1() {
int &expr = T::expr();
fn1(expr);
}
int fn2(const Integer &) __attribute__((enable_if(false, ""))); // expected-note{{candidate disabled}}
template <class T> void test2() {
int &expr = T::expr();
fn2(expr); // expected-error{{no matching function for call to 'fn2'}}
}
int fn3(bool b) __attribute__((enable_if(b, "")));
template <class T> void test3() {
fn3(sizeof(T) == 1);
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-sign-conversion.cpp
|
// RUN: %clang_cc1 -verify -fsyntax-only -Wsign-conversion %s
// NOTE: When a 'enumeral mismatch' warning is implemented then expect several
// of the following cases to be impacted.
// namespace for anonymous enums tests
namespace test1 {
enum { A };
enum { B = -1 };
template <typename T> struct Foo {
enum { C };
enum { D = ~0U };
};
enum { E = ~0U };
void doit_anonymous( int i ) {
int a1 = 1 ? i : A;
int a2 = 1 ? A : i;
int b1 = 1 ? i : B;
int b2 = 1 ? B : i;
int c1 = 1 ? i : Foo<bool>::C;
int c2 = 1 ? Foo<bool>::C : i;
int d1a = 1 ? i : Foo<bool>::D; // expected-warning {{test1::Foo<bool>::(anonymous enum at }}
int d1b = 1 ? i : Foo<bool>::D; // expected-warning {{warn-sign-conversion.cpp:13:5)' to 'int'}}
int d2a = 1 ? Foo<bool>::D : i; // expected-warning {{operand of ? changes signedness: 'test1::Foo<bool>::(anonymous enum at }}
int d2b = 1 ? Foo<bool>::D : i; // expected-warning {{warn-sign-conversion.cpp:13:5)' to 'int'}}
int d3a = 1 ? B : Foo<bool>::D; // expected-warning {{operand of ? changes signedness: 'test1::Foo<bool>::(anonymous enum at }}
int d3b = 1 ? B : Foo<bool>::D; // expected-warning {{warn-sign-conversion.cpp:13:5)' to 'int'}}
int d4a = 1 ? Foo<bool>::D : B; // expected-warning {{operand of ? changes signedness: 'test1::Foo<bool>::(anonymous enum at }}
int d4b = 1 ? Foo<bool>::D : B; // expected-warning {{warn-sign-conversion.cpp:13:5)' to 'int'}}
int e1a = 1 ? i : E; // expected-warning {{operand of ? changes signedness: 'test1::(anonymous enum at }}
int e1b = 1 ? i : E; // expected-warning {{warn-sign-conversion.cpp:16:3)' to 'int'}}
int e2a = 1 ? E : i; // expected-warning {{operand of ? changes signedness: 'test1::(anonymous enum at }}
int e2b = 1 ? E : i; // expected-warning {{warn-sign-conversion.cpp:16:3)' to 'int'}}
int e3a = 1 ? E : B; // expected-warning {{operand of ? changes signedness: 'test1::(anonymous enum at }}
int e3b = 1 ? E : B; // expected-warning {{warn-sign-conversion.cpp:16:3)' to 'int'}}
int e4a = 1 ? B : E; // expected-warning {{operand of ? changes signedness: 'test1::(anonymous enum at }}
int e4b = 1 ? B : E; // expected-warning {{warn-sign-conversion.cpp:16:3)' to 'int'}}
}
}
// namespace for named enums tests
namespace test2 {
enum Named1 { A };
enum Named2 { B = -1 };
template <typename T> struct Foo {
enum Named3 { C };
enum Named4 { D = ~0U };
};
enum Named5 { E = ~0U };
void doit_anonymous( int i ) {
int a1 = 1 ? i : A;
int a2 = 1 ? A : i;
int b1 = 1 ? i : B;
int b2 = 1 ? B : i;
int c1 = 1 ? i : Foo<bool>::C;
int c2 = 1 ? Foo<bool>::C : i;
int d1 = 1 ? i : Foo<bool>::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo<bool>::Named4' to 'int'}}
int d2 = 1 ? Foo<bool>::D : i; // expected-warning {{operand of ? changes signedness: 'test2::Foo<bool>::Named4' to 'int'}}
int d3 = 1 ? B : Foo<bool>::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo<bool>::Named4' to 'int'}}
int d4 = 1 ? Foo<bool>::D : B; // expected-warning {{operand of ? changes signedness: 'test2::Foo<bool>::Named4' to 'int'}}
int e1 = 1 ? i : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}}
int e2 = 1 ? E : i; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}}
int e3 = 1 ? E : B; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}}
int e4 = 1 ? B : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/warn-unused-private-field-delayed-template.cpp
|
// RUN: %clang_cc1 -fsyntax-only -fdelayed-template-parsing -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++11 %s
// expected-no-diagnostics
class EverythingMayBeUsed {
int x;
public:
template <class T>
void f() {
x = 0;
}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp
|
// This is a test for an egregious hack in Clang that works around
// an issue with GCC's <utility> implementation. std::pair::swap
// has an exception specification that makes an unqualified call to
// swap. This is invalid, because it ends up calling itself with
// the wrong number of arguments.
//
// The same problem afflicts a bunch of other class templates. Those
// affected are array, pair, priority_queue, stack, and queue.
// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=array
// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=pair
// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=priority_queue
// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=stack
// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=queue
// MSVC's standard library uses a very similar pattern that relies on delayed
// parsing of exception specifications.
//
// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=array -DMSVC
#ifdef BE_THE_HEADER
#pragma GCC system_header
namespace std {
template<typename T> void swap(T &, T &);
template<typename T> void do_swap(T &a, T &b) noexcept(noexcept(swap(a, b))) {
swap(a, b);
}
template<typename A, typename B> struct CLASS {
#ifdef MSVC
void swap(CLASS &other) noexcept(noexcept(do_swap(member, other.member)));
#endif
A member;
#ifndef MSVC
void swap(CLASS &other) noexcept(noexcept(swap(member, other.member)));
#endif
};
// template<typename T> void do_swap(T &, T &);
// template<typename A> struct vector {
// void swap(vector &other) noexcept(noexcept(do_swap(member, other.member)));
// A member;
// };
}
#else
#define BE_THE_HEADER
#include __FILE__
struct X {};
using PX = std::CLASS<X, X>;
using PI = std::CLASS<int, int>;
void swap(X &, X &) noexcept;
PX px;
PI pi;
static_assert(noexcept(px.swap(px)), "");
static_assert(!noexcept(pi.swap(pi)), "");
namespace sad {
template<typename T> void swap(T &, T &);
template<typename A, typename B> struct CLASS {
void swap(CLASS &other) noexcept(noexcept(swap(*this, other))); // expected-error {{too many arguments}} expected-note {{declared here}}
};
CLASS<int, int> pi;
static_assert(!noexcept(pi.swap(pi)), ""); // expected-note {{in instantiation of}}
}
#endif
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/inherit.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class A { };
class B1 : A { };
class B2 : virtual A { };
class B3 : virtual virtual A { }; // expected-error{{duplicate 'virtual' in base specifier}}
class C : public B1, private B2 { };
class D; // expected-note {{forward declaration of 'D'}}
class E : public D { }; // expected-error{{base class has incomplete type}}
typedef int I;
class F : public I { }; // expected-error{{base specifier must name a class}}
union U1 : public A { }; // expected-error{{unions cannot have base classes}}
union U2 {};
class G : public U2 { }; // expected-error{{unions cannot be base classes}}
typedef G G_copy;
typedef G G_copy_2;
typedef G_copy G_copy_3;
class H : G_copy, A, G_copy_2, // expected-error{{base class 'G_copy' (aka 'G') specified more than once as a direct base class}}
public G_copy_3 { }; // expected-error{{base class 'G_copy' (aka 'G') specified more than once as a direct base class}}
struct J { char c; int i[]; };
struct K : J { }; // expected-error{{base class 'J' has a flexible array member}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/goto2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
//PR9463
int subfun(const char *text) {
const char *tmp = text;
return 0;
}
void fun(const char* text) {
int count = 0;
bool check = true;
if (check)
{
const char *end = text;
if (check)
{
do
{
if (check)
{
count = subfun(end);
goto end;
}
check = !check;
}
while (check);
}
// also works, after commenting following line of source code
int e = subfun(end);
}
end:
if (check)
++count;
}
const char *text = "some text";
int main() {
const char *ptr = text;
fun(ptr);
return 0;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/builtin-ptrtomember-overload-1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
struct A {};
struct E {};
struct R {
operator A*();
operator E*(); // expected-note{{candidate function}}
};
struct S {
operator A*();
operator E*(); // expected-note{{candidate function}}
};
struct B : R {
operator A*();
};
struct C : B {
};
void foo(C c, int A::* pmf) {
int i = c->*pmf;
}
struct B1 : R, S {
operator A*();
};
struct C1 : B1 {
};
void foo1(C1 c1, int A::* pmf) {
int i = c1->*pmf;
c1->*pmf = 10;
}
void foo1(C1 c1, int E::* pmf) {
int i = c1->*pmf; // expected-error {{use of overloaded operator '->*' is ambiguous}} \
// expected-note {{because of ambiguity in conversion of 'C1' to 'E *'}} \
// expected-note 4 {{built-in candidate operator}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/auto-cxx0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
void f() {
auto int a; // expected-warning {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
int auto b; // expected-error{{cannot combine with previous 'int' declaration specifier}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/microsoft-dtor-lookup.cpp
|
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -std=c++11 -triple %itanium_abi_triple -fsyntax-only %s
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -std=c++11 -triple %ms_abi_triple -verify %s
namespace Test1 {
// Should be accepted under the Itanium ABI (first RUN line) but rejected
// under the Microsoft ABI (second RUN line), as Microsoft ABI requires
// operator delete() lookups to be done when vtables are marked used.
struct A {
void operator delete(void *); // expected-note {{member found by ambiguous name lookup}}
};
struct B {
void operator delete(void *); // expected-note {{member found by ambiguous name lookup}}
};
struct C : A, B {
~C();
};
struct VC : A, B {
virtual ~VC(); // expected-error {{member 'operator delete' found in multiple base classes of different types}}
};
void f() {
// This marks VC's vtable used.
VC vc;
}
}
namespace Test2 {
// In the MSVC ABI, functions must destroy their aggregate arguments. foo
// requires a dtor for B, but we can't implicitly define it because ~A is
// private. bar should be able to call A's private dtor without error, even
// though MSVC rejects bar.
class A {
private:
~A();
int a;
};
struct B : public A { // expected-note {{destructor of 'B' is implicitly deleted because base class 'Test2::A' has an inaccessible destructor}}
int b;
};
struct C {
~C();
int c;
};
struct D {
// D has a non-trivial implicit dtor that destroys C.
C o;
};
void foo(B b) { } // expected-error {{attempt to use a deleted function}}
void bar(A a) { } // no error; MSVC rejects this, but we skip the direct access check.
void baz(D d) { } // no error
}
#ifdef MSVC_ABI
namespace Test3 {
class A {
A();
~A(); // expected-note {{implicitly declared private here}}
friend void bar(A);
int a;
};
void bar(A a) { }
void baz(A a) { } // no error; MSVC rejects this, but the standard allows it.
// MSVC accepts foo() but we reject it for consistency with Itanium. MSVC also
// rejects this if A has a copy ctor or if we call A's ctor.
void foo(A *a) {
bar(*a); // expected-error {{temporary of type 'Test3::A' has private destructor}}
}
}
#endif
namespace Test4 {
// Don't try to access the dtor of an incomplete on a function declaration.
class A;
void foo(A a);
}
#ifdef MSVC_ABI
namespace Test5 {
// Do the operator delete access control check from the context of the dtor.
class A {
protected:
void operator delete(void *);
};
class B : public A {
virtual ~B();
};
B *test() {
// Previously, marking the vtable used here would do the operator delete
// lookup from this context, which doesn't have access.
return new B;
}
}
#endif
namespace Test6 {
class A {
protected:
void operator delete(void *);
};
class B : public A {
virtual ~B();
public:
virtual void m_fn1();
};
void fn1(B *b) { b->m_fn1(); }
}
namespace Test7 {
class A {
protected:
void operator delete(void *);
};
struct B : public A {
virtual ~B();
};
void fn1(B b) {}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
|
// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -emit-llvm-only %s
// DONTRUNYET: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
// DONTRUNYET: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fms-extensions %s -DMS_EXTENSIONS
// DONTRUNYET: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING
constexpr int ODRUSE_SZ = sizeof(char);
template<class T, int N>
void f(T, const int (&)[N]) { }
template<class T>
void f(const T&, const int (&)[ODRUSE_SZ]) { }
#define DEFINE_SELECTOR(x) \
int selector_ ## x[sizeof(x) == ODRUSE_SZ ? ODRUSE_SZ : ODRUSE_SZ + 5]
#define F_CALL(x, a) f(x, selector_ ## a)
// This is a risky assumption, because if an empty class gets captured by value
// the lambda's size will still be '1'
#define ASSERT_NO_CAPTURES(L) static_assert(sizeof(L) == 1, "size of closure with no captures must be 1")
#define ASSERT_CLOSURE_SIZE_EXACT(L, N) static_assert(sizeof(L) == (N), "size of closure must be " #N)
#define ASSERT_CLOSURE_SIZE(L, N) static_assert(sizeof(L) >= (N), "size of closure must be >=" #N)
namespace sample {
struct X {
int i;
X(int i) : i(i) { }
};
}
namespace test_transformations_in_templates {
template<class T> void foo(T t) {
auto L = [](auto a) { return a; };
}
template<class T> void foo2(T t) {
auto L = [](auto a) -> void {
auto M = [](char b) -> void {
auto N = [](auto c) -> void {
int selector[sizeof(c) == 1 ?
(sizeof(b) == 1 ? 1 : 2)
: 2
]{};
};
N('a');
};
};
L(3.14);
}
void doit() {
foo(3);
foo('a');
foo2('A');
}
}
namespace test_return_type_deduction {
void doit() {
auto L = [](auto a, auto b) {
if ( a > b ) return a;
return b;
};
L(2, 4);
{
auto L2 = [](auto a, int i) {
return a + i;
};
L2(3.14, 2);
}
{
int a; //expected-note{{declared here}}
auto B = []() { return ^{ return a; }; }; //expected-error{{cannot be implicitly capture}}\
//expected-note{{begins here}}
//[](){ return ({int b = 5; return 'c'; 'x';}); };
//auto X = ^{ return a; };
//auto Y = []() -> auto { return 3; return 'c'; };
}
}
}
namespace test_no_capture{
void doit() {
const int x = 10; //expected-note{{declared here}}
{
// should not capture 'x' - variable undergoes lvalue-to-rvalue
auto L = [=](auto a) {
int y = x;
return a + y;
};
ASSERT_NO_CAPTURES(L);
}
{
// should not capture 'x' - even though certain instantiations require
auto L = [](auto a) { //expected-note{{begins here}}
DEFINE_SELECTOR(a);
F_CALL(x, a); //expected-error{{'x' cannot be implicitly captured}}
};
ASSERT_NO_CAPTURES(L);
L('s'); //expected-note{{in instantiation of}}
}
{
// Does not capture because no default capture in inner most lambda 'b'
auto L = [=](auto a) {
return [=](int p) {
return [](auto b) {
DEFINE_SELECTOR(a);
F_CALL(x, a);
return 0;
};
};
};
ASSERT_NO_CAPTURES(L);
}
} // doit
} // namespace
namespace test_capture_of_potentially_evaluated_expression {
void doit() {
const int x = 5;
{
auto L = [=](auto a) {
DEFINE_SELECTOR(a);
F_CALL(x, a);
};
static_assert(sizeof(L) == 4, "Must be captured");
}
{
int j = 0; //expected-note{{declared}}
auto L = [](auto a) { //expected-note{{begins here}}
return j + 1; //expected-error{{cannot be implicitly captured}}
};
}
{
const int x = 10;
auto L = [](auto a) {
//const int y = 20;
return [](int p) {
return [](auto b) {
DEFINE_SELECTOR(a);
F_CALL(x, a);
return 0;
};
};
};
auto M = L(3);
auto N = M(5);
}
{ // if the nested capture does not implicitly or explicitly allow any captures
// nothing should capture - and instantiations will create errors if needed.
const int x = 0;
auto L = [=](auto a) { // <-- #A
const int y = 0;
return [](auto b) { // <-- #B
int c[sizeof(b)];
f(x, c);
f(y, c);
int i = x;
};
};
ASSERT_NO_CAPTURES(L);
auto M_int = L(2);
ASSERT_NO_CAPTURES(M_int);
}
{ // Permutations of this example must be thoroughly tested!
const int x = 0;
sample::X cx{5};
auto L = [=](auto a) {
const int z = 3;
return [&,a](auto b) {
const int y = 5;
return [=](auto c) {
int d[sizeof(a) == sizeof(c) || sizeof(c) == sizeof(b) ? 2 : 1];
f(x, d);
f(y, d);
f(z, d);
decltype(a) A = a;
decltype(b) B = b;
const int &i = cx.i;
};
};
};
auto M = L(3)(3.5);
M(3.14);
}
}
namespace Test_no_capture_of_clearly_no_odr_use {
auto foo() {
const int x = 10;
auto L = [=](auto a) {
return [=](auto b) {
return [=](auto c) {
int A = x;
return A;
};
};
};
auto M = L(1);
auto N = M(2.14);
ASSERT_NO_CAPTURES(L);
ASSERT_NO_CAPTURES(N);
return 0;
}
}
namespace Test_capture_of_odr_use_var {
auto foo() {
const int x = 10;
auto L = [=](auto a) {
return [=](auto b) {
return [=](auto c) {
int A = x;
const int &i = x;
decltype(a) A2 = a;
return A;
};
};
};
auto M_int = L(1);
auto N_int_int = M_int(2);
ASSERT_CLOSURE_SIZE_EXACT(L, sizeof(x));
// M_int captures both a & x
ASSERT_CLOSURE_SIZE_EXACT(M_int, sizeof(x) + sizeof(int));
// N_int_int captures both a & x
ASSERT_CLOSURE_SIZE_EXACT(N_int_int, sizeof(x) + sizeof(int));
auto M_double = L(3.14);
ASSERT_CLOSURE_SIZE(M_double, sizeof(x) + sizeof(double));
return 0;
}
auto run = foo();
}
}
namespace more_nested_captures_1 {
template<class T> struct Y {
static void f(int, double, ...) { }
template<class R>
static void f(const int&, R, ...) { }
template<class R>
void foo(R t) {
const int x = 10; //expected-note{{declared here}}
auto L = [](auto a) {
return [=](auto b) {
return [=](auto c) {
f(x, c, b, a); //expected-error{{reference to local variable 'x'}}
return 0;
};
};
};
auto M = L(t);
auto N = M('b');
N(3.14);
N(5); //expected-note{{in instantiation of}}
}
};
Y<int> yi;
int run = (yi.foo(3.14), 0); //expected-note{{in instantiation of}}
}
namespace more_nested_captures_1_1 {
template<class T> struct Y {
static void f(int, double, ...) { }
template<class R>
static void f(const int&, R, ...) { }
template<class R>
void foo(R t) {
const int x = 10; //expected-note{{declared here}}
auto L = [](auto a) {
return [=](char b) {
return [=](auto c) {
f(x, c, b, a); //expected-error{{reference to local variable 'x'}}
return 0;
};
};
};
auto M = L(t);
auto N = M('b');
N(3.14);
N(5); //expected-note{{in instantiation of}}
}
};
Y<int> yi;
int run = (yi.foo(3.14), 0); //expected-note{{in instantiation of}}
}
namespace more_nested_captures_1_2 {
template<class T> struct Y {
static void f(int, double, ...) { }
template<class R>
static void f(const int&, R, ...) { }
template<class R>
void foo(R t) {
const int x = 10;
auto L = [=](auto a) {
return [=](char b) {
return [=](auto c) {
f(x, c, b, a);
return 0;
};
};
};
auto M = L(t);
auto N = M('b');
N(3.14);
N(5);
}
};
Y<int> yi;
int run = (yi.foo(3.14), 0);
}
namespace more_nested_captures_1_3 {
template<class T> struct Y {
static void f(int, double, ...) { }
template<class R>
static void f(const int&, R, ...) { }
template<class R>
void foo(R t) {
const int x = 10; //expected-note{{declared here}}
auto L = [=](auto a) {
return [](auto b) {
const int y = 0;
return [=](auto c) {
f(x, c, b); //expected-error{{reference to local variable 'x'}}
f(y, b, c);
return 0;
};
};
};
auto M = L(t);
auto N = M('b');
N(3.14);
N(5); //expected-note{{in instantiation of}}
}
};
Y<int> yi;
int run = (yi.foo(3.14), 0); //expected-note{{in instantiation of}}
}
namespace more_nested_captures_1_4 {
template<class T> struct Y {
static void f(int, double, ...) { }
template<class R>
static void f(const int&, R, ...) { }
template<class R>
void foo(R t) {
const int x = 10; //expected-note{{declared here}}
auto L = [=](auto a) {
T t2{t};
return [](auto b) {
const int y = 0; //expected-note{{declared here}}
return [](auto c) { //expected-note 2{{lambda expression begins here}}
f(x, c); //expected-error{{variable 'x'}}
f(y, c); //expected-error{{variable 'y'}}
return 0;
};
};
};
auto M = L(t);
auto N_char = M('b');
N_char(3.14);
auto N_double = M(3.14);
N_double(3.14);
N_char(3); //expected-note{{in instantiation of}}
}
};
Y<int> yi;
int run = (yi.foo('a'), 0); //expected-note{{in instantiation of}}
}
namespace more_nested_captures_2 {
template<class T> struct Y {
static void f(int, double) { }
template<class R>
static void f(const int&, R) { }
template<class R>
void foo(R t) {
const int x = 10;
auto L = [=](auto a) {
return [=](auto b) {
return [=](auto c) {
f(x, c);
return 0;
};
};
};
auto M = L(t);
auto N = M('b');
N(3);
N(3.14);
}
};
Y<int> yi;
int run = (yi.foo(3.14), 0);
}
namespace more_nested_captures_3 {
template<class T> struct Y {
static void f(int, double) { }
template<class R>
static void f(const int&, R) { }
template<class R>
void foo(R t) {
const int x = 10; //expected-note{{declared here}}
auto L = [](auto a) {
return [=](auto b) {
return [=](auto c) {
f(x, c); //expected-error{{reference to local variable 'x'}}
return 0;
};
};
};
auto M = L(t);
auto N = M('b');
N(3); //expected-note{{in instantiation of}}
N(3.14);
}
};
Y<int> yi;
int run = (yi.foo(3.14), 0); //expected-note{{in instantiation of}}
}
namespace more_nested_captures_4 {
template<class T> struct Y {
static void f(int, double) { }
template<class R>
static void f(const int&, R) { }
template<class R>
void foo(R t) {
const int x = 10; //expected-note{{'x' declared here}}
auto L = [](auto a) {
return [=](char b) {
return [=](auto c) {
f(x, c); //expected-error{{reference to local variable 'x'}}
return 0;
};
};
};
auto M = L(t);
auto N = M('b');
N(3); //expected-note{{in instantiation of}}
N(3.14);
}
};
Y<int> yi;
int run = (yi.foo(3.14), 0); //expected-note{{in instantiation of}}
}
namespace more_nested_captures_5 {
template<class T> struct Y {
static void f(int, double) { }
template<class R>
static void f(const int&, R) { }
template<class R>
void foo(R t) {
const int x = 10;
auto L = [=](auto a) {
return [=](char b) {
return [=](auto c) {
f(x, c);
return 0;
};
};
};
auto M = L(t);
auto N = M('b');
N(3);
N(3.14);
}
};
Y<int> yi;
int run = (yi.foo(3.14), 0);
}
namespace lambdas_in_NSDMIs {
template<class T>
struct L {
T t{};
T t2 = ([](auto a) { return [](auto b) { return b; };})(t)(t);
T t3 = ([](auto a) { return a; })(t);
};
L<int> l;
int run = l.t2;
}
namespace test_nested_decltypes_in_trailing_return_types {
int foo() {
auto L = [](auto a) {
return [](auto b, decltype(a) b2) -> decltype(a) {
return decltype(a){};
};
};
auto M = L(3.14);
M('a', 6.26);
return 0;
}
}
namespace more_this_capture_1 {
struct X {
void f(int) { }
static void f(double) { }
void foo() {
{
auto L = [=](auto a) {
f(a);
};
L(3);
L(3.13);
}
{
auto L = [](auto a) {
f(a); //expected-error{{this}}
};
L(3.13);
L(2); //expected-note{{in instantiation}}
}
}
int g() {
auto L = [=](auto a) {
return [](int i) {
return [=](auto b) {
f(b);
int x = i;
};
};
};
auto M = L(0.0);
auto N = M(3);
N(5.32); // OK
return 0;
}
};
int run = X{}.g();
}
namespace more_this_capture_1_1 {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto L = [=](auto a) {
return [](int i) {
return [=](auto b) {
f(decltype(a){}); //expected-error{{this}}
int x = i;
};
};
};
auto M = L(0.0);
auto N = M(3);
N(5.32); // OK
L(3); // expected-note{{instantiation}}
return 0;
}
};
int run = X{}.g();
}
namespace more_this_capture_1_1_1 {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto L = [=](auto a) {
return [](auto b) {
return [=](int i) {
f(b);
f(decltype(a){}); //expected-error{{this}}
};
};
};
auto M = L(0.0); // OK
auto N = M(3.3); //OK
auto M_int = L(0); //expected-note{{instantiation}}
return 0;
}
};
int run = X{}.g();
}
namespace more_this_capture_1_1_1_1 {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto L = [=](auto a) {
return [](auto b) {
return [=](int i) {
f(b); //expected-error{{this}}
f(decltype(a){});
};
};
};
auto M_double = L(0.0); // OK
auto N = M_double(3); //expected-note{{instantiation}}
return 0;
}
};
int run = X{}.g();
}
namespace more_this_capture_2 {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto L = [=](auto a) {
return [](int i) {
return [=](auto b) {
f(b); //expected-error{{'this' cannot}}
int x = i;
};
};
};
auto M = L(0.0);
auto N = M(3);
N(5); // NOT OK expected-note{{in instantiation of}}
return 0;
}
};
int run = X{}.g();
}
namespace diagnose_errors_early_in_generic_lambdas {
int foo()
{
{ // This variable is used and must be caught early, do not need instantiation
const int x = 0; //expected-note{{declared}}
auto L = [](auto a) { //expected-note{{begins}}
const int &r = x; //expected-error{{variable}}
};
}
{ // This variable is not used
const int x = 0;
auto L = [](auto a) {
int i = x;
};
}
{
const int x = 0; //expected-note{{declared}}
auto L = [=](auto a) { // <-- #A
const int y = 0;
return [](auto b) { //expected-note{{begins}}
int c[sizeof(b)];
f(x, c);
f(y, c);
int i = x;
// This use will always be an error regardless of instantatiation
// so diagnose this early.
const int &r = x; //expected-error{{variable}}
};
};
}
return 0;
}
int run = foo();
}
namespace generic_nongenerics_interleaved_1 {
int foo() {
{
auto L = [](int a) {
int y = 10;
return [=](auto b) {
return a + y;
};
};
auto M = L(3);
M(5);
}
{
int x;
auto L = [](int a) {
int y = 10;
return [=](auto b) {
return a + y;
};
};
auto M = L(3);
M(5);
}
{
// FIXME: why are there 2 error messages here?
int x;
auto L = [](auto a) { //expected-note {{declared here}}
int y = 10; //expected-note {{declared here}}
return [](int b) { //expected-note 2{{expression begins here}}
return [=] (auto c) {
return a + y; //expected-error 2{{cannot be implicitly captured}}
};
};
};
}
{
int x;
auto L = [](auto a) {
int y = 10;
return [=](int b) {
return [=] (auto c) {
return a + y;
};
};
};
}
return 1;
}
int run = foo();
}
namespace dont_capture_refs_if_initialized_with_constant_expressions {
auto foo(int i) {
// This is surprisingly not odr-used within the lambda!
static int j;
j = i;
int &ref_j = j;
return [](auto a) { return ref_j; }; // ok
}
template<class T>
auto foo2(T t) {
// This is surprisingly not odr-used within the lambda!
static T j;
j = t;
T &ref_j = j;
return [](auto a) { return ref_j; }; // ok
}
int do_test() {
auto L = foo(3);
auto L_int = L(3);
auto L_char = L('a');
auto L1 = foo2(3.14);
auto L1_int = L1(3);
auto L1_char = L1('a');
return 0;
}
} // dont_capture_refs_if_initialized_with_constant_expressions
namespace test_conversion_to_fptr {
template<class T> struct X {
T (*fp)(T) = [](auto a) { return a; };
};
X<int> xi;
template<class T>
void fooT(T t, T (*fp)(T) = [](auto a) { return a; }) {
fp(t);
}
int test() {
{
auto L = [](auto a) { return a; };
int (*fp)(int) = L;
fp(5);
L(3);
char (*fc)(char) = L;
fc('b');
L('c');
double (*fd)(double) = L;
fd(3.14);
fd(6.26);
L(4.25);
}
{
auto L = [](auto a) ->int { return a; }; //expected-note 2{{candidate template ignored}}
int (*fp)(int) = L;
char (*fc)(char) = L; //expected-error{{no viable conversion}}
double (*fd)(double) = L; //expected-error{{no viable conversion}}
}
{
int x = 5;
auto L = [=](auto b, char c = 'x') {
int i = x;
return [](auto a) ->decltype(a) { return a; };
};
int (*fp)(int) = L(8);
fp(5);
L(3);
char (*fc)(char) = L('a');
fc('b');
L('c');
double (*fd)(double) = L(3.14);
fd(3.14);
fd(6.26);
}
{
auto L = [=](auto b) {
return [](auto a) ->decltype(b)* { return (decltype(b)*)0; };
};
int* (*fp)(int) = L(8);
fp(5);
L(3);
char* (*fc)(char) = L('a');
fc('b');
L('c');
double* (*fd)(double) = L(3.14);
fd(3.14);
fd(6.26);
}
{
auto L = [=](auto b) {
return [](auto a) ->decltype(b)* { return (decltype(b)*)0; }; //expected-note{{candidate template ignored}}
};
char* (*fp)(int) = L('8');
fp(5);
char* (*fc)(char) = L('a');
fc('b');
double* (*fi)(int) = L(3.14);
fi(5);
int* (*fi2)(int) = L(3.14); //expected-error{{no viable conversion}}
}
{
auto L = [=](auto b) {
return [](auto a) {
return [=](auto c) {
return [](auto d) ->decltype(a + b + c + d) { return d; };
};
};
};
int (*fp)(int) = L('8')(3)(short{});
double (*fs)(char) = L(3.14)(short{})('4');
}
fooT(3);
fooT('a');
fooT(3.14);
fooT("abcdefg");
return 0;
}
int run2 = test();
}
namespace this_capture {
void f(char, int) { }
template<class T>
void f(T, const int&) { }
struct X {
int x = 0;
void foo() {
auto L = [=](auto a) {
return [=](auto b) {
//f(a, x++);
x++;
};
};
L('a')(5);
L('b')(4);
L(3.14)('3');
}
};
int run = (X{}.foo(), 0);
namespace this_capture_unresolvable {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto lam = [=](auto a) { f(a); }; // captures 'this'
lam(0); // ok.
lam(0.0); // ok.
return 0;
}
int g2() {
auto lam = [](auto a) { f(a); }; // expected-error{{'this'}}
lam(0); // expected-note{{in instantiation of}}
lam(0.0); // ok.
return 0;
}
double (*fd)(double) = [](auto a) { f(a); return a; };
};
int run = X{}.g();
}
namespace check_nsdmi_and_this_capture_of_member_functions {
struct FunctorDouble {
template<class T> FunctorDouble(T t) { t(2.14); };
};
struct FunctorInt {
template<class T> FunctorInt(T t) { t(2); }; //expected-note{{in instantiation of}}
};
template<class T> struct YUnresolvable {
void f(int) { }
static void f(double) { }
T t = [](auto a) { f(a); return a; };
T t2 = [=](auto b) { f(b); return b; };
};
template<class T> struct YUnresolvable2 {
void f(int) { }
static void f(double) { }
T t = [](auto a) { f(a); return a; }; //expected-error{{'this'}} \
//expected-note{{in instantiation of}}
T t2 = [=](auto b) { f(b); return b; };
};
YUnresolvable<FunctorDouble> yud;
// This will cause an error since it call's with an int and calls a member function.
YUnresolvable2<FunctorInt> yui;
template<class T> struct YOnlyStatic {
static void f(double) { }
T t = [](auto a) { f(a); return a; };
};
YOnlyStatic<FunctorDouble> yos;
template<class T> struct YOnlyNonStatic {
void f(int) { }
T t = [](auto a) { f(a); return a; }; //expected-error{{'this'}}
};
}
namespace check_nsdmi_and_this_capture_of_data_members {
struct FunctorDouble {
template<class T> FunctorDouble(T t) { t(2.14); };
};
struct FunctorInt {
template<class T> FunctorInt(T t) { t(2); };
};
template<class T> struct YThisCapture {
const int x = 10;
static double d;
T t = [](auto a) { return x; }; //expected-error{{'this'}}
T t2 = [](auto b) { return d; };
T t3 = [this](auto a) {
return [=](auto b) {
return x;
};
};
T t4 = [=](auto a) {
return [=](auto b) {
return x;
};
};
T t5 = [](auto a) {
return [=](auto b) {
return x; //expected-error{{'this'}}
};
};
};
template<class T> double YThisCapture<T>::d = 3.14;
}
#ifdef DELAYED_TEMPLATE_PARSING
template<class T> void foo_no_error(T t) {
auto L = []()
{ return t; };
}
template<class T> void foo(T t) { //expected-note 2{{declared here}}
auto L = []() //expected-note 2{{begins here}}
{ return t; }; //expected-error 2{{cannot be implicitly captured}}
}
template void foo(int); //expected-note{{in instantiation of}}
#else
template<class T> void foo(T t) { //expected-note{{declared here}}
auto L = []() //expected-note{{begins here}}
{ return t; }; //expected-error{{cannot be implicitly captured}}
}
#endif
}
namespace no_this_capture_for_static {
struct X {
static void f(double) { }
int g() {
auto lam = [=](auto a) { f(a); };
lam(0); // ok.
ASSERT_NO_CAPTURES(lam);
return 0;
}
};
int run = X{}.g();
}
namespace this_capture_for_non_static {
struct X {
void f(double) { }
int g() {
auto L = [=](auto a) { f(a); };
L(0);
auto L2 = [](auto a) { f(a); }; //expected-error {{cannot be implicitly captured}}
return 0;
}
};
int run = X{}.g();
}
namespace this_captures_with_num_args_disambiguation {
struct X {
void f(int) { }
static void f(double, int i) { }
int g() {
auto lam = [](auto a) { f(a, a); };
lam(0);
return 0;
}
};
int run = X{}.g();
}
namespace enclosing_function_is_template_this_capture {
// Only error if the instantiation tries to use the member function.
struct X {
void f(int) { }
static void f(double) { }
template<class T>
int g(T t) {
auto L = [](auto a) { f(a); }; //expected-error{{'this'}}
L(t); // expected-note{{in instantiation of}}
return 0;
}
};
int run = X{}.g(0.0); // OK.
int run2 = X{}.g(0); // expected-note{{in instantiation of}}
}
namespace enclosing_function_is_template_this_capture_2 {
// This should error, even if not instantiated, since
// this would need to be captured.
struct X {
void f(int) { }
template<class T>
int g(T t) {
auto L = [](auto a) { f(a); }; //expected-error{{'this'}}
L(t);
return 0;
}
};
}
namespace enclosing_function_is_template_this_capture_3 {
// This should not error, this does not need to be captured.
struct X {
static void f(int) { }
template<class T>
int g(T t) {
auto L = [](auto a) { f(a); };
L(t);
return 0;
}
};
int run = X{}.g(0.0); // OK.
int run2 = X{}.g(0); // OK.
}
namespace nested_this_capture_1 {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto L = [=](auto a) {
return [this]() {
return [=](auto b) {
f(b);
};
};
};
auto M = L(0);
auto N = M();
N(5);
return 0;
}
};
int run = X{}.g();
}
namespace nested_this_capture_2 {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto L = [=](auto a) {
return [&]() {
return [=](auto b) {
f(b);
};
};
};
auto M = L(0);
auto N = M();
N(5);
N(3.14);
return 0;
}
};
int run = X{}.g();
}
namespace nested_this_capture_3_1 {
struct X {
template<class T>
void f(int, T t) { }
template<class T>
static void f(double, T t) { }
int g() {
auto L = [=](auto a) {
return [&](auto c) {
return [=](auto b) {
f(b, c);
};
};
};
auto M = L(0);
auto N = M('a');
N(5);
N(3.14);
return 0;
}
};
int run = X{}.g();
}
namespace nested_this_capture_3_2 {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto L = [=](auto a) {
return [](int i) {
return [=](auto b) {
f(b); //expected-error {{'this' cannot}}
int x = i;
};
};
};
auto M = L(0.0);
auto N = M(3);
N(5); //expected-note {{in instantiation of}}
N(3.14); // OK.
return 0;
}
};
int run = X{}.g();
}
namespace nested_this_capture_4 {
struct X {
void f(int) { }
static void f(double) { }
int g() {
auto L = [](auto a) {
return [=](auto i) {
return [=](auto b) {
f(b); //expected-error {{'this' cannot}}
int x = i;
};
};
};
auto M = L(0.0);
auto N = M(3);
N(5); //expected-note {{in instantiation of}}
N(3.14); // OK.
return 0;
}
};
int run = X{}.g();
}
namespace capture_enclosing_function_parameters {
inline auto foo(int x) {
int i = 10;
auto lambda = [=](auto z) { return x + z; };
return lambda;
}
int foo2() {
auto L = foo(3);
L(4);
L('a');
L(3.14);
return 0;
}
inline auto foo3(int x) {
int local = 1;
auto L = [=](auto a) {
int i = a[local];
return [=](auto b) mutable {
auto n = b;
return [&, n](auto c) mutable {
++local;
return ++x;
};
};
};
auto M = L("foo-abc");
auto N = M("foo-def");
auto O = N("foo-ghi");
return L;
}
int main() {
auto L3 = foo3(3);
auto M3 = L3("L3-1");
auto N3 = M3("M3-1");
auto O3 = N3("N3-1");
N3("N3-2");
M3("M3-2");
M3("M3-3");
L3("L3-2");
}
} // end ns
namespace capture_arrays {
inline int sum_array(int n) {
int array2[5] = { 1, 2, 3, 4, 5};
auto L = [=](auto N) -> int {
int sum = 0;
int array[5] = { 1, 2, 3, 4, 5 };
sum += array2[sum];
sum += array2[N];
return 0;
};
L(2);
return L(n);
}
}
namespace capture_non_odr_used_variable_because_named_in_instantiation_dependent_expressions {
// even though 'x' is not odr-used, it should be captured.
int test() {
const int x = 10;
auto L = [=](auto a) {
(void) +x + a;
};
ASSERT_CLOSURE_SIZE_EXACT(L, sizeof(x));
}
} //end ns
#ifdef MS_EXTENSIONS
namespace explicit_spec {
template<class R> struct X {
template<class T> int foo(T t) {
auto L = [](auto a) { return a; };
L(&t);
return 0;
}
template<> int foo<char>(char c) { //expected-warning{{explicit specialization}}
const int x = 10;
auto LC = [](auto a) { return a; };
R r;
LC(&r);
auto L = [=](auto a) {
return [=](auto b) {
int d[sizeof(a)];
f(x, d);
};
};
auto M = L(1);
ASSERT_NO_CAPTURES(M);
return 0;
}
};
int run_char = X<int>{}.foo('a');
int run_int = X<double>{}.foo(4);
}
#endif // MS_EXTENSIONS
namespace nsdmi_capturing_this {
struct X {
int m = 10;
int n = [this](auto) { return m; }(20);
};
template<class T>
struct XT {
T m = 10;
T n = [this](auto) { return m; }(20);
};
XT<int> xt{};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/pragma-unused.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -Wunused -verify %s
// expected-no-diagnostics
struct S {
void m(int x, int y) {
int z;
#pragma unused(x,y,z)
}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/class-base-member-init.cpp
|
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
class S {
public:
S ();
};
struct D : S {
D() :
b1(0), // expected-note {{previous initialization is here}}
b2(1),
b1(0), // expected-error {{multiple initializations given for non-static member 'b1'}}
S(), // expected-note {{previous initialization is here}}
S() // expected-error {{multiple initializations given for base 'S'}}
{}
int b1;
int b2;
};
struct A {
struct {
int a;
int b;
};
A();
};
A::A() : a(10), b(20) { }
namespace Test1 {
template<typename T> struct A {};
template<typename T> struct B : A<T> {
B() : A<T>(), // expected-note {{previous initialization is here}}
A<T>() { } // expected-error {{multiple initializations given for base 'A<T>'}}
};
}
namespace Test2 {
template<typename T> struct A : T {
A() : T(), // expected-note {{previous initialization is here}}
T() { } // expected-error {{multiple initializations given for base 'T'}}
};
}
namespace Test3 {
template<typename T> struct A {
T t;
A() : t(1), // expected-note {{previous initialization is here}}
t(2) { } // expected-error {{multiple initializations given for non-static member 't'}}
};
}
namespace test4 {
class A {
union {
struct {
int a;
int b;
};
int c;
union {
int d;
int e;
};
};
A(char _) : a(0), b(0) {}
A(short _) : a(0), c(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}}
A(int _) : d(0), e(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}}
A(long _) : a(0), d(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}}
};
}
namespace test5 {
struct Base {
Base(int);
};
struct A : Base {
A() : decltype(Base(1))(3) {
}
A(int) : Base(3), // expected-note {{previous initialization is here}}
decltype(Base(1))(2), // expected-error {{multiple initializations given for base 'decltype(test5::Base(1))' (aka 'test5::Base')}}
decltype(int())() { // expected-error {{constructor initializer 'decltype(int())' (aka 'int') does not name a class}}
}
A(float) : decltype(A())(3) {
}
};
}
namespace rdar13185264 {
class X {
X() : a(), // expected-note{{previous initialization is here}}
a() { } // expected-error{{multiple initializations given for non-static member 'a'}}
union { void *a; };
};
}
namespace PR16596 {
class A { public: virtual ~A(); };
typedef const A Foo;
void Apply(Foo processor);
struct Bar : public Foo {};
void Fetch() {
Apply(Bar());
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test
|
repos/DirectXShaderCompiler/tools/clang/test/SemaCXX/visibility.cpp
|
// RUN: %clang_cc1 -fsyntax-only %s
namespace test1 {
template <class C>
struct C2
{
static int p __attribute__((visibility("hidden")));
};
int f() {
return C2<int>::p;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.