Bug 107111 - GCC accepts invalid program involving function declaration with pack expansion
Summary: GCC accepts invalid program involving function declaration with pack expansion
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
: 107113 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-10-01 17:05 UTC by Jason Liam
Modified: 2022-10-06 09:23 UTC (History)
3 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 Jason Liam 2022-10-01 17:05:30 UTC
The following program is incorrectly accepted by gcc. Demo: https://godbolt.org/z/rvfqzo5YW

```
template<typename T, typename... V> 
struct C 
{
    T v(V()...);;
};
int main()
{
    
    C<int> c; //works with gcc but rejected in clang 
    C<int, double, int, int> c2; //same here: works with gcc but rejected in clang
}
```
This is invalid because the construct `V()...` is actually equivalent to `V(),...`. So `V` is not expanded and this must be rejected.
Comment 1 Jason Liam 2022-10-01 17:11:22 UTC
The last statement in my original report is not valid because `V` is a template parameter pack. So ignore that line.
Comment 2 Jason Liam 2022-10-01 17:24:38 UTC
Also gcc rejects `V...()` but clang accepts that. Demo: https://godbolt.org/z/bfx9rv6hP
Comment 3 Egor 2022-10-02 04:34:34 UTC
The correct behavior should be to accept `V...()` and to reject `V()...`.
Comment 4 Egor 2022-10-02 04:35:20 UTC
*** Bug 107113 has been marked as a duplicate of this bug. ***
Comment 5 Jason Liam 2022-10-02 09:47:41 UTC
Note also that gcc accepts `T v(V...b())` but rejects `T v(V...())`. Note the use of parameter name in the former. Demo: https://godbolt.org/z/hMevdc8TE