public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "samestimable2016 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/94619] String literals as non-type template parameter fails to compile with partial specialization of calling function
Date: Tue, 25 Aug 2020 14:34:22 +0000	[thread overview]
Message-ID: <bug-94619-4-EtTE5mcOYA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94619-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94619

Sam Huang <samestimable2016 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samestimable2016 at gmail dot com

--- Comment #2 from Sam Huang <samestimable2016 at gmail dot com> ---
I was going to file the same bug but with a different and much simpler
scenario. The compiler fails to deduce the parameter when you pass a non-type
template parameter to another template.

Consider the following scenario (tested on compiler explorer using GCC 9.1,
9.2, 9.3, 10.1, 10.2 with options -std=c++2a -O3):

>>>>>>>>>>>>>>>>>>>>>>>>>>>

#include <array>
#include <cstddef>

template<std::size_t N>
struct constexpr_string
{
    std::array<char, N> _data;

public:
    constexpr constexpr_string(const char (&data)[N])
    {
        std::copy(std::begin(data), std::end(data), _data.data());
    }
};

template<constexpr_string String>
struct foo
{};

template<constexpr_string String>
struct bar
{
    using type = foo<String>; // <-- Fails to compile on this line
};

int main()
{}

>>>>>>>>>>>>>>>>>>>>>>>>>>>

The diagnostic produced by the compiler is:
"
<source>:23:28: error: class template argument deduction failed:

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

<source>:23:28: error: no matching function for call to
'constexpr_string(constexpr_string<...auto...>)'

<source>:10:15: note: candidate: 'template<long unsigned int N>
constexpr_string(const char (&)[N])-> constexpr_string<N>'

   10 |     constexpr constexpr_string(const char (&data)[N])

      |               ^~~~~~~~~~~~~~~~

<source>:10:15: note:   template argument deduction/substitution failed:

<source>:23:28: note:   mismatched types 'const char [N]' and
'constexpr_string<...auto...>'

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

<source>:5:8: note: candidate: 'template<long unsigned int N>
constexpr_string(constexpr_string<N>)-> constexpr_string<N>'

    5 | struct constexpr_string

      |        ^~~~~~~~~~~~~~~~

<source>:5:8: note:   template argument deduction/substitution failed:

<source>:23:28: note:   mismatched types 'constexpr_string<N>' and
'constexpr_string<...auto...>'

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

ASM generation compiler returned: 1

<source>:23:28: error: class template argument deduction failed:

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

<source>:23:28: error: no matching function for call to
'constexpr_string(constexpr_string<...auto...>)'

<source>:10:15: note: candidate: 'template<long unsigned int N>
constexpr_string(const char (&)[N])-> constexpr_string<N>'

   10 |     constexpr constexpr_string(const char (&data)[N])

      |               ^~~~~~~~~~~~~~~~

<source>:10:15: note:   template argument deduction/substitution failed:

<source>:23:28: note:   mismatched types 'const char [N]' and
'constexpr_string<...auto...>'

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

<source>:5:8: note: candidate: 'template<long unsigned int N>
constexpr_string(constexpr_string<N>)-> constexpr_string<N>'

    5 | struct constexpr_string

      |        ^~~~~~~~~~~~~~~~

<source>:5:8: note:   template argument deduction/substitution failed:

<source>:23:28: note:   mismatched types 'constexpr_string<N>' and
'constexpr_string<...auto...>'

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

Execution build compiler returned: 1
"

  parent reply	other threads:[~2020-08-25 14:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16 14:20 [Bug c++/94619] New: " pacoarjonilla at yahoo dot es
2020-04-16 16:07 ` [Bug c++/94619] " daniel.kruegler at googlemail dot com
2020-08-25 14:34 ` samestimable2016 at gmail dot com [this message]
2021-08-05  4:46 ` pinskia at gcc dot gnu.org

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=bug-94619-4-EtTE5mcOYA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).