https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94894
Patrick Palka <ppalka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|13.0 |--- Status|RESOLVED |NEW Resolution|FIXED |--- CC| |jason at gcc dot gnu.org --- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> --- Good point, this PR is only partially fixed then (since GCC 13). Avoiding the unnecessary instantiation in the original example and in your example seems tricky in general unfortunately. GCC already shortcuts consideration of template candidates when it sees a perfect non-template candidate, but in these examples we want to shortcut consideration of other non-template candidates when we see a perfect non-template candidate. IIUC such shortcutting would be unsound because if there were multiple perfect non-template candidates then we would overlook that and fail to diagnose ambiguity. (Note that the compiler needs to instantiate restrictive<0> when considering the 'unrelated' candidate because restrictive<0> might be derived from 'unrelated' (e.g. through a partial specialization), which would make the candidate viable after all.) So one workaround that might work for your use case is to turn the problematic 'unrelated' overload into a template, e.g. template<class...> void fun(unrelated) {}