File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 12
12
#include " clang/AST/ASTTypeTraits.h"
13
13
#include " clang/AST/DeclCXX.h"
14
14
#include " clang/AST/Expr.h"
15
+ #include " clang/AST/ExprCXX.h"
15
16
#include " clang/AST/PrettyPrinter.h"
16
17
#include " clang/AST/RecursiveASTVisitor.h"
17
18
#include " clang/AST/TypeLoc.h"
@@ -245,6 +246,10 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
245
246
if (canSafelySkipNode (N))
246
247
return false ;
247
248
push (std::move (N));
249
+ if (shouldSkipChildren (X)) {
250
+ pop ();
251
+ return false ;
252
+ }
248
253
return true ;
249
254
}
250
255
bool dataTraverseStmtPost (Stmt *X) {
@@ -355,6 +360,15 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
355
360
return true ;
356
361
}
357
362
363
+ // There are certain nodes we want to treat as leaves in the SelectionTree,
364
+ // although they do have children.
365
+ bool shouldSkipChildren (const Stmt *X) const {
366
+ // UserDefinedLiteral (e.g. 12_i) has two children (12 and _i).
367
+ // Unfortunately TokenBuffer sees 12_i as one token and can't split it.
368
+ // So we treat UserDefinedLiteral as a leaf node, owning the token.
369
+ return llvm::isa<UserDefinedLiteral>(X);
370
+ }
371
+
358
372
// Pushes a node onto the ancestor stack. Pairs with pop().
359
373
// Performs early hit detection for some nodes (on the earlySourceRange).
360
374
void push (DynTypedNode Node) {
Original file line number Diff line number Diff line change @@ -304,6 +304,16 @@ TEST(SelectionTest, CommonAncestor) {
304
304
}
305
305
)cpp" ,
306
306
" CallExpr" },
307
+
308
+ // User-defined literals are tricky: is 12_i one token or two?
309
+ // For now we treat it as one, and the UserDefinedLiteral as a leaf.
310
+ {
311
+ R"cpp(
312
+ struct Foo{};
313
+ Foo operator""_ud(unsigned long long);
314
+ Foo x = [[^12_ud]];
315
+ )cpp" ,
316
+ " UserDefinedLiteral" },
307
317
};
308
318
for (const Case &C : Cases) {
309
319
Annotations Test (C.Code );
You can’t perform that action at this time.
0 commit comments