The following code does not compile in all of gcc 10.1, msvc 19.24, and clang 10.0.0: template <int N> struct A { void g() requires (N == 3) {} void f() requires (N == 3) { g(); } }; template struct A<2>;
The error is "use of function 'void A<N>::g() requires N == 3 [with int N = 2]' with unsatisfied constraints"
Confirmed. [temp.explicit]/11 says: An explicit instantiation that names a class template specialization is also an explicit instantiation of the same kind (declaration or definition) of each of its members (not including members inherited from base classes and members that are templates) that has not been previously explicitly specialized in the translation unit containing the explicit instantiation, ***provided that the associated constraints, if any, of that member are satisfied by the template arguments of the explicit instantiation*** ...
Another testcase: template <int N> struct A { void f() requires (N == 3) { static_assert(N == 3); } }; template struct A<2>;
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:dc3d1e181445fafbbd146eb355a750c41c338794 commit r11-2417-gdc3d1e181445fafbbd146eb355a750c41c338794 Author: Patrick Palka <ppalka@redhat.com> Date: Wed Jul 29 22:06:33 2020 -0400 c++: constraints and explicit instantiation [PR96164] When considering to instantiate a member of a class template as part of an explicit instantiation of the class template, we need to first check the member's constraints before proceeding with the instantiation of the member. gcc/cp/ChangeLog: PR c++/96164 * constraint.cc (constraints_satisfied_p): Return true if !flags_concepts. * pt.c (do_type_instantiation): Update a paragraph taken from [temp.explicit] to reflect the latest specification. Don't instantiate a member with unsatisfied constraints. gcc/testsuite/ChangeLog: PR c++/96164 * g++.dg/cpp2a/concepts-explicit-inst5.C: New test.
The releases/gcc-10 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:215927a736d21d8cff8baeb50f687911a00149b9 commit r10-8602-g215927a736d21d8cff8baeb50f687911a00149b9 Author: Patrick Palka <ppalka@redhat.com> Date: Wed Jul 29 22:06:33 2020 -0400 c++: constraints and explicit instantiation [PR96164] When considering to instantiate a member of a class template as part of an explicit instantiation of the class template, we need to first check the member's constraints before proceeding with the instantiation of the member. gcc/cp/ChangeLog: PR c++/96164 * constraint.cc (constraints_satisfied_p): Return true if !flags_concepts. * pt.c (do_type_instantiation): Update a paragraph taken from [temp.explicit] to reflect the latest specification. Don't instantiate a member with unsatisfied constraints. gcc/testsuite/ChangeLog: PR c++/96164 * g++.dg/cpp2a/concepts-explicit-inst5.C: New test. (cherry picked from commit dc3d1e181445fafbbd146eb355a750c41c338794)
This should be fixed for GCC 10.3+, thanks for the report.
*** Bug 77595 has been marked as a duplicate of this bug. ***
*** Bug 68608 has been marked as a duplicate of this bug. ***