[PATCH] D85645: [AST] Fix the CXXFoldExpr source range when parentheses range is invalid.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 06:11:38 PDT 2020
hokein created this revision.
hokein added a reviewer: nridge.
Herald added a project: clang.
hokein requested review of this revision.
The CXXFoldExpr's range is invalid if the cxxfoldexpr is formed via the
Concept's TypeContraints (because the parentheses are not written in the
source code). We fallback to use the range from the pattern.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85645
Files:
clang/include/clang/AST/ExprCXX.h
clang/test/AST/ast-dump-concepts.cpp
Index: clang/test/AST/ast-dump-concepts.cpp
===================================================================
--- clang/test/AST/ast-dump-concepts.cpp
+++ clang/test/AST/ast-dump-concepts.cpp
@@ -12,6 +12,9 @@
template <typename T, typename U>
concept binary_concept = true;
+template <typename... Ts>
+concept triple_concept = true;
+
template <typename T>
struct Foo {
// CHECK: TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'binary_concept'
@@ -37,4 +40,12 @@
template <typename R>
Foo(R, char) requires unary_concept<R> {
}
+
+ // CHECK: CXXFoldExpr {{.*}} <col:12>
+ template <triple_concept... Ts>
+ Foo();
+
+ // CHECK: CXXFoldExpr {{.*}} <col:12, col:30>
+ template <triple_concept<int>... Ts>
+ Foo();
};
Index: clang/include/clang/AST/ExprCXX.h
===================================================================
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -4575,9 +4575,17 @@
return None;
}
- SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
+ SourceLocation getBeginLoc() const LLVM_READONLY {
+ if (LParenLoc.isValid())
+ return LParenLoc;
+ return getPattern()->getBeginLoc();
+ }
- SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
+ SourceLocation getEndLoc() const LLVM_READONLY {
+ if (RParenLoc.isValid())
+ return RParenLoc;
+ return getPattern()->getEndLoc();
+ }
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXFoldExprClass;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85645.284338.patch
Type: text/x-patch
Size: 1534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200810/f8676124/attachment-0001.bin>
More information about the cfe-commits
mailing list