https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95607
Bug ID: 95607 Summary: Inconsistent treating of default argument instantiation as immediate context Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: akrzemi1 at gmail dot com Target Milestone: --- Consider the following three declarations in exactly this order: ``` template<typename T> int f(T, T = "") ; int f(...) ; template<typename T> concept has_f = requires (T v) { f(v); }; ``` If I evaluate expression `has_f<int>` it returns `false`. This is quite surprising because other compilers, like Clang give me a hard error because in order to test the satisfaction of the concept it has to perform *default argument instantiation*. But we could call it "implementation divergence". Anyway, GCC apparently considers the default argument instantiation to be *in* immediate context. But when I make the call `f(1)` I get a hard error. The first overload cannot work because the default argument cannot be instantiated. The second one would wort, but it is not even considered. So it looks like in this case GCC treats default argument instantiation as *not being in* immediate context. This is two different behaviors in two different contexts. It is confusing, and difficult to build a mental model that would help anticipate when we get a hard error and when we get a SFINAE-detectable one.