Bug 5786 - array types decay too quickly
Summary: array types decay too quickly
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.3
: P3 normal
Target Milestone: 4.5.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
: 11857 (view as bug list)
Depends on:
Blocks: 24666 2892 8041
  Show dependency treegraph
 
Reported: 2002-02-26 09:06 UTC by david.abrahams
Modified: 2009-11-17 06:06 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-11-17 06:05:20


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description david.abrahams 2002-02-26 09:06:01 UTC
Various kinds of array argument deduction from temporaries fails.

-Dave

Release:
3.0.3

Environment:
Cygwin

How-To-Repeat:
Compile the following:
template <class T, unsigned N>
void print1(T const (&x)[N])
{
}

template <class T, unsigned N, unsigned M>
void print2(T const (&x)[N][M])
{
}

struct X { int x[2][4]; };

int main()
{
   print1(X().x);
   print2(X().x);
   return 0;
}
Comment 1 Nathan Sidwell 2002-09-14 15:43:31 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed, I don't think this is parser related.
Comment 2 Andrew Pinski 2003-05-28 13:43:16 UTC
Still happens on the mainline (20030526):

pr5786.cc: In function `int main()':
pr5786.cc:16: error: could not convert `X().X::x' to `const int (&)[2][4]'
pr5786.cc:4: error: in passing argument 1 of `void print1(const T (&)[N]) [with 
   T = int[4], unsigned int N = 2]'
pr5786.cc:17: error: could not convert `X().X::x' to `const int (&)[2][4]'
pr5786.cc:9: error: in passing argument 1 of `void print2(const T (&)[N][M]) 
   [with T = int, unsigned int N = 2, unsigned int M = 4]'
Comment 3 Nathan Sidwell 2004-01-05 09:38:17 UTC
*** Bug 11857 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2004-06-02 04:12:23 UTC
Most likely the same bug as PR 2892.
Comment 5 Giovanni Bajo 2005-03-16 15:56:59 UTC
This could be fixed already...
Comment 6 Andrew Pinski 2005-03-16 16:02:43 UTC
(In reply to comment #5)
> This could be fixed already...

It is not:
t.cc: In function ‘int main()’:
t.cc:15: error: invalid initialization of non-const reference of type ‘const int (&)[2][4]’ from a temporary 
of type ‘int [2][4]’
t.cc:2: error: in passing argument 1 of ‘void print1(const T (&)[N]) [with T = int [4], unsigned int N = 
2u]’
t.cc:16: error: invalid initialization of non-const reference of type ‘const int (&)[2][4]’ from a temporary 
of type ‘int [2][4]’
t.cc:7: error: in passing argument 1 of ‘void print2(const T (&)[N][M]) [with T = int, unsigned int N = 2u, 
unsigned int M = 4u]’
Comment 7 Eelis 2008-04-13 21:19:40 UTC
Still fails on GCC 4.4.0 20080413 (experimental).
Comment 8 Jason Merrill 2009-11-17 06:05:42 UTC
This seems to be fixed for 4.5.
Comment 9 Jason Merrill 2009-11-17 06:06:17 UTC
.