Skip to content

Commit 5dc4a16

Browse files
committed
[cppyy] Don't leak deprecation warnings when resolving enum types
Cppyy::ResolveEnum() determines an enum's underlying integer type by JIT-compiling a probe expression of the form: ```c++ std::is_same<unsigned int, std::underlying_type<SomeEnum>::type>::value; ``` If the enum being resolved (or its enclosing scope) is marked deprecated, this purely internal introspection emits a `-Wdeprecated-declarations` warning to stderr. Since cppyy resolves enums while wrapping classes, the warning surfaces in ordinary PyROOT sessions that merely touch a class carrying such an enum. This started breaking a range of roottest tests (which diff process output against reference files) after the historical ESTLType/ESTLtype enum copies in TClassEdit, TDictionary and TStreamerElement were deprecated. Wrap the probe expression in clang diagnostic push/ignored/pop pragmas so that resolving a deprecated enum stays silent. 🤖 Done by AI.
1 parent 0edd975 commit 5dc4a16

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

bindings/pyroot/cppyy/cppyy-backend/clingwrapper/src/clingwrapper.cxx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,17 @@ std::string Cppyy::ResolveEnum(const std::string& enum_type)
622622
std::ostringstream decl;
623623
// TODO: now presumed fixed with https://sft.its.cern.ch/jira/browse/ROOT-6988
624624
for (auto& itype : {"unsigned int"}) {
625-
decl << "std::is_same<"
625+
// This is pure type introspection: silence any deprecation warning that
626+
// would otherwise be emitted just because the enum being resolved (or its
627+
// scope) happens to be marked deprecated.
628+
decl << "_Pragma(\"clang diagnostic push\")"
629+
"_Pragma(\"clang diagnostic ignored \\\"-Wdeprecated-declarations\\\"\")"
630+
<< "std::is_same<"
626631
<< itype
627632
<< ", std::underlying_type<"
628633
<< et_short
629-
<< ">::type>::value;";
634+
<< ">::type>::value;"
635+
"_Pragma(\"clang diagnostic pop\")";
630636
if (gInterpreter->ProcessLine(decl.str().c_str())) {
631637
// TODO: "re-sugaring" like this is brittle, but the top
632638
// should be re-translated into AST-based code anyway

0 commit comments

Comments
 (0)