[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
Tue Aug 11 00:20:00 PDT 2020


hokein updated this revision to Diff 284592.
hokein marked an inline comment as done.
hokein added a comment.

address review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85645/new/

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 variadic_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:13, col:29>
+  template <variadic_concept... Ts>
+  Foo();
+
+  // CHECK: CXXFoldExpr {{.*}} <col:13, col:34>
+  template <variadic_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,21 @@
     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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85645.284592.patch
Type: text/x-patch
Size: 1651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200811/350550bd/attachment.bin>


More information about the cfe-commits mailing list