[llvm-branch-commits] [clang] 62072e7 - [clang][AST] Handle implicit first argument in CallExpr::getBeginLoc()

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Apr 25 16:29:50 PDT 2025


Author: Nathan Ridge
Date: 2025-04-25T16:29:08-07:00
New Revision: 62072e7f877e444f386ea78dce3581904bdb727d

URL: https://github.com/llvm/llvm-project/commit/62072e7f877e444f386ea78dce3581904bdb727d
DIFF: https://github.com/llvm/llvm-project/commit/62072e7f877e444f386ea78dce3581904bdb727d.diff

LOG: [clang][AST] Handle implicit first argument in CallExpr::getBeginLoc()

Added: 
    

Modified: 
    clang/lib/AST/Expr.cpp
    clang/test/SemaCXX/cxx2b-deducing-this.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 8571b617c70eb..a5b7ef8c4271b 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1665,8 +1665,11 @@ SourceLocation CallExpr::getBeginLoc() const {
         Method && Method->isExplicitObjectMemberFunction()) {
       bool HasFirstArg = getNumArgs() > 0 && getArg(0);
       assert(HasFirstArg);
-      if (HasFirstArg)
-        return getArg(0)->getBeginLoc();
+      if (HasFirstArg) {
+        if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
+          return FirstArgLoc;
+        }
+      }
     }
   }
 

diff  --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 6f17ce7275456..7e392213710a4 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1134,3 +1134,10 @@ struct S {
 static_assert((S{} << 11) == a);
 // expected-error at -1 {{use of undeclared identifier 'a'}}
 }
+
+namespace GH135522 {
+struct S {
+  auto f(this auto) -> S;
+  bool g() { return f(); } // expected-error {{no viable conversion from returned value of type 'S' to function return type 'bool'}}
+};
+}


        


More information about the llvm-branch-commits mailing list