Skip to content

Commit 0323938

Browse files
giulianobelinassierichkeane
authored andcommitted
Fix warning in MSVC
Currently there is no PrintOnLeft attribute set, which results in an empty switch-case. When compiling this, MSVC issues a warning saying that the switch-case is empty. Fix this by using a macro and checking if this macro is defined or not. Links to D157394
1 parent 12ac0f6 commit 0323938

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

clang/lib/AST/DeclPrinter.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,23 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
250250
return Out;
251251
}
252252

253+
// For CLANG_ATTR_LIST_CanPrintOnLeft macro.
254+
#include "clang/Basic/AttrLeftSideCanPrintList.inc"
255+
256+
// For CLANG_ATTR_LIST_PrintOnLeft macro.
257+
#include "clang/Basic/AttrLeftSideMustPrintList.inc"
258+
253259
static bool canPrintOnLeftSide(attr::Kind kind) {
260+
#ifdef CLANG_ATTR_LIST_CanPrintOnLeft
254261
switch (kind) {
255-
#include "clang/Basic/AttrLeftSideCanPrintList.inc"
262+
CLANG_ATTR_LIST_CanPrintOnLeft
256263
return true;
257264
default:
258265
return false;
259266
}
267+
#else
268+
return false;
269+
#endif
260270
}
261271

262272
static bool canPrintOnLeftSide(const Attr *A) {
@@ -268,11 +278,16 @@ static bool canPrintOnLeftSide(const Attr *A) {
268278

269279
static bool mustPrintOnLeftSide(attr::Kind kind) {
270280
switch (kind) {
271-
#include "clang/Basic/AttrLeftSideMustPrintList.inc"
281+
#ifdef CLANG_ATTR_LIST_PrintOnLeft
282+
switch (kind) {
283+
CLANG_ATTR_LIST_PrintOnLeft
272284
return true;
273285
default:
274286
return false;
275287
}
288+
#else
289+
return false;
290+
#endif
276291
}
277292

278293
static bool mustPrintOnLeftSide(const Attr *A) {
@@ -314,7 +329,6 @@ void DeclPrinter::prettyPrintAttributes(Decl *D, llvm::raw_ostream &Out,
314329
VD->getInitStyle() == VarDecl::CallInit)
315330
AttrLoc = AttrPrintLoc::Left;
316331
}
317-
318332
// Only print the side matches the user requested.
319333
if ((Loc & AttrLoc) != AttrPrintLoc::None)
320334
A->printPretty(Out, Policy);

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3217,15 +3217,24 @@ void EmitClangAttrPrintList(const std::string &FieldName, RecordKeeper &Records,
32173217

32183218
std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
32193219
std::vector<Record *> PragmaAttrs;
3220+
bool first = false;
3221+
32203222
for (auto *Attr : Attrs) {
32213223
if (!Attr->getValueAsBit("ASTNode"))
32223224
continue;
32233225

32243226
if (!Attr->getValueAsBit(FieldName))
32253227
continue;
32263228

3227-
OS << "case attr::" << Attr->getName() << ":\n";
3229+
if (!first) {
3230+
first = true;
3231+
OS << "#define CLANG_ATTR_LIST_" << FieldName;
3232+
}
3233+
3234+
OS << " \\\n case attr::" << Attr->getName() << ":";
32283235
}
3236+
3237+
OS << '\n';
32293238
}
32303239

32313240
// Emits the enumeration list for attributes.

0 commit comments

Comments
 (0)