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>
5 files changed