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
This commit is contained in:
Giuliano Belinassi
2023-09-11 06:51:11 -07:00
committed by erichkeane
parent 12ac0f6ede
commit 0323938d3c
2 changed files with 28 additions and 5 deletions

View File

@@ -250,13 +250,23 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
return Out;
}
static bool canPrintOnLeftSide(attr::Kind kind) {
switch (kind) {
// For CLANG_ATTR_LIST_CanPrintOnLeft macro.
#include "clang/Basic/AttrLeftSideCanPrintList.inc"
// For CLANG_ATTR_LIST_PrintOnLeft macro.
#include "clang/Basic/AttrLeftSideMustPrintList.inc"
static bool canPrintOnLeftSide(attr::Kind kind) {
#ifdef CLANG_ATTR_LIST_CanPrintOnLeft
switch (kind) {
CLANG_ATTR_LIST_CanPrintOnLeft
return true;
default:
return false;
}
#else
return false;
#endif
}
static bool canPrintOnLeftSide(const Attr *A) {
@@ -268,11 +278,16 @@ static bool canPrintOnLeftSide(const Attr *A) {
static bool mustPrintOnLeftSide(attr::Kind kind) {
switch (kind) {
#include "clang/Basic/AttrLeftSideMustPrintList.inc"
#ifdef CLANG_ATTR_LIST_PrintOnLeft
switch (kind) {
CLANG_ATTR_LIST_PrintOnLeft
return true;
default:
return false;
}
#else
return false;
#endif
}
static bool mustPrintOnLeftSide(const Attr *A) {
@@ -314,7 +329,6 @@ void DeclPrinter::prettyPrintAttributes(Decl *D, llvm::raw_ostream &Out,
VD->getInitStyle() == VarDecl::CallInit)
AttrLoc = AttrPrintLoc::Left;
}
// Only print the side matches the user requested.
if ((Loc & AttrLoc) != AttrPrintLoc::None)
A->printPretty(Out, Policy);

View File

@@ -3217,6 +3217,8 @@ void EmitClangAttrPrintList(const std::string &FieldName, RecordKeeper &Records,
std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
std::vector<Record *> PragmaAttrs;
bool first = false;
for (auto *Attr : Attrs) {
if (!Attr->getValueAsBit("ASTNode"))
continue;
@@ -3224,8 +3226,15 @@ void EmitClangAttrPrintList(const std::string &FieldName, RecordKeeper &Records,
if (!Attr->getValueAsBit(FieldName))
continue;
OS << "case attr::" << Attr->getName() << ":\n";
if (!first) {
first = true;
OS << "#define CLANG_ATTR_LIST_" << FieldName;
}
OS << " \\\n case attr::" << Attr->getName() << ":";
}
OS << '\n';
}
// Emits the enumeration list for attributes.