https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98524
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <[email protected]>: https://gcc.gnu.org/g:f213d6591640f76eb86cafdb4366d87b87747038 commit r17-1355-gf213d6591640f76eb86cafdb4366d87b87747038 Author: Marek Polacek <[email protected]> Date: Wed Jun 3 15:01:33 2026 -0400 c++: CWG 1704, type checking in explicit inst of var tmpl [PR125575] While working on something else I noticed that we compile template<typename T> constexpr int vt = 42; template float vt<int>; but we shouldn't due to the float/int mismatch. Andrew found 98524 which is the same problem. This turned out to be CWG 1704. For explicit specialization of functions, determine_specialization already performs the checking; see the various same_type_p, compparms, comp_template_parms etc. checks. Except I do believe it doesn't check exception specification as it should: template<typename T> void (fn)(T) {} template void (fn<int>)(int) noexcept; // ill-formed, we accept The fix should be rather easy. PR c++/125575 PR c++/98524 gcc/cp/ChangeLog: * pt.cc (check_explicit_inst_of_var_template): New. (check_explicit_specialization): Use it. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/var-templ90.C: New test. * g++.dg/cpp1y/var-templ91.C: New test. * g++.dg/cpp1y/var-templ92.C: New test. * g++.dg/cpp1y/var-templ93.C: New test. Reviewed-by: Jason Merrill <[email protected]>
