public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bence Kodaj <bence.kodaj@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: GCC 9.2, partial specialization with non-type template parameters: bug or not?
Date: Sat, 18 Apr 2020 21:51:31 +0200	[thread overview]
Message-ID: <CAN3SYmtNS0=Ov5UrpzzL3qRY1YQefo7EmGpACQ6KF11vMF=MSA@mail.gmail.com> (raw)

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;
}

             reply	other threads:[~2020-04-18 19:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-18 19:51 Bence Kodaj [this message]
2020-04-20 10:03 ` Bence Kodaj
2020-04-20 13:04   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN3SYmtNS0=Ov5UrpzzL3qRY1YQefo7EmGpACQ6KF11vMF=MSA@mail.gmail.com' \
    --to=bence.kodaj@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).