Hi! The following testcase ICEs since r12-6080. The problem is that lookup_fnfields can return NULL_TREE on failure, but the maybe_incomplete handling was added before the if (!baselink) handling and assumes that baselink is non-NULL (and BASELINK).
The following patch reorders the if (maybe_incomplete) handling with if (!baselink). Bootstrapped/regtested on x86_64-linux and i686-linux, approved in the PR by Patrick, committed to trunk (so far). 2025-11-20 Jakub Jelinek <[email protected]> PR c++/120876 * pt.cc (tsubst_baselink): Move maybe_incomplete handling after !baselink handling. * g++.dg/parse/crash81.C: New test. --- gcc/cp/pt.cc.jj 2025-11-17 09:39:39.627473470 +0100 +++ gcc/cp/pt.cc 2025-11-19 16:35:48.922884412 +0100 @@ -17625,19 +17625,6 @@ tsubst_baselink (tree baselink, tree obj bool maybe_incomplete = BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink); baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1, complain); - if (maybe_incomplete) - { - /* Filter out from the new lookup set those functions which didn't - appear in the original lookup set (in a less specialized form). - This is needed to preserve the consistency of member lookup - performed in an incomplete-class context, within which - later-declared members ought to remain invisible. */ - BASELINK_FUNCTIONS (baselink) - = filter_memfn_lookup (fns, BASELINK_FUNCTIONS (baselink), - binfo_type); - BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink) = true; - } - if (!baselink) { if (complain & tf_error) @@ -17655,6 +17642,19 @@ tsubst_baselink (tree baselink, tree obj return error_mark_node; } + if (maybe_incomplete) + { + /* Filter out from the new lookup set those functions which didn't + appear in the original lookup set (in a less specialized form). + This is needed to preserve the consistency of member lookup + performed in an incomplete-class context, within which + later-declared members ought to remain invisible. */ + BASELINK_FUNCTIONS (baselink) + = filter_memfn_lookup (fns, BASELINK_FUNCTIONS (baselink), + binfo_type); + BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink) = true; + } + fns = BASELINK_FUNCTIONS (baselink); } else --- gcc/testsuite/g++.dg/parse/crash81.C.jj 2025-11-19 16:41:21.651130105 +0100 +++ gcc/testsuite/g++.dg/parse/crash81.C 2025-11-19 16:40:35.614787909 +0100 @@ -0,0 +1,14 @@ +// PR c++/120876 +// { dg-do compile { target c++11 } } + +template <typename T> +struct S { + static bool foo (decltype (bar (T {}))); // { dg-error "'bar' was not declared in this scope; did you mean 'baz'\\\?" } + static constexpr bool s = foo (0); // { dg-error "declaration of 'S<int>::foo' depends on itself" } +}; + +void +baz () +{ + S <int>::s; +} Jakub
