public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC 9.2, partial specialization with non-type template parameters: bug or not?
@ 2020-04-18 19:51 Bence Kodaj
  2020-04-20 10:03 ` Bence Kodaj
  0 siblings, 1 reply; 3+ messages in thread
From: Bence Kodaj @ 2020-04-18 19:51 UTC (permalink / raw)
  To: gcc-help

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
9.2.1-17ubuntu1~18.04.1)
- 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;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-20 13:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18 19:51 GCC 9.2, partial specialization with non-type template parameters: bug or not? Bence Kodaj
2020-04-20 10:03 ` Bence Kodaj
2020-04-20 13:04   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).