GCC 9.2, partial specialization with non-type template parameters: bug or not?

Bence Kodaj bence.kodaj@gmail.com
Sat Apr 18 19:51:31 GMT 2020

Dear list members,

I'd like to ask for your help with the following: in GCC 9.2., is partial
template specialization expected to work for *all* allowed non-type
template parameters of class type?

For a concrete example, please see the code below: it prints "false, true",
i.e., apparently, specializing T for X< Int > does not succeed, whereas it
does for Y< int >. Since Int is now (in C++20) allowed to be used as the
type of non-type template parameters, one would naively expect the
specialization of T for X< Int > to succeed just like the one for Y< int >
does. Is this belief justified, or am I missing something?

Disclaimer: I do realize that C++20 support in GCC 9 is experimental - I'm
just looking for clarity regarding this issue, i.e., does the C++20 (draft)
standard require that the code below print "true, true"?

Best regards,
Bence Kodaj
- Compiler version (from g++ -v): gcc version 9.2.1 20191102 (Ubuntu
- Compilation command: g++ -std=c++2a main.cpp

- Code:
#include <iostream>
#include <type_traits>

struct Int {
    constexpr Int(int v): value{ v } {}
    const int value;

template< Int i >
struct X {};

template< int i >
struct Y {};

template< typename >
struct T : std::false_type {};

template< Int i >
struct T< X< i > > : std::true_type {};

template< int i >
struct T< Y< i > > : std::true_type {};

int main()
    std::cout << std::boolalpha << T< X< 123 > >::value << ", " << T< Y<
123 > >::value << "\n";
    return 0;

More information about the Gcc-help mailing list