[clang] dc7b1e9 - [AST] Fix the CXXFoldExpr source range when parentheses range is invalid.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 00:20:54 PDT 2020
Author: Haojian Wu
Date: 2020-08-12T09:20:23+02:00
New Revision: dc7b1e9db58152273d3232cca3fa95cef721796b
URL: https://github.com/llvm/llvm-project/commit/dc7b1e9db58152273d3232cca3fa95cef721796b
DIFF: https://github.com/llvm/llvm-project/commit/dc7b1e9db58152273d3232cca3fa95cef721796b.diff
LOG: [AST] Fix the CXXFoldExpr source range when parentheses range is invalid.
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.
Differential Revision: https://reviews.llvm.org/D85645
Added:
Modified:
clang/include/clang/AST/ExprCXX.h
clang/test/AST/ast-dump-concepts.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index b53bb20f7ebc..6b4b57eca9be 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4575,9 +4575,21 @@ class CXXFoldExpr : public Expr {
return None;
}
- SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
+ SourceLocation getBeginLoc() const LLVM_READONLY {
+ if (LParenLoc.isValid())
+ return LParenLoc;
+ if (isLeftFold())
+ return getEllipsisLoc();
+ return getLHS()->getBeginLoc();
+ }
- SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
+ SourceLocation getEndLoc() const LLVM_READONLY {
+ if (RParenLoc.isValid())
+ return RParenLoc;
+ if (isRightFold())
+ return getEllipsisLoc();
+ return getRHS()->getEndLoc();
+ }
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXFoldExprClass;
diff --git a/clang/test/AST/ast-dump-concepts.cpp b/clang/test/AST/ast-dump-concepts.cpp
index 524ac0f65a06..dff300a55951 100644
--- a/clang/test/AST/ast-dump-concepts.cpp
+++ b/clang/test/AST/ast-dump-concepts.cpp
@@ -12,6 +12,9 @@ concept unary_concept = true;
template <typename T, typename U>
concept binary_concept = true;
+template <typename... Ts>
+concept variadic_concept = true;
+
template <typename T>
struct Foo {
// CHECK: TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'binary_concept'
@@ -37,4 +40,12 @@ struct Foo {
template <typename R>
Foo(R, char) requires unary_concept<R> {
}
+
+ // CHECK: CXXFoldExpr {{.*}} <col:13, col:29>
+ template <variadic_concept... Ts>
+ Foo();
+
+ // CHECK: CXXFoldExpr {{.*}} <col:13, col:34>
+ template <variadic_concept<int>... Ts>
+ Foo();
};
More information about the cfe-commits
mailing list