[llvm] [TableGen] Avoid deprecated-enum-enum-conversion C++20 warnings; NFC (PR #218909)
Sven van Haastregt via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 05:00:01 PDT 2026
https://github.com/svenvh created https://github.com/llvm/llvm-project/pull/218909
The bitwise OR of different enum types resulted in many C++20 deprecation warnings in the generated option tables:
warning: bitwise operation between different enumeration types
‘llvm::opt::DriverVisibility’ and
‘clang::options::ClangVisibility’ is deprecated
[-Wdeprecated-enum-enum-conversion]
Fix by emitting casts to `unsigned`, matching the types of the corresponding fields in `OptTable::Info`.
>From efe59766193df85bfa52b9756a83ac829d6969b3 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt <sven.vanhaastregt at arm.com>
Date: Tue, 25 Aug 2026 14:59:40 +0100
Subject: [PATCH] [TableGen] Avoid deprecated-enum-enum-conversion C++20
warnings; NFC
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The bitwise OR of different enum types resulted in many C++20
deprecation warnings in the generated option tables:
warning: bitwise operation between different enumeration types
‘llvm::opt::DriverVisibility’ and
‘clang::options::ClangVisibility’ is deprecated
[-Wdeprecated-enum-enum-conversion]
Fix by emitting casts to `unsigned`, matching the types of the
corresponding fields in `OptTable::Info`.
---
llvm/utils/TableGen/OptionParserEmitter.cpp | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/llvm/utils/TableGen/OptionParserEmitter.cpp b/llvm/utils/TableGen/OptionParserEmitter.cpp
index 829c202b495e4..471119edccfd6 100644
--- a/llvm/utils/TableGen/OptionParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptionParserEmitter.cpp
@@ -524,11 +524,12 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
int NumFlags = 0;
const ListInit *LI = R.getValueAsListInit("Flags");
for (const Init *I : *LI)
- OS << (NumFlags++ ? " | " : "") << cast<DefInit>(I)->getDef()->getName();
+ OS << (NumFlags++ ? " | " : "") << "static_cast<unsigned>("
+ << cast<DefInit>(I)->getDef()->getName() << ")";
if (GroupFlags) {
for (const Init *I : *GroupFlags)
- OS << (NumFlags++ ? " | " : "")
- << cast<DefInit>(I)->getDef()->getName();
+ OS << (NumFlags++ ? " | " : "") << "static_cast<unsigned>("
+ << cast<DefInit>(I)->getDef()->getName() << ")";
}
if (NumFlags == 0)
OS << '0';
@@ -538,12 +539,12 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
int NumVisFlags = 0;
LI = R.getValueAsListInit("Visibility");
for (const Init *I : *LI)
- OS << (NumVisFlags++ ? " | " : "")
- << cast<DefInit>(I)->getDef()->getName();
+ OS << (NumVisFlags++ ? " | " : "") << "static_cast<unsigned>("
+ << cast<DefInit>(I)->getDef()->getName() << ")";
if (GroupVis) {
for (const Init *I : *GroupVis)
- OS << (NumVisFlags++ ? " | " : "")
- << cast<DefInit>(I)->getDef()->getName();
+ OS << (NumVisFlags++ ? " | " : "") << "static_cast<unsigned>("
+ << cast<DefInit>(I)->getDef()->getName() << ")";
}
if (NumVisFlags == 0)
OS << '0';
More information about the llvm-commits
mailing list