Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 1 | //=== unittests/Sema/CodeCompleteTest.cpp - Code Complete tests ==============// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/Frontend/CompilerInstance.h" |
| 11 | #include "clang/Frontend/FrontendActions.h" |
| 12 | #include "clang/Lex/Preprocessor.h" |
| 13 | #include "clang/Parse/ParseAST.h" |
| 14 | #include "clang/Sema/Sema.h" |
| 15 | #include "clang/Sema/SemaDiagnostic.h" |
| 16 | #include "clang/Tooling/Tooling.h" |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 17 | #include "gmock/gmock.h" |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 18 | #include "gtest/gtest.h" |
| 19 | #include <cstddef> |
| 20 | #include <string> |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 21 | |
| 22 | namespace { |
| 23 | |
| 24 | using namespace clang; |
| 25 | using namespace clang::tooling; |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 26 | using ::testing::Each; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 27 | using ::testing::UnorderedElementsAre; |
| 28 | |
| 29 | const char TestCCName[] = "test.cc"; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 30 | |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 31 | struct CompletionContext { |
| 32 | std::vector<std::string> VisitedNamespaces; |
| 33 | std::string PreferredType; |
| 34 | }; |
| 35 | |
| 36 | class VisitedContextFinder : public CodeCompleteConsumer { |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 37 | public: |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 38 | VisitedContextFinder(CompletionContext &ResultCtx) |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 39 | : CodeCompleteConsumer(/*CodeCompleteOpts=*/{}, |
| 40 | /*CodeCompleteConsumer*/ false), |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 41 | ResultCtx(ResultCtx), |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 42 | CCTUInfo(std::make_shared<GlobalCodeCompletionAllocator>()) {} |
| 43 | |
| 44 | void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, |
| 45 | CodeCompletionResult *Results, |
| 46 | unsigned NumResults) override { |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 47 | ResultCtx.VisitedNamespaces = |
| 48 | getVisitedNamespace(Context.getVisitedContexts()); |
| 49 | ResultCtx.PreferredType = Context.getPreferredType().getAsString(); |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | CodeCompletionAllocator &getAllocator() override { |
| 53 | return CCTUInfo.getAllocator(); |
| 54 | } |
| 55 | |
| 56 | CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; } |
| 57 | |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 58 | private: |
| 59 | std::vector<std::string> getVisitedNamespace( |
| 60 | CodeCompletionContext::VisitedContextSet VisitedContexts) const { |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 61 | std::vector<std::string> NSNames; |
| 62 | for (const auto *Context : VisitedContexts) |
| 63 | if (const auto *NS = llvm::dyn_cast<NamespaceDecl>(Context)) |
| 64 | NSNames.push_back(NS->getQualifiedNameAsString()); |
| 65 | return NSNames; |
| 66 | } |
| 67 | |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 68 | CompletionContext &ResultCtx; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 69 | CodeCompletionTUInfo CCTUInfo; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | class CodeCompleteAction : public SyntaxOnlyAction { |
| 73 | public: |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 74 | CodeCompleteAction(ParsedSourceLocation P, CompletionContext &ResultCtx) |
| 75 | : CompletePosition(std::move(P)), ResultCtx(ResultCtx) {} |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 76 | |
| 77 | bool BeginInvocation(CompilerInstance &CI) override { |
| 78 | CI.getFrontendOpts().CodeCompletionAt = CompletePosition; |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 79 | CI.setCodeCompletionConsumer(new VisitedContextFinder(ResultCtx)); |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 80 | return true; |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | // 1-based code complete position <Line, Col>; |
| 85 | ParsedSourceLocation CompletePosition; |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 86 | CompletionContext &ResultCtx; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | ParsedSourceLocation offsetToPosition(llvm::StringRef Code, size_t Offset) { |
| 90 | Offset = std::min(Code.size(), Offset); |
| 91 | StringRef Before = Code.substr(0, Offset); |
| 92 | int Lines = Before.count('\n'); |
| 93 | size_t PrevNL = Before.rfind('\n'); |
| 94 | size_t StartOfLine = (PrevNL == StringRef::npos) ? 0 : (PrevNL + 1); |
| 95 | return {TestCCName, static_cast<unsigned>(Lines + 1), |
| 96 | static_cast<unsigned>(Offset - StartOfLine + 1)}; |
| 97 | } |
| 98 | |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 99 | CompletionContext runCompletion(StringRef Code, size_t Offset) { |
| 100 | CompletionContext ResultCtx; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 101 | auto Action = llvm::make_unique<CodeCompleteAction>( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 102 | offsetToPosition(Code, Offset), ResultCtx); |
Roman Lebedev | 497fd98 | 2018-02-27 15:54:55 +0000 | [diff] [blame] | 103 | clang::tooling::runToolOnCodeWithArgs(Action.release(), Code, {"-std=c++11"}, |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 104 | TestCCName); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 105 | return ResultCtx; |
| 106 | } |
| 107 | |
| 108 | struct ParsedAnnotations { |
| 109 | std::vector<size_t> Points; |
| 110 | std::string Code; |
| 111 | }; |
| 112 | |
| 113 | ParsedAnnotations parseAnnotations(StringRef AnnotatedCode) { |
| 114 | ParsedAnnotations R; |
| 115 | while (!AnnotatedCode.empty()) { |
| 116 | size_t NextPoint = AnnotatedCode.find('^'); |
| 117 | if (NextPoint == StringRef::npos) { |
| 118 | R.Code += AnnotatedCode; |
| 119 | AnnotatedCode = ""; |
| 120 | break; |
| 121 | } |
| 122 | R.Code += AnnotatedCode.substr(0, NextPoint); |
| 123 | R.Points.push_back(R.Code.size()); |
| 124 | |
| 125 | AnnotatedCode = AnnotatedCode.substr(NextPoint + 1); |
| 126 | } |
| 127 | return R; |
| 128 | } |
| 129 | |
| 130 | CompletionContext runCodeCompleteOnCode(StringRef AnnotatedCode) { |
| 131 | ParsedAnnotations P = parseAnnotations(AnnotatedCode); |
| 132 | assert(P.Points.size() == 1 && "expected exactly one annotation point"); |
| 133 | return runCompletion(P.Code, P.Points.front()); |
| 134 | } |
| 135 | |
| 136 | std::vector<std::string> collectPreferredTypes(StringRef AnnotatedCode) { |
| 137 | ParsedAnnotations P = parseAnnotations(AnnotatedCode); |
| 138 | std::vector<std::string> Types; |
| 139 | for (size_t Point : P.Points) |
| 140 | Types.push_back(runCompletion(P.Code, Point).PreferredType); |
| 141 | return Types; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | TEST(SemaCodeCompleteTest, VisitedNSForValidQualifiedId) { |
| 145 | auto VisitedNS = runCodeCompleteOnCode(R"cpp( |
| 146 | namespace ns1 {} |
| 147 | namespace ns2 {} |
| 148 | namespace ns3 {} |
| 149 | namespace ns3 { namespace nns3 {} } |
| 150 | |
| 151 | namespace foo { |
| 152 | using namespace ns1; |
| 153 | namespace ns4 {} // not visited |
| 154 | namespace { using namespace ns2; } |
| 155 | inline namespace bar { using namespace ns3::nns3; } |
| 156 | } // foo |
| 157 | namespace ns { foo::^ } |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 158 | )cpp") |
| 159 | .VisitedNamespaces; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 160 | EXPECT_THAT(VisitedNS, UnorderedElementsAre("foo", "ns1", "ns2", "ns3::nns3", |
| 161 | "foo::(anonymous)")); |
| 162 | } |
| 163 | |
| 164 | TEST(SemaCodeCompleteTest, VisitedNSForInvalideQualifiedId) { |
| 165 | auto VisitedNS = runCodeCompleteOnCode(R"cpp( |
| 166 | namespace ns { foo::^ } |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 167 | )cpp") |
| 168 | .VisitedNamespaces; |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 169 | EXPECT_TRUE(VisitedNS.empty()); |
| 170 | } |
| 171 | |
Eric Liu | f5ba09f | 2018-07-04 10:01:18 +0000 | [diff] [blame] | 172 | TEST(SemaCodeCompleteTest, VisitedNSWithoutQualifier) { |
| 173 | auto VisitedNS = runCodeCompleteOnCode(R"cpp( |
| 174 | namespace n1 { |
| 175 | namespace n2 { |
| 176 | void f(^) {} |
| 177 | } |
| 178 | } |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 179 | )cpp") |
| 180 | .VisitedNamespaces; |
Eric Liu | f5ba09f | 2018-07-04 10:01:18 +0000 | [diff] [blame] | 181 | EXPECT_THAT(VisitedNS, UnorderedElementsAre("n1", "n1::n2")); |
| 182 | } |
| 183 | |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 184 | TEST(PreferredTypeTest, BinaryExpr) { |
| 185 | // Check various operations for arithmetic types. |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 186 | StringRef code1 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 187 | void test(int x) { |
| 188 | x = ^10; |
| 189 | x += ^10; x -= ^10; x *= ^10; x /= ^10; x %= ^10; |
| 190 | x + ^10; x - ^10; x * ^10; x / ^10; x % ^10; |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 191 | })cpp"; |
| 192 | EXPECT_THAT(collectPreferredTypes(code1), Each("int")); |
| 193 | StringRef code2 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 194 | void test(float x) { |
| 195 | x = ^10; |
| 196 | x += ^10; x -= ^10; x *= ^10; x /= ^10; x %= ^10; |
| 197 | x + ^10; x - ^10; x * ^10; x / ^10; x % ^10; |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 198 | })cpp"; |
| 199 | EXPECT_THAT(collectPreferredTypes(code2), Each("float")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 200 | |
| 201 | // Pointer types. |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 202 | StringRef code3 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 203 | void test(int *ptr) { |
| 204 | ptr - ^ptr; |
| 205 | ptr = ^ptr; |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 206 | })cpp"; |
| 207 | EXPECT_THAT(collectPreferredTypes(code3), Each("int *")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 208 | |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 209 | StringRef code4 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 210 | void test(int *ptr) { |
| 211 | ptr + ^10; |
| 212 | ptr += ^10; |
| 213 | ptr -= ^10; |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 214 | })cpp"; |
| 215 | EXPECT_THAT(collectPreferredTypes(code4), Each("long")); // long is normalized 'ptrdiff_t'. |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 216 | |
| 217 | // Comparison operators. |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 218 | StringRef code5 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 219 | void test(int i) { |
| 220 | i <= ^1; i < ^1; i >= ^1; i > ^1; i == ^1; i != ^1; |
| 221 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 222 | )cpp"; |
| 223 | EXPECT_THAT(collectPreferredTypes(code5), Each("int")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 224 | |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 225 | StringRef code6 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 226 | void test(int *ptr) { |
| 227 | ptr <= ^ptr; ptr < ^ptr; ptr >= ^ptr; ptr > ^ptr; |
| 228 | ptr == ^ptr; ptr != ^ptr; |
| 229 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 230 | )cpp"; |
| 231 | EXPECT_THAT(collectPreferredTypes(code6), Each("int *")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 232 | |
| 233 | // Relational operations. |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 234 | StringRef code7 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 235 | void test(int i, int *ptr) { |
| 236 | i && ^1; i || ^1; |
| 237 | ptr && ^1; ptr || ^1; |
| 238 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 239 | )cpp"; |
| 240 | EXPECT_THAT(collectPreferredTypes(code7), Each("_Bool")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 241 | |
| 242 | // Bitwise operations. |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 243 | StringRef code8 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 244 | void test(long long ll) { |
| 245 | ll | ^1; ll & ^1; |
| 246 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 247 | )cpp"; |
| 248 | EXPECT_THAT(collectPreferredTypes(code8), Each("long long")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 249 | |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 250 | StringRef code9 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 251 | enum A {}; |
| 252 | void test(A a) { |
| 253 | a | ^1; a & ^1; |
| 254 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 255 | )cpp"; |
| 256 | EXPECT_THAT(collectPreferredTypes(code9), Each("enum A")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 257 | |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 258 | StringRef code10 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 259 | enum class A {}; |
| 260 | void test(A a) { |
| 261 | // This is technically illegal with the 'enum class' without overloaded |
| 262 | // operators, but we pretend it's fine. |
| 263 | a | ^a; a & ^a; |
| 264 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 265 | )cpp"; |
| 266 | EXPECT_THAT(collectPreferredTypes(code10), Each("enum A")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 267 | |
| 268 | // Binary shifts. |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 269 | StringRef code11 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 270 | void test(int i, long long ll) { |
| 271 | i << ^1; ll << ^1; |
| 272 | i <<= ^1; i <<= ^1; |
| 273 | i >> ^1; ll >> ^1; |
| 274 | i >>= ^1; i >>= ^1; |
| 275 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 276 | )cpp"; |
| 277 | EXPECT_THAT(collectPreferredTypes(code11), Each("int")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 278 | |
| 279 | // Comma does not provide any useful information. |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 280 | StringRef code12 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 281 | class Cls {}; |
| 282 | void test(int i, int* ptr, Cls x) { |
| 283 | (i, ^i); |
| 284 | (ptr, ^ptr); |
| 285 | (x, ^x); |
| 286 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 287 | )cpp"; |
| 288 | EXPECT_THAT(collectPreferredTypes(code12), Each("NULL TYPE")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 289 | |
| 290 | // User-defined types do not take operator overloading into account. |
| 291 | // However, they provide heuristics for some common cases. |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 292 | StringRef code13 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 293 | class Cls {}; |
| 294 | void test(Cls c) { |
| 295 | // we assume arithmetic and comparions ops take the same type. |
| 296 | c + ^c; c - ^c; c * ^c; c / ^c; c % ^c; |
| 297 | c == ^c; c != ^c; c < ^c; c <= ^c; c > ^c; c >= ^c; |
| 298 | // same for the assignments. |
| 299 | c = ^c; c += ^c; c -= ^c; c *= ^c; c /= ^c; c %= ^c; |
| 300 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 301 | )cpp"; |
| 302 | EXPECT_THAT(collectPreferredTypes(code13), Each("class Cls")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 303 | |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 304 | StringRef code14 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 305 | class Cls {}; |
| 306 | void test(Cls c) { |
| 307 | // we assume relational ops operate on bools. |
| 308 | c && ^c; c || ^c; |
| 309 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 310 | )cpp"; |
| 311 | EXPECT_THAT(collectPreferredTypes(code14), Each("_Bool")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 312 | |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 313 | StringRef code15 = R"cpp( |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 314 | class Cls {}; |
| 315 | void test(Cls c) { |
| 316 | // we make no assumptions about the following operators, since they are |
| 317 | // often overloaded with a non-standard meaning. |
| 318 | c << ^c; c >> ^c; c | ^c; c & ^c; |
| 319 | c <<= ^c; c >>= ^c; c |= ^c; c &= ^c; |
| 320 | } |
David Green | 0250e29 | 2018-12-13 17:20:06 +0000 | [diff] [blame^] | 321 | )cpp"; |
| 322 | EXPECT_THAT(collectPreferredTypes(code15), Each("NULL TYPE")); |
Ilya Biryukov | 4974d75d | 2018-12-13 16:06:11 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Haojian Wu | 10d95c5 | 2018-01-17 14:29:25 +0000 | [diff] [blame] | 325 | } // namespace |