AaronBallman wrote:

> Thanks for the feedback!
> 
> Is there a way to call `ASTContext::createMangleContext()` when I have a 
> `const ASTUnit`? I've tried to make `ASTContext::createMangleContext()` const 
> but this failed as it seems to actually call methods that potentially modify 
> the context.
> 
> However, when I have a `const Decl`, I can just call 
> `getAstContext().createMangleContext()`.

There's two answers. In a world where we have const correctness, you shouldn't 
be able to (this is a misfeature on `Decl` that it has a `const` overload that 
returns a `const ASTContext &`). However, Clang inherited a lack of const 
correctness from the mists of time, so we have these sort of misfeatures still 
lurking (and will for quite some time). So for now, the recommendation is 
`const_cast` so it's clear where we're breaking const correctness.

https://github.com/llvm/llvm-project/pull/130096
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to