Skip to content

Commit 259caad

Browse files
authored
[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
1 parent 273777e commit 259caad

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ Bug Fixes to C++ Support
803803
with the same parameters not to be diagnosed. (Fixes #GH93456).
804804
- Clang now diagnoses unexpanded parameter packs in attributes. (Fixes #GH93269).
805805
- Clang now allows ``@$``` in raw string literals. Fixes (#GH93130).
806+
- Fix an assertion failure when checking invalid ``this`` usage in the wrong context. (Fixes #GH91536).
806807

807808
Bug Fixes to AST Handling
808809
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,10 +1444,10 @@ bool Sema::CheckCXXThisType(SourceLocation Loc, QualType Type) {
14441444
// category are defined within such member functions as they are within
14451445
// an implicit object member function).
14461446
DeclContext *DC = getFunctionLevelDeclContext();
1447-
if (const auto *Method = dyn_cast<CXXMethodDecl>(DC);
1448-
Method && Method->isExplicitObjectMemberFunction()) {
1447+
const auto *Method = dyn_cast<CXXMethodDecl>(DC);
1448+
if (Method && Method->isExplicitObjectMemberFunction()) {
14491449
Diag(Loc, diag::err_invalid_this_use) << 1;
1450-
} else if (isLambdaCallWithExplicitObjectParameter(CurContext)) {
1450+
} else if (Method && isLambdaCallWithExplicitObjectParameter(CurContext)) {
14511451
Diag(Loc, diag::err_invalid_this_use) << 1;
14521452
} else {
14531453
Diag(Loc, diag::err_invalid_this_use) << 0;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2+
3+
decltype([]()->decltype(this) { }) a; // expected-error {{invalid use of 'this' outside of a non-static member function}}
4+

0 commit comments

Comments
 (0)