https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123404
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:de19477814821362e0a2b3c10fc1d7cf62be60cc commit r16-7060-gde19477814821362e0a2b3c10fc1d7cf62be60cc Author: Jakub Jelinek <[email protected]> Date: Tue Jan 27 10:23:43 2026 +0100 c++: Don't error on non-consteval defaulted special members in consteval-only classes [PR123404] As discussed earlier, the following testcase is incorrectly rejected. While check_consteval_only_fn -> immediate_escalating_function_p knows that defaulted special members are immediate-scalating: /* -- a defaulted special member function that is not declared with the consteval specifier */ special_function_kind sfk = special_memfn_p (fn); if (sfk != sfk_none && DECL_DEFAULTED_FN (fn)) return true; it returns false anyway, because the call is too early and DECL_DEFAULTED_FN is not set yet (unlike DECL_DELETED_FN). For DECL_DEFAULTED_FN there is quite more code, involving diagnostics for invalid uses of = delete etc. later in grokfield: else if (init == ridpointers[(int)RID_DEFAULT]) { if (defaultable_fn_check (value)) { DECL_DEFAULTED_FN (value) = 1; DECL_INITIALIZED_IN_CLASS_P (value) = 1; DECL_DECLARED_INLINE_P (value) = 1; /* grokfndecl set this to error_mark_node, but we want to leave it unset until synthesize_method. */ DECL_INITIAL (value) = NULL_TREE; } } but that is after the else if (init == ridpointers[(int)RID_DEFAULT]) initialized = SD_DEFAULTED; ... value = grokdeclarator (declarator, declspecs, FIELD, initialized, &attrlist); call in the same function where grokdeclarator calls grokfndecl. As for defaulted special member functions there is nothing to diagnose, those are always immediate-escalating or explicitly consteval and neither of those is diagnosed, the following patch just passes not just whether a fn is deleted, but whole initialized, so both whether it is deleted or defaulted, and just doesn't call check_consteval_only_fn in that case. During pt.cc check_consteval_only_fn call DECL_DEFAULTED_FN is already set before we test it. 2026-01-27 Jakub Jelinek <[email protected]> PR c++/123404 * decl.cc (grokfndecl): Replace bool deletedp argument with int initialized. Test initialized == SD_DELETED instead of deletedp. Don't call check_consteval_only_fn for defaulted special member fns. (grokdeclarator): Pass initialized rather than initialized == SD_DELETED to grokfndecl. * g++.dg/reflect/pr123404.C: New test.
