https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59655
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I can confirm the #c0/#c1 case, I think #c4/#c5 are actually invalid testcases. For #c1, a slightly modified testcase where the foo call is before the static_assert rather than after it works (emits just one error for the static_assert failure). What is going on is that if the current instantiation is erroneous, we don't instantiate some of the templates, limit_bad_template_recursion is called and if the current template is neglectable_inst_p, we just return early from instantiate_decl. The question is, should we not call any of the no_linkage_error if any errors were diagnosed first (errorcount + sorrycount > 0), or just ignore in such cases templates that are neglectable_inst_p? Of course, the errorcount + sorrycount would need to be evaluated before the loop, so we can emit multiple no_linkage_error errors. Or shall we mark the templates we haven't instantiated due to this some way (some lang specific flag or something in cgraph node) and just skip those in no_linkage_error and check_global_declaration? Note, the latter already uses TREE_NO_WARNING as one way to shut it up.