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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits