[clang] Change `ASTUnit::getASTContext() const` to return a non-const `ASTContext` (PR #130096)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 6 06:52:54 PST 2025
AaronBallman wrote:
> There is no const_cast, or casting away const in any form on this patch, so how does it weaken const correctness?
When a function is marked as `const`, the implication is that calling the function should not lead to an underlying mutation. Given that this function is returning data it holds (`*Ctx`), the expectation is that the return value is also `const`-qualified. The typical pattern is to have an overload set as in the original code -- the non-const version can return something which can mutate, the const version can return something which doesn't allow for mutation without casting away the constness.
https://github.com/llvm/llvm-project/pull/130096
More information about the cfe-commits
mailing list