2015-10-08 16:28:09 +08:00
|
|
|
// RUN: %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 | FileCheck %s
|
2012-10-13 06:45:14 +08:00
|
|
|
|
|
|
|
// CHECK: r;
|
|
|
|
// CHECK-NEXT: (r->method());
|
|
|
|
struct MyClass
|
|
|
|
{
|
|
|
|
void method() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Reference
|
|
|
|
{
|
|
|
|
MyClass* object;
|
|
|
|
MyClass* operator ->() { return object; }
|
|
|
|
};
|
|
|
|
|
2012-10-19 05:53:46 +08:00
|
|
|
void test1() {
|
2012-10-13 06:45:14 +08:00
|
|
|
Reference r;
|
|
|
|
(r->method());
|
|
|
|
}
|
|
|
|
|
2012-10-17 07:45:15 +08:00
|
|
|
// CHECK: if (int a = 1)
|
|
|
|
// CHECK: while (int a = 1)
|
|
|
|
// CHECK: switch (int a = 1)
|
|
|
|
|
2012-10-19 05:53:46 +08:00
|
|
|
void test2()
|
2012-10-17 07:45:15 +08:00
|
|
|
{
|
|
|
|
if (int a = 1) { }
|
|
|
|
while (int a = 1) { }
|
|
|
|
switch (int a = 1) { }
|
|
|
|
}
|
|
|
|
|
2012-10-19 04:54:37 +08:00
|
|
|
// CHECK: new (1) int;
|
|
|
|
void *operator new (typeof(sizeof(1)), int, int = 2);
|
2012-10-19 05:53:46 +08:00
|
|
|
void test3() {
|
2012-10-19 04:54:37 +08:00
|
|
|
new (1) int;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: new X;
|
|
|
|
struct X {
|
|
|
|
void *operator new (typeof(sizeof(1)), int = 2);
|
|
|
|
};
|
2012-10-19 05:53:46 +08:00
|
|
|
void test4() { new X; }
|
2012-10-19 04:58:58 +08:00
|
|
|
|
|
|
|
// CHECK: for (int i = 2097, j = 42; false;)
|
2012-10-19 05:53:46 +08:00
|
|
|
void test5() {
|
2012-10-19 04:58:58 +08:00
|
|
|
for (int i = 2097, j = 42; false;) {}
|
|
|
|
}
|
2012-10-19 05:53:46 +08:00
|
|
|
|
|
|
|
// CHECK: test6fn((int &)y);
|
|
|
|
void test6fn(int& x);
|
|
|
|
void test6() {
|
|
|
|
unsigned int y = 0;
|
|
|
|
test6fn((int&)y);
|
|
|
|
}
|
2012-10-20 04:36:44 +08:00
|
|
|
|
2015-01-30 10:04:26 +08:00
|
|
|
// CHECK: S s(1, 2);
|
2012-10-20 04:36:44 +08:00
|
|
|
|
|
|
|
template <class S> void test7()
|
|
|
|
{
|
|
|
|
S s( 1,2 );
|
|
|
|
}
|
|
|
|
|
2012-10-24 04:26:57 +08:00
|
|
|
|
|
|
|
// CHECK: t.~T();
|
|
|
|
|
|
|
|
template <typename T> void test8(T t) { t.~T(); }
|
2012-10-25 04:21:25 +08:00
|
|
|
|
|
|
|
|
2015-10-08 16:28:09 +08:00
|
|
|
// CHECK: enum E
|
2012-10-25 04:21:25 +08:00
|
|
|
// CHECK-NEXT: A,
|
|
|
|
// CHECK-NEXT: B,
|
|
|
|
// CHECK-NEXT: C
|
|
|
|
// CHECK-NEXT: };
|
|
|
|
// CHECK-NEXT: {{^[ ]+}}E a = A;
|
|
|
|
|
|
|
|
struct test9
|
|
|
|
{
|
|
|
|
void f()
|
|
|
|
{
|
|
|
|
enum E { A, B, C };
|
|
|
|
E a = A;
|
|
|
|
}
|
|
|
|
};
|
2013-01-25 07:21:11 +08:00
|
|
|
|
|
|
|
namespace test10 {
|
|
|
|
namespace M {
|
|
|
|
template<typename T>
|
|
|
|
struct X {
|
|
|
|
enum { value };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int INT;
|
|
|
|
|
|
|
|
// CHECK: test11
|
|
|
|
// CHECK-NEXT: return test10::M::X<INT>::value;
|
|
|
|
int test11() {
|
|
|
|
return test10::M::X<INT>::value;
|
|
|
|
}
|
|
|
|
|
2013-01-28 05:28:24 +08:00
|
|
|
|
|
|
|
struct DefaultArgClass
|
|
|
|
{
|
|
|
|
DefaultArgClass(int a = 1) {}
|
2013-05-25 00:11:44 +08:00
|
|
|
DefaultArgClass(int a, int b, int c = 1) {}
|
2013-01-28 05:28:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NoArgClass
|
|
|
|
{
|
|
|
|
NoArgClass() {}
|
|
|
|
};
|
|
|
|
|
2013-02-04 07:02:47 +08:00
|
|
|
struct VirualDestrClass
|
|
|
|
{
|
|
|
|
VirualDestrClass(int arg);
|
|
|
|
virtual ~VirualDestrClass();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstrWithCleanupsClass
|
|
|
|
{
|
|
|
|
ConstrWithCleanupsClass(const VirualDestrClass& cplx = VirualDestrClass(42));
|
|
|
|
};
|
|
|
|
|
2013-01-28 05:28:24 +08:00
|
|
|
// CHECK: test12
|
|
|
|
// CHECK-NEXT: DefaultArgClass useDefaultArg;
|
|
|
|
// CHECK-NEXT: DefaultArgClass overrideDefaultArg(1);
|
2013-05-25 00:11:44 +08:00
|
|
|
// CHECK-NEXT: DefaultArgClass(1, 2);
|
|
|
|
// CHECK-NEXT: DefaultArgClass(1, 2, 3);
|
2013-01-28 05:28:24 +08:00
|
|
|
// CHECK-NEXT: NoArgClass noArg;
|
2013-02-04 07:02:47 +08:00
|
|
|
// CHECK-NEXT: ConstrWithCleanupsClass cwcNoArg;
|
|
|
|
// CHECK-NEXT: ConstrWithCleanupsClass cwcOverrideArg(48);
|
|
|
|
// CHECK-NEXT: ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56));
|
2013-01-28 05:28:24 +08:00
|
|
|
void test12() {
|
|
|
|
DefaultArgClass useDefaultArg;
|
|
|
|
DefaultArgClass overrideDefaultArg(1);
|
2013-05-25 00:11:44 +08:00
|
|
|
DefaultArgClass tempWithDefaultArg = DefaultArgClass(1, 2);
|
|
|
|
DefaultArgClass tempWithExplictArg = DefaultArgClass(1, 2, 3);
|
2013-01-28 05:28:24 +08:00
|
|
|
NoArgClass noArg;
|
2013-02-04 07:02:47 +08:00
|
|
|
ConstrWithCleanupsClass cwcNoArg;
|
|
|
|
ConstrWithCleanupsClass cwcOverrideArg(48);
|
|
|
|
ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56));
|
2013-01-28 05:28:24 +08:00
|
|
|
}
|
|
|
|
|
2013-05-02 03:02:43 +08:00
|
|
|
// CHECK: void test13() {
|
|
|
|
// CHECK: _Atomic(int) i;
|
|
|
|
// CHECK: __c11_atomic_init(&i, 0);
|
|
|
|
// CHECK: __c11_atomic_load(&i, 0);
|
|
|
|
// CHECK: }
|
|
|
|
void test13() {
|
|
|
|
_Atomic(int) i;
|
|
|
|
__c11_atomic_init(&i, 0);
|
|
|
|
__c11_atomic_load(&i, 0);
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:54:04 +08:00
|
|
|
|
|
|
|
// CHECK: void test14() {
|
|
|
|
// CHECK: struct X {
|
|
|
|
// CHECK: union {
|
|
|
|
// CHECK: int x;
|
|
|
|
// CHECK: } x;
|
|
|
|
// CHECK: };
|
|
|
|
// CHECK: }
|
|
|
|
void test14() {
|
|
|
|
struct X { union { int x; } x; };
|
|
|
|
}
|
2013-11-22 00:43:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
// CHECK: float test15() {
|
|
|
|
// CHECK: return __builtin_asinf(1.F);
|
|
|
|
// CHECK: }
|
|
|
|
// CHECK-NOT: extern "C"
|
|
|
|
float test15() {
|
|
|
|
return __builtin_asinf(1.0F);
|
|
|
|
}
|
2014-02-26 02:03:55 +08:00
|
|
|
|
|
|
|
namespace PR18776 {
|
|
|
|
struct A {
|
|
|
|
operator void *();
|
|
|
|
explicit operator bool();
|
|
|
|
A operator&(A);
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: struct A
|
|
|
|
// CHECK-NEXT: {{^[ ]*operator}} void *();
|
|
|
|
// CHECK-NEXT: {{^[ ]*explicit}} operator bool();
|
|
|
|
|
|
|
|
void bar(void *);
|
|
|
|
|
|
|
|
void foo() {
|
|
|
|
A a, b;
|
|
|
|
bar(a & b);
|
|
|
|
// CHECK: bar(a & b);
|
|
|
|
if (a & b)
|
|
|
|
// CHECK: if (a & b)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2014-05-14 00:12:14 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
void test(int i) {
|
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
// CHECK: {{\[\[clang::fallthrough\]\]}}
|
|
|
|
[[clang::fallthrough]];
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-16 00:45:30 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
// CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
|
|
|
|
struct [[gnu::visibility("hidden")]] S;
|
|
|
|
}
|
2015-01-29 06:06:01 +08:00
|
|
|
|
2015-01-30 10:04:26 +08:00
|
|
|
// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{};
|
2015-01-29 06:06:01 +08:00
|
|
|
struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{};
|
|
|
|
|
|
|
|
// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{};
|
|
|
|
struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{};
|
2015-09-23 21:43:16 +08:00
|
|
|
|
|
|
|
namespace PR24872 {
|
|
|
|
// CHECK: template <typename T> struct Foo : T {
|
|
|
|
// CHECK: using T::operator-;
|
|
|
|
template <typename T> struct Foo : T {
|
|
|
|
using T::operator-;
|
|
|
|
};
|
|
|
|
}
|
2016-07-09 00:04:22 +08:00
|
|
|
|
2016-07-09 05:09:08 +08:00
|
|
|
namespace dont_crash_on_auto_vars {
|
2016-07-09 00:04:22 +08:00
|
|
|
struct T { enum E {X = 12ll }; };
|
|
|
|
struct S {
|
|
|
|
struct { int I; } ADecl;
|
|
|
|
static const auto Y = T::X;
|
|
|
|
};
|
|
|
|
//CHECK: static const auto Y = T::X;
|
2016-07-09 05:09:08 +08:00
|
|
|
constexpr auto var = T::X;
|
|
|
|
//CHECK: constexpr auto var = T::X;
|
2016-07-09 00:04:22 +08:00
|
|
|
}
|