Skip to content

Conversation

@HighCommander4
Copy link
Collaborator

Backport 289baf1

Fixes #135922

@HighCommander4 HighCommander4 added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Apr 16, 2025
@HighCommander4 HighCommander4 added this to the LLVM 20.X Release milestone Apr 16, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Apr 16, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 16, 2025
@HighCommander4 HighCommander4 requested a review from zyn0217 April 16, 2025 07:50
@llvmbot
Copy link
Member

llvmbot commented Apr 16, 2025

@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)

Changes

Backport 289baf1

Fixes #135922


Full diff: https://github.com/llvm/llvm-project/pull/135927.diff

2 Files Affected:

  • (modified) clang/lib/AST/Expr.cpp (+5-2)
  • (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+7)
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@-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'}}
+};
+}

@HighCommander4 HighCommander4 requested a review from cor3ntin April 16, 2025 07:50
@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Apr 16, 2025
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tstellar tstellar force-pushed the issue-135522-backport branch from a9ea5de to 62072e7 Compare April 25, 2025 23:29
@tstellar tstellar merged commit 62072e7 into llvm:release/20.x Apr 25, 2025
7 of 10 checks passed
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Apr 25, 2025
@github-actions
Copy link

@HighCommander4 (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

Development

Successfully merging this pull request may close these issues.

5 participants