clang::MangleContext::shouldMangleDeclName

Hi,
   shouldMangleDeclName returns true for decls like EnumConstantDecl.
   Is that expected behaviour? Am I missing something?
Vassil

It doesn't really return anything meaningful for declarations that
obviously aren't mangled.

John.

To clarify, that query is only meaningful for declarations that can be
directly referenced as global symbols. It's not meaningful for, say,
enum constants or classes or using declarations.

John.

Thanks for the answer, John!

It's somehow contra-intuitive for shouldMangleDeclName to return true for decls that aren't/can't be mangled.

I know that I can solve the issue on my side, but I thought this is the original idea of that interface. Isn't it better to check for the decls that are mangled and for everything else to return false?
Vassil

The point of the function is to decide whether the linking symbol for the declaration should be mangled, as opposed to simply being the same as its identifier. It does not make sense to ask whether to mangle the linking symbol of a declaration that does not have a linking symbol. If you would like to prepare a patch to have this function assert when given an EnumConstantDecl, that would be acceptable; but otherwise I see no reason to prefer any particular answer.

John.

John,
   I see your point. You come from the fact that the uses of the function in clang are through GlobalDecl, which is translated to a global symbol.
   My use-case was to provide an interface (see below), where (that was I thought first) shouldMangleDeclName will help me avoid the asserts in mangleName.

   void mangleName(const clang::NamedDecl* D,
                                std::string& mangledName) const {
     if (!m_MangleCtx) {
m_MangleCtx.reset(getCI()->getASTContext().createMangleContext());
     }
     if (m_MangleCtx->shouldMangleDeclName(D)) {
       llvm::raw_string_ostream RawStr(mangledName);
       m_MangleCtx->mangleName(D, RawStr);
       RawStr.flush();
     } else {
       mangledName = D->getNameAsString();
     }
   }

Of course I can and will work that around on my side, but I thought is good to have.
Thanks for the explanation!
Vassil