Skip to content

Commit 0adf6e8

Browse files
authored
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
1 parent 78eafb1 commit 0adf6e8

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,10 +1997,12 @@ private:
19971997
ArrayRef<SourceLocation> ArgLocs;
19981998

19991999
public:
2000-
static constexpr int THIS = 0;
2001-
static constexpr int INVALID = -1;
2002-
static constexpr int UNKNOWN = -2;
2003-
static constexpr int GLOBAL = -3;
2000+
enum ArgIndex {
2001+
This = 0,
2002+
Invalid = -1,
2003+
Unknown = -2,
2004+
Global = -3,
2005+
};
20042006

20052007
void setArgs(ArrayRef<IdentifierInfo*> Idents, ArrayRef<SourceLocation> Locs) {
20062008
assert(Idents.size() == params_Size);

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
665665
CanonCallee->getParamDecl(I)->getAttr<LifetimeCaptureByAttr>();
666666
CaptureAttr && isa<CXXConstructorDecl>(CanonCallee) &&
667667
llvm::any_of(CaptureAttr->params(), [](int ArgIdx) {
668-
return ArgIdx == LifetimeCaptureByAttr::THIS;
668+
return ArgIdx == LifetimeCaptureByAttr::This;
669669
}))
670670
// `lifetime_capture_by(this)` in a class constructor has the same
671671
// semantics as `lifetimebound`:

clang/lib/Sema/SemaAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
290290
// pointer-like reference types (`const T&`, `T&&`).
291291
if (PVD->getType()->isReferenceType() &&
292292
sema::isGLSPointerType(PVD->getType().getNonReferenceType())) {
293-
int CaptureByThis[] = {LifetimeCaptureByAttr::THIS};
293+
int CaptureByThis[] = {LifetimeCaptureByAttr::This};
294294
PVD->addAttr(
295295
LifetimeCaptureByAttr::CreateImplicit(Context, CaptureByThis, 1));
296296
}

clang/lib/Sema/SemaChecking.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,8 +3333,8 @@ void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction,
33333333
if (!FD || Args.empty())
33343334
return;
33353335
auto GetArgAt = [&](int Idx) -> const Expr * {
3336-
if (Idx == LifetimeCaptureByAttr::GLOBAL ||
3337-
Idx == LifetimeCaptureByAttr::UNKNOWN)
3336+
if (Idx == LifetimeCaptureByAttr::Global ||
3337+
Idx == LifetimeCaptureByAttr::Unknown)
33383338
return nullptr;
33393339
if (IsMemberFunction && Idx == 0)
33403340
return ThisArg;
@@ -3349,7 +3349,7 @@ void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction,
33493349
for (int CapturingParamIdx : Attr->params()) {
33503350
// lifetime_capture_by(this) case is handled in the lifetimebound expr
33513351
// initialization codepath.
3352-
if (CapturingParamIdx == LifetimeCaptureByAttr::THIS &&
3352+
if (CapturingParamIdx == LifetimeCaptureByAttr::This &&
33533353
isa<CXXConstructorDecl>(FD))
33543354
continue;
33553355
Expr *Capturing = const_cast<Expr *>(GetArgAt(CapturingParamIdx));

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4155,7 +4155,7 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
41554155
}
41564156
if (!IsValid)
41574157
return nullptr;
4158-
SmallVector<int> FakeParamIndices(N, LifetimeCaptureByAttr::INVALID);
4158+
SmallVector<int> FakeParamIndices(N, LifetimeCaptureByAttr::Invalid);
41594159
auto *CapturedBy =
41604160
LifetimeCaptureByAttr::Create(Context, FakeParamIndices.data(), N, AL);
41614161
CapturedBy->setArgs(ParamIdents, ParamLocs);
@@ -4198,8 +4198,8 @@ void Sema::LazyProcessLifetimeCaptureByParams(FunctionDecl *FD) {
41984198
if (Attrs.empty())
41994199
return;
42004200
llvm::StringMap<int> NameIdxMapping = {
4201-
{"global", LifetimeCaptureByAttr::GLOBAL},
4202-
{"unknown", LifetimeCaptureByAttr::UNKNOWN}};
4201+
{"global", LifetimeCaptureByAttr::Global},
4202+
{"unknown", LifetimeCaptureByAttr::Unknown}};
42034203
int Idx = 0;
42044204
if (HasImplicitThisParam) {
42054205
NameIdxMapping["this"] = 0;

0 commit comments

Comments
 (0)