[clang] [Clang] Fix misleading diagnostic for pointer const type static data member (PR #223596)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 15 05:06:49 PDT 2026


================

----------------
AaronBallman wrote:

I think it's one of those "depends on context" situations. If you're writing modern C++ code, then I think the expectation is to push people to inserting `constexpr`; if you're maintaining an ancient C++ code base, then I think the push towards defining it out-of-line rather than an in-class initializer is reasonable.

However, the one thing which makes this a bit difficult is: `constexpr` implies `const` and so this is actually pushing people towards a functionally different solution than what they wrote. e.g., they may want `aaa` to be a `non-const` pointer because they want to modify it later and this is just a default value. In that case, pushing to `constexpr` would push them in the wrong direction.

So I'm not convinced a change here is warranted; I think this premise is incorrect:

> This message is misleading. The most appropriate diagnostic here would be

the message is not misleading, it's telling the user how to repair the code they wrote to keep the same semantics.

CC @erichkeane @cor3ntin @jyknight @Sirraide for some additional opinions

https://github.com/llvm/llvm-project/pull/223596


More information about the cfe-commits mailing list