1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
14 | #include "clang/Tooling/Tooling.h" |
15 | #include "gtest/gtest.h" |
16 | |
17 | using namespace clang::ast_matchers; |
18 | using namespace clang::tooling; |
19 | |
20 | TEST(Decl, CleansUpAPValues) { |
21 | MatchFinder Finder; |
22 | std::unique_ptr<FrontendActionFactory> Factory( |
23 | newFrontendActionFactory(&Finder)); |
24 | |
25 | |
26 | |
27 | |
28 | std::vector<std::string> Args(1, "-std=c++11"); |
29 | Args.push_back("-fno-ms-extensions"); |
30 | ASSERT_TRUE(runToolOnCodeWithArgs( |
31 | Factory->create(), |
32 | "struct X { int a; }; constexpr X x = { 42 };" |
33 | "union Y { constexpr Y(int a) : a(a) {} int a; }; constexpr Y y = { 42 };" |
34 | "constexpr int z[2] = { 42, 43 };" |
35 | "constexpr int __attribute__((vector_size(16))) v1 = {};" |
36 | "\n#ifdef __SIZEOF_INT128__\n" |
37 | "constexpr __uint128_t large_int = 0xffffffffffffffff;" |
38 | "constexpr __uint128_t small_int = 1;" |
39 | "\n#endif\n" |
40 | "constexpr double d1 = 42.42;" |
41 | "constexpr long double d2 = 42.42;" |
42 | "constexpr _Complex long double c1 = 42.0i;" |
43 | "constexpr _Complex long double c2 = 42.0;" |
44 | "template<int N> struct A : A<N-1> {};" |
45 | "template<> struct A<0> { int n; }; A<50> a;" |
46 | "constexpr int &r = a.n;" |
47 | "constexpr int A<50>::*p = &A<50>::n;" |
48 | "void f() { foo: bar: constexpr int k = __builtin_constant_p(0) ?" |
49 | " (char*)&&foo - (char*)&&bar : 0; }", |
50 | Args)); |
51 | |
52 | |
53 | |
54 | ASSERT_FALSE(runToolOnCodeWithArgs( |
55 | Factory->create(), |
56 | "constexpr _Complex __uint128_t c = 0xffffffffffffffff;", |
57 | Args)); |
58 | } |
59 | |