public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/54299] New: Array parameter does not allow for iterator syntax
@ 2012-08-17 15:26 drepper.fsp at gmail dot com
  2012-08-17 15:40 ` [Bug middle-end/54299] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: drepper.fsp at gmail dot com @ 2012-08-17 15:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54299

             Bug #: 54299
           Summary: Array parameter does not allow for iterator syntax
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: drepper.fsp@gmail.com


Compile the following code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int aa[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

int f(int arr[10])
{
  int s = 0;
  for (auto i : arr)
    s += i;
  return s;
}

int main()
{
  return f(aa);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This fails with

u.cc: In function ‘int f(int*)’:
u.cc:18:17: error: ‘begin’ was not declared in this scope
u.cc:18:17: error: ‘end’ was not declared in this scope
u.cc:18:17: error: unable to deduce ‘auto’ from ‘<expression error>’



This indicates that the problem is that the parameter is seen as 'int *'
instead of as 'int [10]'.  According to Andrew another problem caused by the
too-early decay of arguments to pointers (bug 24666).

Changing the code as follows makes it compile:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int aa[1][10] = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } };

int f(int arr[1][10])
{
  int s = 0;
  for (auto i : arr[0])
    s += i;
  return s;
}

int main()
{
  return f(aa);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-06  3:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-17 15:26 [Bug middle-end/54299] New: Array parameter does not allow for iterator syntax drepper.fsp at gmail dot com
2012-08-17 15:40 ` [Bug middle-end/54299] " redi at gcc dot gnu.org
2012-08-17 15:43 ` redi at gcc dot gnu.org
2022-01-06  3:44 ` [Bug c++/54299] " pinskia at gcc dot gnu.org
2022-01-06  3:46 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).