[Bug c++/125575] explicit instantiation of variable template misses type check
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jun 4 22:07:31 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125575
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:f213d6591640f76eb86cafdb4366d87b87747038
commit r17-1355-gf213d6591640f76eb86cafdb4366d87b87747038
Author: Marek Polacek <polacek@redhat.com>
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 <jason@redhat.com>
More information about the Gcc-bugs
mailing list