On Sat, Jan 17, 2026 at 11:49:09PM +1100, Nathaniel Shead wrote:
> I'm not sure if this is really the best approach in the end but should
> fix the errors at least.

Thanks for working on this and I think parts it will be useful in any case,
I think the caching will be useful anyway.

Something I've discussed on internal chat with Marek shows further problems.

Currently consteval_only_p only calls complete_type on the type it is
called on (resp. on type of the decl it is called on).
But, consteval-only is not just about class types, but also about
pointers/references to them, arrays thereof, function types somewhere
referencing those, pointer to member referencing those, see
https://eel.is/c++draft/basic.types.general#12

E.g.
template <typename T, T V> struct S { T s = V; };
constexpr S <decltype (^^::), ^^::> *p = nullptr;
Here, when consteval_only_p is called on p, it returns false (complete_type
does nothing, because POINTER_TYPE_P there is complete I think), but
what it points to is not complete and it should really return true.
So I'm afraid we shouldn't call complete_type in consteval_only_p but
in consteval_only_type_r; for class types first check
CLASSTYPE_CONSTEVAL_ONLY_P_SET and in that case return
CLASSTYPE_CONSTEVAL_ONLY_P, otherwise call complete_type
and walk the type afterwards.

And another testcase I have no idea what actually should happen is
struct Q;
constexpr Q *q = nullptr;
struct Q { decltype (^^int) x = ^^int; };
I think Q * is not a consteval-only type when parsing the q declaration,
but when the Q class is defined, it is consteval-only and so is Q *.
So, shall we somehow later on arrange for q not to be emitted (or error
if say something non-consteval made it odr-used?  Though, if what is
consteval-only can change at any point, that is kind of complicated.

Though, that also means we shouldn't set CLASSTYPE_CONSTEVAL_ONLY_P_SET
on incomplete class types because even when they aren't consteval-only
when queried, they might be later on.

        Jakub

Reply via email to