Bug 92101 - Class template partial specializations with class NTTP does not work
Summary: Class template partial specializations with class NTTP does not work
Status: RESOLVED DUPLICATE of bug 93083
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-15 07:45 UTC by Mateusz Pusz
Modified: 2023-11-10 16:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-01-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mateusz Pusz 2019-10-15 07:45:32 UTC
Assuming the following basic_fixed_string implementation

```
#include <cstdlib>

template<typename CharT, std::size_t N>
struct basic_fixed_string {
    CharT data_[N+1] = {};

    constexpr basic_fixed_string(const CharT (&txt)[N+1]) noexcept
    {
        for(std::size_t i = 0; i <= N; ++i)
            data_[i] = txt[i];
    }
    // auto operator==(const basic_fixed_string &) = default;
};

template<typename CharT, std::size_t N>
basic_fixed_string(const CharT (&str)[N]) -> basic_fixed_string<CharT, N-1>;
```

the following works:

```
template<basic_fixed_string Name, typename...>
struct A {
    static constexpr auto name = Name;    
};

struct B : A<"abc", int> {};
```

but the following does not work

```
template<basic_fixed_string Name, typename...>
struct A;

template<basic_fixed_string Name, typename T1>
struct A<Name, T1> {
    static constexpr auto name = Name;
};

struct B : A<"abc", int> {};
```

Fails with the following error:

```
source>:26:18: error: class template argument deduction failed:

   26 | struct A<Name, T1> {

      |                  ^

<source>:26:18: error: no matching function for call to 'basic_fixed_string(basic_fixed_string<...auto...>)'

<source>:16:1: note: candidate: 'template<class CharT, long unsigned int N> basic_fixed_string(const CharT (&)[N])-> basic_fixed_string<CharT, (N - 1)>'

   16 | basic_fixed_string(const CharT (&str)[N]) -> basic_fixed_string<CharT, N-1>;

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

<source>:16:1: note:   template argument deduction/substitution failed:

<source>:26:18: note:   mismatched types 'const CharT [N]' and 'basic_fixed_string<...auto...>'

   26 | struct A<Name, T1> {

      |                  ^

<source>:7:15: note: candidate: 'template<class CharT, long unsigned int N> basic_fixed_string(const CharT (&)[(N + 1)])-> basic_fixed_string<CharT, N>'

    7 |     constexpr basic_fixed_string(const CharT (&txt)[N+1]) noexcept

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

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

<source>:26:18: note:   mismatched types 'const CharT [(N + 1)]' and 'basic_fixed_string<...auto...>'

   26 | struct A<Name, T1> {

      |                  ^

<source>:4:8: note: candidate: 'template<class CharT, long unsigned int N> basic_fixed_string(basic_fixed_string<CharT, N>)-> basic_fixed_string<CharT, N>'

    4 | struct basic_fixed_string {

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

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

<source>:26:18: note:   mismatched types 'basic_fixed_string<CharT, N>' and 'basic_fixed_string<...auto...>'

   26 | struct A<Name, T1> {

      |                  ^

<source>:30:12: error: invalid use of incomplete type 'struct A<basic_fixed_string<char, 3>{"abc"}, int>'

   30 | struct B : A<"abc", int> {};

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

<source>:23:8: note: declaration of 'struct A<basic_fixed_string<char, 3>{"abc"}, int>'

   23 | struct A;

      |        ^

Compiler returned: 1
```

Godbolt link: https://godbolt.org/z/MCdhTJ
Comment 1 Martin Liška 2020-01-29 13:41:06 UTC
Is the code accepted with clang?
Comment 2 Mateusz Pusz 2020-05-08 18:48:23 UTC
No, it fails on clang with:

```
<source>:22:10: error: use of class template 'basic_fixed_string' requires template arguments; argument deduction not allowed in template parameter
template<basic_fixed_string Name, typename...>
         ^~~~~~~~~~~~~~~~~~
```

As I understand, argument deduction for template parameters is allowed and supported already by gcc.
Comment 3 Patrick Palka 2023-11-10 16:21:20 UTC
This appears to be a dup of PR93083 which has since been fixed for GCC >= 10.3.

*** This bug has been marked as a duplicate of bug 93083 ***