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

            Bug ID: 116694
           Summary: -Ftemplate-depth = parameter does not match the actual
                    number of instantiations
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: polarlinda6 at 163 dot com
  Target Milestone: ---

Version: x86-64 gcc 14.2.1
command-line parameter: -ftemplate-depth=52 -std=c++20
Link: https://godbolt.org/z/rnn35nsac

PS: The code compiles successfully and clang.
( MSVC does not provide a parameter for the template instantiation depth and
cannot be tested )

```cpp
#include <utility>

template<auto s, auto... S>
struct A {
  constexpr static auto value = A<S...>::value;
};
template<auto s>
struct A<s> {
    constexpr static auto value = s;
}; 

template<auto... S>
auto func(std::index_sequence<S...>) {
  return A<S...>::value;
}

auto main() -> int { auto s = func(std::make_index_sequence<50>{}); }
```

#### error message:

<source>: In instantiation of 'struct A<25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49>':
<source>:5:42:   required from 'constexpr const auto A<24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49>::value'
    5 |   constexpr static auto value = A<S...>::value;
      |                                          ^~~~~
<source>:5:25:   required from 'struct A<24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49>'
    5 |   constexpr static auto value = A<S...>::value;
      |                         ^~~~~
<source>:5:42:   required from 'constexpr const auto A<23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49>::value'
    5 |   constexpr static auto value = A<S...>::value;
      |                                          ^~~~~
<source>:5:25:   required from 'struct A<23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49>'
    5 |   constexpr static auto value = A<S...>::value;
      |                         ^~~~~
<source>:5:42:   required from 'constexpr const auto A<22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49>::value'
    5 |   constexpr static auto value = A<S...>::value;
      |                                          ^~~~~
<source>:5:25:   [ skipping 41 instantiation contexts, use
-ftemplate-backtrace-limit=0 to disable ]
<source>:5:42:   required from 'constexpr const auto A<1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49>::value'
<source>:5:25:   required from 'struct A<1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49>'
    5 |   constexpr static auto value = A<S...>::value;
      |                         ^~~~~
<source>:5:42:   required from 'constexpr const auto A<0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49>::value'
    5 |   constexpr static auto value = A<S...>::value;
      |                                          ^~~~~
<source>:5:25:   required from 'struct A<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49>'
    5 |   constexpr static auto value = A<S...>::value;
      |                         ^~~~~
<source>:14:19:   required from 'auto func(std::index_sequence<S ...>) [with
auto ...S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49}]'
   14 |   return A<S...>::value;
      |                   ^~~~~
<source>:17:35:   required from here
   17 | auto main() -> int { auto s = func(std::make_index_sequence<50>{}); }
      |                               ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:5:25: fatal error: template instantiation depth exceeds maximum of 52
(use '-ftemplate-depth=' to increase the maximum)
    5 |   constexpr static auto value = A<S...>::value;
      |

Reply via email to