Bug 78754 - incorrectly accepts non-deductible template parameter pack in function template
Summary: incorrectly accepts non-deductible template parameter pack in function template
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2016-12-09 14:57 UTC by Felix Morgner
Modified: 2022-10-28 16:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Felix Morgner 2016-12-09 14:57:31 UTC
g++ incorrectly accepts the following code that contains a non-deductible
template parameter pack:

  #include <utility>

  template<std::size_t ...Ns, typename ...Ts>
  void foo(std::index_sequence<Ns...>)
    {
    }

  int main()
    {
    foo(std::make_index_sequence<5>{});
    }

ISO14882:2014 states the following in [temp.param]:

(9) [...] A default template-argument may be specified for any kind of
template-parameter (type, non-type, template) that is not a template parameter
pack (14.5.3). [...]

(11) [...]  A template parameter pack of a function template shall not be
followed by another template parameter unless that template parameter can be
deduced from the parameter-type-list of the function template or has a default
argument (14.8.2).

It also gives an example similar to the above. As far as I can tell, it is
neither possible to deduce nor to specify the types for 'Ts' and thus this
template function should be rejected.

The example code was compiled with the following command line invocation:

  g++ -Wall -Wextra -pedantic -pedantic-errors -Werror -std=c++14 templ.cpp
Comment 1 Andrew Pinski 2021-08-10 04:11:36 UTC
clang, ICC and GCC all accept it.  ICC warns though:
<source>(4): warning #2922: template parameter "Ts" cannot be used because it follows a parameter pack and cannot be deduced from the parameters of function template "foo"
    template<std::size_t ...Ns, typename ...Ts>
                                            ^


And MSVC errors out:
<source>(5): error C3547: template parameter 'Ts' cannot be used because it follows a template parameter pack and cannot be deduced from the function parameters of 'foo'