Skip to content

Commit a80f916

Browse files
committed
[cling] Use SuppressUnwrittenScope to strip anonymous namespace names
Since LLVM12, suppressing inline and anonymous namespaces were separated into distinct flags: - SuppressUnwrittenScope: suppresses anonymous namespaces - SuppressInlineNamespace: suppresses redundant inline namespaces See: llvm/llvm-project@5f12f4ff Add `SuppressUnwrittenScope = true` to strip anonymous namespace prefixes Without this, types in anonymous namespaces are printed as '::(anonymous namespace)::EvNavHandler' which is invalid C++ and causes compilation failures in rootcling-generated dictionary code as seen when building dd4hep against ROOT LLVM22. We were relying on `SuppressScope` which was removed in LLVM22. Also update the Transform.C test to reflect the corrected output
1 parent 8701053 commit a80f916

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

core/clingutils/src/TClingUtils.cxx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,10 @@ bool TClingLookupHelper::GetPartiallyDesugaredNameWithScopeHandling(const std::s
660660
policy.SuppressTagKeyword = true; // Never get the class or struct keyword
661661
policy.SuppressTagKeywordInAnonNames = true; // Skip printing tags for anonymous entities
662662
// The scope suppression is required for getting rid of the anonymous part of the name of a class defined in an anonymous namespace.
663-
// This gives us more control vs not using the clang::ElaboratedType and relying on the Policy.SuppressUnwrittenScope which would
664-
// strip both the anonymous and the inline namespace names (and we probably do not want the later to be suppressed).
663+
// In LLVM22 (and before), SuppressUnwrittenScope suppresses anonymous namespaces. Inline namespace suppression is separately
664+
// controlled by SuppressInlineNamespace, which we probably don't want to be suppressed.
665+
policy.SuppressUnwrittenScope = true; // Strip anonymous namespace names
666+
665667
// getAsStringInternal() appends.
666668
result.clear();
667669
dest.getAsStringInternal(result, policy);
@@ -4231,8 +4233,9 @@ void ROOT::TMetaUtils::GetNormalizedName(std::string &norm_name, const clang::Qu
42314233
policy.SuppressTagKeywordInAnonNames = true; // Skip printing tags for anonymous entities
42324234
policy.AnonymousTagLocations = false; // Do not extract file name + line number for anonymous types.
42334235
// The scope suppression is required for getting rid of the anonymous part of the name of a class defined in an anonymous namespace.
4234-
// This gives us more control vs not using the clang::ElaboratedType and relying on the Policy.SuppressUnwrittenScope which would
4235-
// strip both the anonymous and the inline namespace names (and we probably do not want the later to be suppressed).
4236+
// In LLVM22 (and before), SuppressUnwrittenScope suppresses anonymous namespaces. Inline namespace suppression is separately
4237+
// controlled by SuppressInlineNamespace, which we probably don't want to be suppressed.
4238+
policy.SuppressUnwrittenScope = true; // Strip anonymous namespace names
42364239

42374240
std::string normalizedNameStep1;
42384241

interpreter/cling/test/Utils/Transform.C

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,17 @@ Transform::GetPartiallyDesugaredType(Ctx, QT, transConfig).getAsString().c_str()
231231
// The above result is not quite want we want, so the client must using
232232
// the following:
233233
// The scope suppression is required for getting rid of the anonymous part of the name of a class defined in an anonymous namespace.
234-
// This gives us more control vs not using the clang::ElaboratedType and relying on the Policy.SuppressUnwrittenScope which would
235-
// strip both the anonymous and the inline namespace names (and we probably do not want the later to be suppressed).
234+
// In LLVM22 (and before), SuppressUnwrittenScope suppresses anonymous namespaces. Inline namespace suppression is separately
235+
// controlled by SuppressInlineNamespace, which we probably don't want to be suppressed.
236+
Policy.SuppressUnwrittenScope = true; // Strip anonymous namespace names
236237
clang::PrintingPolicy Policy(Ctx.getPrintingPolicy());
237238
Policy.SuppressTagKeyword = true; // Never get the class or struct keyword
238239
Policy.SuppressTagKeywordInAnonNames = true; // Skip printing tags for anonymous entities
239240
Policy.SplitTemplateClosers = true; // Print a<b<c> >' rather than 'a<b<c>>'.
240241
std::string name;
241242
Transform::GetPartiallyDesugaredType(Ctx, QT, transConfig).getAsStringInternal(name,Policy);
242243
name.c_str()
243-
// CHECK: ({{[^)]+}}) "(anonymous namespace)::InsideAnonymous"
244+
// CHECK: ({{[^)]+}}) "InsideAnonymous"
244245

245246
// Test desugaring pointers types:
246247
QT = lookup.findType("Int_t*", diags);

0 commit comments

Comments
 (0)