Work around a build issue with MSVC; NFC (#142195)

Microsoft helpfully defines `THIS` to `void` in two different platform
SDK headers, at least one of which is reachable via <Windows.h>. We have
a user who ran into a build because of `THIS` unfortunate macro name
collision.

Rename the members to better match our naming conventions.

Fixes #142186
This commit is contained in:
Aaron Ballman
2025-05-31 08:35:26 -04:00
committed by GitHub
parent 78eafb14f7
commit 0adf6e8d33
5 changed files with 14 additions and 12 deletions

View File

@@ -1997,10 +1997,12 @@ private:
ArrayRef<SourceLocation> ArgLocs;
public:
static constexpr int THIS = 0;
static constexpr int INVALID = -1;
static constexpr int UNKNOWN = -2;
static constexpr int GLOBAL = -3;
enum ArgIndex {
This = 0,
Invalid = -1,
Unknown = -2,
Global = -3,
};
void setArgs(ArrayRef<IdentifierInfo*> Idents, ArrayRef<SourceLocation> Locs) {
assert(Idents.size() == params_Size);

View File

@@ -665,7 +665,7 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
CanonCallee->getParamDecl(I)->getAttr<LifetimeCaptureByAttr>();
CaptureAttr && isa<CXXConstructorDecl>(CanonCallee) &&
llvm::any_of(CaptureAttr->params(), [](int ArgIdx) {
return ArgIdx == LifetimeCaptureByAttr::THIS;
return ArgIdx == LifetimeCaptureByAttr::This;
}))
// `lifetime_capture_by(this)` in a class constructor has the same
// semantics as `lifetimebound`:

View File

@@ -290,7 +290,7 @@ void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
// pointer-like reference types (`const T&`, `T&&`).
if (PVD->getType()->isReferenceType() &&
sema::isGLSPointerType(PVD->getType().getNonReferenceType())) {
int CaptureByThis[] = {LifetimeCaptureByAttr::THIS};
int CaptureByThis[] = {LifetimeCaptureByAttr::This};
PVD->addAttr(
LifetimeCaptureByAttr::CreateImplicit(Context, CaptureByThis, 1));
}

View File

@@ -3333,8 +3333,8 @@ void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction,
if (!FD || Args.empty())
return;
auto GetArgAt = [&](int Idx) -> const Expr * {
if (Idx == LifetimeCaptureByAttr::GLOBAL ||
Idx == LifetimeCaptureByAttr::UNKNOWN)
if (Idx == LifetimeCaptureByAttr::Global ||
Idx == LifetimeCaptureByAttr::Unknown)
return nullptr;
if (IsMemberFunction && Idx == 0)
return ThisArg;
@@ -3349,7 +3349,7 @@ void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction,
for (int CapturingParamIdx : Attr->params()) {
// lifetime_capture_by(this) case is handled in the lifetimebound expr
// initialization codepath.
if (CapturingParamIdx == LifetimeCaptureByAttr::THIS &&
if (CapturingParamIdx == LifetimeCaptureByAttr::This &&
isa<CXXConstructorDecl>(FD))
continue;
Expr *Capturing = const_cast<Expr *>(GetArgAt(CapturingParamIdx));

View File

@@ -4155,7 +4155,7 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
}
if (!IsValid)
return nullptr;
SmallVector<int> FakeParamIndices(N, LifetimeCaptureByAttr::INVALID);
SmallVector<int> FakeParamIndices(N, LifetimeCaptureByAttr::Invalid);
auto *CapturedBy =
LifetimeCaptureByAttr::Create(Context, FakeParamIndices.data(), N, AL);
CapturedBy->setArgs(ParamIdents, ParamLocs);
@@ -4198,8 +4198,8 @@ void Sema::LazyProcessLifetimeCaptureByParams(FunctionDecl *FD) {
if (Attrs.empty())
return;
llvm::StringMap<int> NameIdxMapping = {
{"global", LifetimeCaptureByAttr::GLOBAL},
{"unknown", LifetimeCaptureByAttr::UNKNOWN}};
{"global", LifetimeCaptureByAttr::Global},
{"unknown", LifetimeCaptureByAttr::Unknown}};
int Idx = 0;
if (HasImplicitThisParam) {
NameIdxMapping["this"] = 0;