Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ bool Sema::CheckCXXThisType(SourceLocation Loc, QualType Type) {
const auto *Method = dyn_cast<CXXMethodDecl>(DC);
if (Method && Method->isExplicitObjectMemberFunction()) {
Diag(Loc, diag::err_invalid_this_use) << 1;
} else if (Method && isLambdaCallWithExplicitObjectParameter(CurContext)) {
} else if (Method && isLambdaCallWithExplicitObjectParameter(DC)) {
Diag(Loc, diag::err_invalid_this_use) << 1;
} else {
Diag(Loc, diag::err_invalid_this_use) << 0;
Expand Down
65 changes: 65 additions & 0 deletions clang/test/CXX/expr/expr.prim/expr.prim.this/p4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s

namespace N0 {
struct A {
static void f() {
[]() -> decltype(this) { }; // expected-error{{invalid use of 'this' outside of a non-static member function}}
}
};
} // namespace N0

namespace N1 {
struct A {
static void f() {
[]() noexcept(decltype(this)()) { }; // expected-error{{invalid use of 'this' outside of a non-static member function}}
}
};
} // namespace N1

namespace N2 {
struct A {
static void f() {
[](this auto&&) -> decltype(this) { }; // expected-error{{invalid use of 'this' outside of a non-static member function}}
}
};
} // namespace N2

namespace N3 {
struct A {
static void f() {
[](this auto&&) noexcept(decltype(this)()) { }; // expected-error{{invalid use of 'this' outside of a non-static member function}}
}
};
} // namespace N3

namespace N4 {
struct A {
void f() {
[]() -> decltype(this) { };
}
};
} // namespace N4

namespace N5 {
struct A {
void f() {
[]() noexcept(decltype(this)()) { }; // expected-error{{conversion from 'decltype(this)' (aka 'N5::A *') to 'bool' is not allowed in a converted constant expression}}
}
};
} // namespace N5

namespace N6 {
struct A {
void f() {
[](this auto&&) -> decltype(this) { };
}
};
} // namespace N6

namespace N7 {
struct A {
void f() {
[](this auto&&) noexcept(decltype(this)()) { }; // expected-error{{conversion from 'decltype(this)' (aka 'N7::A *') to 'bool' is not allowed in a converted constant expression}}
}
};
} // namespace N7
Loading