Fix CodeCompleteTest.cpp for older gcc plus ccache builds

Some versions of gcc, especially when invoked through ccache (-E), can have
trouble with raw string literals inside macros. This moves the string out of
the macro.

llvm-svn: 349059
This commit is contained in:
David Green 2018-12-13 17:20:06 +00:00
parent 791ae69afe
commit 0250e29e50
1 changed files with 45 additions and 45 deletions

View File

@ -183,113 +183,113 @@ TEST(SemaCodeCompleteTest, VisitedNSWithoutQualifier) {
TEST(PreferredTypeTest, BinaryExpr) { TEST(PreferredTypeTest, BinaryExpr) {
// Check various operations for arithmetic types. // Check various operations for arithmetic types.
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code1 = R"cpp(
void test(int x) { void test(int x) {
x = ^10; x = ^10;
x += ^10; x -= ^10; x *= ^10; x /= ^10; x %= ^10; x += ^10; x -= ^10; x *= ^10; x /= ^10; x %= ^10;
x + ^10; x - ^10; x * ^10; x / ^10; x % ^10; x + ^10; x - ^10; x * ^10; x / ^10; x % ^10;
})cpp"), })cpp";
Each("int")); EXPECT_THAT(collectPreferredTypes(code1), Each("int"));
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code2 = R"cpp(
void test(float x) { void test(float x) {
x = ^10; x = ^10;
x += ^10; x -= ^10; x *= ^10; x /= ^10; x %= ^10; x += ^10; x -= ^10; x *= ^10; x /= ^10; x %= ^10;
x + ^10; x - ^10; x * ^10; x / ^10; x % ^10; x + ^10; x - ^10; x * ^10; x / ^10; x % ^10;
})cpp"), })cpp";
Each("float")); EXPECT_THAT(collectPreferredTypes(code2), Each("float"));
// Pointer types. // Pointer types.
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code3 = R"cpp(
void test(int *ptr) { void test(int *ptr) {
ptr - ^ptr; ptr - ^ptr;
ptr = ^ptr; ptr = ^ptr;
})cpp"), })cpp";
Each("int *")); EXPECT_THAT(collectPreferredTypes(code3), Each("int *"));
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code4 = R"cpp(
void test(int *ptr) { void test(int *ptr) {
ptr + ^10; ptr + ^10;
ptr += ^10; ptr += ^10;
ptr -= ^10; ptr -= ^10;
})cpp"), })cpp";
Each("long")); // long is normalized 'ptrdiff_t'. EXPECT_THAT(collectPreferredTypes(code4), Each("long")); // long is normalized 'ptrdiff_t'.
// Comparison operators. // Comparison operators.
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code5 = R"cpp(
void test(int i) { void test(int i) {
i <= ^1; i < ^1; i >= ^1; i > ^1; i == ^1; i != ^1; i <= ^1; i < ^1; i >= ^1; i > ^1; i == ^1; i != ^1;
} }
)cpp"), )cpp";
Each("int")); EXPECT_THAT(collectPreferredTypes(code5), Each("int"));
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code6 = R"cpp(
void test(int *ptr) { void test(int *ptr) {
ptr <= ^ptr; ptr < ^ptr; ptr >= ^ptr; ptr > ^ptr; ptr <= ^ptr; ptr < ^ptr; ptr >= ^ptr; ptr > ^ptr;
ptr == ^ptr; ptr != ^ptr; ptr == ^ptr; ptr != ^ptr;
} }
)cpp"), )cpp";
Each("int *")); EXPECT_THAT(collectPreferredTypes(code6), Each("int *"));
// Relational operations. // Relational operations.
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code7 = R"cpp(
void test(int i, int *ptr) { void test(int i, int *ptr) {
i && ^1; i || ^1; i && ^1; i || ^1;
ptr && ^1; ptr || ^1; ptr && ^1; ptr || ^1;
} }
)cpp"), )cpp";
Each("_Bool")); EXPECT_THAT(collectPreferredTypes(code7), Each("_Bool"));
// Bitwise operations. // Bitwise operations.
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code8 = R"cpp(
void test(long long ll) { void test(long long ll) {
ll | ^1; ll & ^1; ll | ^1; ll & ^1;
} }
)cpp"), )cpp";
Each("long long")); EXPECT_THAT(collectPreferredTypes(code8), Each("long long"));
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code9 = R"cpp(
enum A {}; enum A {};
void test(A a) { void test(A a) {
a | ^1; a & ^1; a | ^1; a & ^1;
} }
)cpp"), )cpp";
Each("enum A")); EXPECT_THAT(collectPreferredTypes(code9), Each("enum A"));
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code10 = R"cpp(
enum class A {}; enum class A {};
void test(A a) { void test(A a) {
// This is technically illegal with the 'enum class' without overloaded // This is technically illegal with the 'enum class' without overloaded
// operators, but we pretend it's fine. // operators, but we pretend it's fine.
a | ^a; a & ^a; a | ^a; a & ^a;
} }
)cpp"), )cpp";
Each("enum A")); EXPECT_THAT(collectPreferredTypes(code10), Each("enum A"));
// Binary shifts. // Binary shifts.
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code11 = R"cpp(
void test(int i, long long ll) { void test(int i, long long ll) {
i << ^1; ll << ^1; i << ^1; ll << ^1;
i <<= ^1; i <<= ^1; i <<= ^1; i <<= ^1;
i >> ^1; ll >> ^1; i >> ^1; ll >> ^1;
i >>= ^1; i >>= ^1; i >>= ^1; i >>= ^1;
} }
)cpp"), )cpp";
Each("int")); EXPECT_THAT(collectPreferredTypes(code11), Each("int"));
// Comma does not provide any useful information. // Comma does not provide any useful information.
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code12 = R"cpp(
class Cls {}; class Cls {};
void test(int i, int* ptr, Cls x) { void test(int i, int* ptr, Cls x) {
(i, ^i); (i, ^i);
(ptr, ^ptr); (ptr, ^ptr);
(x, ^x); (x, ^x);
} }
)cpp"), )cpp";
Each("NULL TYPE")); EXPECT_THAT(collectPreferredTypes(code12), Each("NULL TYPE"));
// User-defined types do not take operator overloading into account. // User-defined types do not take operator overloading into account.
// However, they provide heuristics for some common cases. // However, they provide heuristics for some common cases.
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code13 = R"cpp(
class Cls {}; class Cls {};
void test(Cls c) { void test(Cls c) {
// we assume arithmetic and comparions ops take the same type. // we assume arithmetic and comparions ops take the same type.
@ -298,19 +298,19 @@ TEST(PreferredTypeTest, BinaryExpr) {
// same for the assignments. // same for the assignments.
c = ^c; c += ^c; c -= ^c; c *= ^c; c /= ^c; c %= ^c; c = ^c; c += ^c; c -= ^c; c *= ^c; c /= ^c; c %= ^c;
} }
)cpp"), )cpp";
Each("class Cls")); EXPECT_THAT(collectPreferredTypes(code13), Each("class Cls"));
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code14 = R"cpp(
class Cls {}; class Cls {};
void test(Cls c) { void test(Cls c) {
// we assume relational ops operate on bools. // we assume relational ops operate on bools.
c && ^c; c || ^c; c && ^c; c || ^c;
} }
)cpp"), )cpp";
Each("_Bool")); EXPECT_THAT(collectPreferredTypes(code14), Each("_Bool"));
EXPECT_THAT(collectPreferredTypes(R"cpp( StringRef code15 = R"cpp(
class Cls {}; class Cls {};
void test(Cls c) { void test(Cls c) {
// we make no assumptions about the following operators, since they are // we make no assumptions about the following operators, since they are
@ -318,8 +318,8 @@ TEST(PreferredTypeTest, BinaryExpr) {
c << ^c; c >> ^c; c | ^c; c & ^c; c << ^c; c >> ^c; c | ^c; c & ^c;
c <<= ^c; c >>= ^c; c |= ^c; c &= ^c; c <<= ^c; c >>= ^c; c |= ^c; c &= ^c;
} }
)cpp"), )cpp";
Each("NULL TYPE")); EXPECT_THAT(collectPreferredTypes(code15), Each("NULL TYPE"));
} }
} // namespace } // namespace