Bug 115012 - noptr-abstract-pack-declarator parsing bug with T... [N]
Summary: noptr-abstract-pack-declarator parsing bug with T... [N]
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on: 113798
Blocks: c++26-core
  Show dependency treegraph
 
Reported: 2024-05-09 13:04 UTC by Jakub Jelinek
Modified: 2024-06-03 21:10 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-05-09 00:00:00


Attachments
gcc15-pr115012.patch (1.05 KB, patch)
2024-05-09 13:23 UTC, Jakub Jelinek
Details | Diff
gcc15-pr115012.patch (1.61 KB, patch)
2024-05-09 14:53 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2024-05-09 13:04:22 UTC
+++ This bug was initially created as a clone of Bug #113798 +++

As mentioned in the https://wg21.link/P2662R3 paper, we aren't parsing correctly T...[N] parameters.

template <int N, typename ...T>
void
foo (T... x[N])
{
}

template <int N, typename T>
void
bar (T [N])
{
}

template <int N, typename ...T>
void
baz (T... [N])
{
}

template <int N, typename ...T>
void
qux (T... [N][N])
{
}

void
corge (int a[10], double b[10], int c[5][5], float d[5][5])
{
  foo <10, int, double> (a, b);
  bar <10, int> (a);
  baz <10, int, double> (a, b);
  qux <5, int, float> (c, d);
}

is accepted by clang++ but not by GCC nor MSCV.
This is going to change in C++26 with pack indexing, but in C++11 .. C++23 it should be valid.
Comment 1 Jakub Jelinek 2024-05-09 13:23:34 UTC
Created attachment 58147 [details]
gcc15-pr115012.patch

Untested fix.
Comment 2 Jakub Jelinek 2024-05-09 14:53:10 UTC
Created attachment 58148 [details]
gcc15-pr115012.patch

Updated patch which also handles the T...(args) case.
Comment 3 GCC Commits 2024-06-03 21:10:26 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:48c3e5a4f935d6b8cd9ef7c51995e3b29ceb8be7

commit r15-1000-g48c3e5a4f935d6b8cd9ef7c51995e3b29ceb8be7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jun 3 23:07:08 2024 +0200

    c++: Fix parsing of abstract-declarator starting with ... followed by opening paren [PR115012]
    
    The C++26 P2662R3 Pack indexing paper mentions that both GCC
    and MSVC don't handle T...[10] parameter declaration when T
    is a pack.  And apparently neither T...(args).
    While the former will change meaning in C++26, T...(args) is still
    valid even in C++26.
    
    The following patch handles just the T...(args) case in
    cp_parser_direct_declarator.
    
    2024-06-03  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/115012
            * parser.cc (cp_parser_direct_declarator): Handle
            abstract declarator starting with ... followed by opening paren.
    
            * g++.dg/cpp0x/variadic185.C: New test.