https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99686
--- Comment #5 from Steven Sun <StevenSun2021 at hotmail dot com> --- I learn a little about gcc recently. I think I got a vague idea of what's going on inside. In c++17 mode with concepts, and with my code in comment 1. The compiler decides to instantiate from the concept constrained template. -------------------------------------------------------------------- Usually the compiler should generate a new function on the AST, but this time there's already one function (fully specialized) on the AST. So, the function `start_preparsed_function` in the below link returns at the quoted line. It's thinking "Ah! There's already a function, no need to allocate a new one." https://gcc.gnu.org/git?p=gcc.git;a=blob;f=gcc/cp/decl.c;h=316ad4c1426940bd4f51197a6297eefc24064fec;hb=HEAD#l16696 -------------------------------------------------------------------- Then the flow goes back to the function in the link below. It's thinking "Since I'm gonna add a new function, new function is allocated on AST. Everything should be prepared for me!" More specifially, it will assume the `cfun` in the correct state set by the `start_preparsed_function`. But `cfun` is null, since the `start_preparsed_function` returns early. This is the direct cause of segfault, which triggered at the line below. https://gcc.gnu.org/git?p=gcc.git;a=blob;f=gcc/cp/pt.c;h=36a8cb5df5d36337c18e1547e775b747f59a087f;hb=HEAD#l25932 -------------------------------------------------------------------- In conclusion, The compiler doesn't consider there would be a situation that an instatiation is still needed when full specialzation is provided. This break the invariants.