https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104578
Bug ID: 104578
Summary: [12 Regression] accepts invalid partial template
specialization, non-type template argument depends on
a template parameter
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
While looking into PR 104567, I just happened upon some code which is rejected
by before GCC 12, MSVC, clang and ICC. I suspect it is invalid code as all
other compilers besides the trunk reject it for a similar reasons.
Take:
template <typename _TAny, int value = _TAny::param>
struct s{};
template <typename _TAny>
struct s<_TAny, _TAny::param>
{
typedef int type;
};
struct checked_type
{
static const int param = 0;
};
s<checked_type>::type t;
int main()
{
return t;
}
----- CUT ----
clang reports:
<source>:5:17: error: type of specialized non-type template argument depends on
a template parameter of the partial specialization
struct s<_TAny, _TAny::param>
^~~~~
<source>:14:18: error: no type named 'type' in 's<checked_type, 0>'
s<checked_type>::type t;
~~~~~~~~~~~~~~~~~^
MSVC reports:
<source>(8): error C2753: 's<_TAny,_TAny::param>': partial specialization
cannot match argument list for primary template
ICC reports:
<source>(5): error: the template argument list of the partial specialization
includes a nontype argument whose type depends on a template parameter
struct s<_TAny, _TAny::param>
^
GCC 11.2.0 reports:
<source>:5:8: error: template argument '_TAny::param' involves template
parameter(s)
5 | struct s<_TAny, _TAny::param>
| ^~~~~~~~~~~~~~~~~~~~~~
GCC 12 accepts this for all levels of the C++ standard.