[clang] 259caad - [Clang] Fix an assertion failure when checking invalid `this` (#93490)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 09:08:42 PDT 2024
Author: Oleksandr T
Date: 2024-05-28T18:08:38+02:00
New Revision: 259caad2f75011174d39615bb0ba31955d16d498
URL: https://github.com/llvm/llvm-project/commit/259caad2f75011174d39615bb0ba31955d16d498
DIFF: https://github.com/llvm/llvm-project/commit/259caad2f75011174d39615bb0ba31955d16d498.diff
LOG: [Clang] Fix an assertion failure when checking invalid `this` (#93490)
Skip explicit this check in non-valid scopes due to `null` type in
lambdas with invalid captures or incomplete parameter lists during
parsing
Fixes #91536
Added:
clang/test/SemaCXX/invalid-this-in-lambda.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExprCXX.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b746cda53c71..173e61fbf7b2c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -803,6 +803,7 @@ Bug Fixes to C++ Support
with the same parameters not to be diagnosed. (Fixes #GH93456).
- Clang now diagnoses unexpanded parameter packs in attributes. (Fixes #GH93269).
- Clang now allows ``@$``` in raw string literals. Fixes (#GH93130).
+- Fix an assertion failure when checking invalid ``this`` usage in the wrong context. (Fixes #GH91536).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d3e9dcb4f4399..6595abbcdda5b 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1444,10 +1444,10 @@ bool Sema::CheckCXXThisType(SourceLocation Loc, QualType Type) {
// category are defined within such member functions as they are within
// an implicit object member function).
DeclContext *DC = getFunctionLevelDeclContext();
- if (const auto *Method = dyn_cast<CXXMethodDecl>(DC);
- Method && Method->isExplicitObjectMemberFunction()) {
+ const auto *Method = dyn_cast<CXXMethodDecl>(DC);
+ if (Method && Method->isExplicitObjectMemberFunction()) {
Diag(Loc, diag::err_invalid_this_use) << 1;
- } else if (isLambdaCallWithExplicitObjectParameter(CurContext)) {
+ } else if (Method && isLambdaCallWithExplicitObjectParameter(CurContext)) {
Diag(Loc, diag::err_invalid_this_use) << 1;
} else {
Diag(Loc, diag::err_invalid_this_use) << 0;
diff --git a/clang/test/SemaCXX/invalid-this-in-lambda.cpp b/clang/test/SemaCXX/invalid-this-in-lambda.cpp
new file mode 100644
index 0000000000000..ae65bda025e23
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-this-in-lambda.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+decltype([]()->decltype(this) { }) a; // expected-error {{invalid use of 'this' outside of a non-static member function}}
+
More information about the cfe-commits
mailing list