Bug 100975 - [C++23] Allow pointer to array of auto
Summary: [C++23] Allow pointer to array of auto
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks: c++23-core
  Show dependency treegraph
 
Reported: 2021-06-08 17:44 UTC by Jason Merrill
Modified: 2021-06-30 16:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-06-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Merrill 2021-06-08 17:44:57 UTC
https://wg21.link/cwg2397
Comment 1 Jason Merrill 2021-06-08 18:43:59 UTC
  int a[3];
  auto (*p)[3] = &a;
Comment 2 Marek Polacek 2021-06-25 19:02:33 UTC
Looks like just disabling the check in create_array_type_for_decl lets us compile:

struct false_type { static constexpr bool value = false; };
struct true_type { static constexpr bool value = true; };
template<class T, class U>
struct is_same : false_type {}; 
template<class T>
struct is_same<T, T> : true_type {};

void
g ()
{
  int a[3];
  auto (*p)[3] = &a;
  auto (&r)[3] = a;
  static_assert (is_same<decltype (p), int(*)[3]>::value);
  static_assert (is_same<decltype (r), int(&)[3]>::value);
}
Comment 3 CVS Commits 2021-06-30 16:17:57 UTC
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:e66d0b7b87d105d24da8c4784a0b907fb6b2c095

commit r12-1933-ge66d0b7b87d105d24da8c4784a0b907fb6b2c095
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Jun 29 14:30:51 2021 -0400

    c++: DR2397 - auto specifier for * and & to arrays [PR100975]
    
    This patch implements DR2397, which removes the restriction in
    [dcl.array]p4 that the array element type may not be a placeholder
    type.  We don't need to worry about decltype(auto) here, so this
    allows code like
    
      int a[3];
      auto (*p)[3] = &a;
      auto (&r)[3] = a;
    
    However, note that
    
      auto (&&r)[2] = { 1, 2 };
      auto arr[2] = { 1, 2 };
    
    still doesn't work (although one day it might) and neither does
    
      int arr[5];
      auto x[5] = arr;
    
    given that auto deduction is performed in terms of function template
    argument deduction, so the array decays to *.
    
            PR c++/100975
            DR 2397
    
    gcc/cp/ChangeLog:
    
            * decl.c (create_array_type_for_decl): Allow array of auto.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/auto24.C: Remove dg-error.
            * g++.dg/cpp0x/auto3.C: Adjust dg-error.
            * g++.dg/cpp0x/auto42.C: Likewise.
            * g++.dg/cpp0x/initlist75.C: Likewise.
            * g++.dg/cpp0x/initlist80.C: Likewise.
            * g++.dg/diagnostic/auto1.C: Remove dg-error.
            * g++.dg/cpp23/auto-array.C: New test.
Comment 4 Marek Polacek 2021-06-30 16:19:03 UTC
Implemented in GCC 12.