Bug 84857 - A valid call to a template function in a variadic template struct is rejected
Summary: A valid call to a template function in a variadic template struct is rejected
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code, rejects-valid
Depends on:
Blocks:
 
Reported: 2018-03-13 23:06 UTC by Vladimir Reshetnikov
Modified: 2021-11-08 09:42 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-07-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Reshetnikov 2018-03-13 23:06:44 UTC
The following C++ code is rejected by GCC 8.0.1 20180313 (tested with https://godbolt.org/):

/************* SOURCE *************/
template<typename... T>
struct S {
    template<T... xs>
    static int f() {
        return 0;
    }
};

int t = S<int, int>::f<0, 0>();
/*********** END SOURCE ***********/


/************* OUTPUT *************/
<source>:9:30: error: no matching function for call to 'S<int, int>::f<0, 0>()'
 int t = S<int, int>::f<0, 0>();
                              ^
<source>:4:16: note: candidate: 'template<T ...xs> static int S<T>::f() [with T ...xs = {xs ...}; T = {int, int}]'
     static int f() {
                ^
<source>:4:16: note:   template argument deduction/substitution failed:
<source>:9:30: error: wrong number of template arguments (2, should be 1)
 int t = S<int, int>::f<0, 0>();
                              ^
Compiler returned: 1
/*********** END OUTPUT ***********/

I believe this code is correct and should be accepted.
Comment 1 Marek Polacek 2018-03-14 06:32:35 UTC
Doesn't seem to be ever accepted, not a regression.
Comment 2 Andrew Pinski 2021-07-27 07:19:06 UTC
Note if you do (instead of the last line):
int t = S<int, int>::f<0>();

On the trunk we produce an ICE:
<source>:9:26: internal compiler error: tree check: accessed elt 1 of 'tree_vec' with 0 elts in tsubst_pack_expansion, at cp/pt.c:13047
    9 | int t = S<int, int>::f<0>();
      |         ~~~~~~~~~~~~~~~~~^~
Comment 3 Andrew Pinski 2021-11-08 09:42:50 UTC
(In reply to Andrew Pinski from comment #2)
> Note if you do (instead of the last line):

That would make it related to PR 84796.