Skip to content

Commit dc7b1e9

Browse files
committed
[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
1 parent e6c5e6e commit dc7b1e9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

clang/include/clang/AST/ExprCXX.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4575,9 +4575,21 @@ class CXXFoldExpr : public Expr {
45754575
return None;
45764576
}
45774577

4578-
SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4578+
SourceLocation getBeginLoc() const LLVM_READONLY {
4579+
if (LParenLoc.isValid())
4580+
return LParenLoc;
4581+
if (isLeftFold())
4582+
return getEllipsisLoc();
4583+
return getLHS()->getBeginLoc();
4584+
}
45794585

4580-
SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4586+
SourceLocation getEndLoc() const LLVM_READONLY {
4587+
if (RParenLoc.isValid())
4588+
return RParenLoc;
4589+
if (isRightFold())
4590+
return getEllipsisLoc();
4591+
return getRHS()->getEndLoc();
4592+
}
45814593

45824594
static bool classof(const Stmt *T) {
45834595
return T->getStmtClass() == CXXFoldExprClass;

clang/test/AST/ast-dump-concepts.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ concept unary_concept = true;
1212
template <typename T, typename U>
1313
concept binary_concept = true;
1414

15+
template <typename... Ts>
16+
concept variadic_concept = true;
17+
1518
template <typename T>
1619
struct Foo {
1720
// CHECK: TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'binary_concept'
@@ -37,4 +40,12 @@ struct Foo {
3740
template <typename R>
3841
Foo(R, char) requires unary_concept<R> {
3942
}
43+
44+
// CHECK: CXXFoldExpr {{.*}} <col:13, col:29>
45+
template <variadic_concept... Ts>
46+
Foo();
47+
48+
// CHECK: CXXFoldExpr {{.*}} <col:13, col:34>
49+
template <variadic_concept<int>... Ts>
50+
Foo();
4051
};

0 commit comments

Comments
 (0)