public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/2892] array addresses corrupted when using template classes
       [not found] <20010521155602.2892.goyette@sgi.com>
@ 2004-02-16  5:13 ` pinskia at gcc dot gnu dot org
  2004-04-28  1:57 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-16  5:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-16 05:12 -------
Note the tree-ssa the simple testcase this code:
pr2892.cc: In function `int main()':
pr2892.cc:46: error: conversion from `int*' to non-scalar type `int[2]' requested
pr2892.cc:50: error: conversion from `int*' to non-scalar type `int[2]' requested


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
   Last reconfirmed|2003-11-16 00:25:41         |2004-02-16 05:12:48
               date|                            |


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


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

* [Bug c++/2892] array addresses corrupted when using template classes
       [not found] <20010521155602.2892.goyette@sgi.com>
  2004-02-16  5:13 ` [Bug c++/2892] array addresses corrupted when using template classes pinskia at gcc dot gnu dot org
@ 2004-04-28  1:57 ` pinskia at gcc dot gnu dot org
  2004-04-28  7:44 ` bangerth at dealii dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-28  1:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-28 01:02 -------
On the mainline we get a warning:
pr2892.cc: In member function `void* X<T, F>::Foo(F) [with T = int[2], F = int[2]]':
pr2892.cc:46:   instantiated from here
pr2892.cc:8: warning: address of local variable `arg' returned

So I think this is invalid.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |
   Last reconfirmed|2004-02-16 05:12:48         |2004-04-28 01:02:53
               date|                            |


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


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

* [Bug c++/2892] array addresses corrupted when using template classes
       [not found] <20010521155602.2892.goyette@sgi.com>
  2004-02-16  5:13 ` [Bug c++/2892] array addresses corrupted when using template classes pinskia at gcc dot gnu dot org
  2004-04-28  1:57 ` pinskia at gcc dot gnu dot org
@ 2004-04-28  7:44 ` bangerth at dealii dot org
  2004-04-28  9:19 ` nathan at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2004-04-28  7:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-04-28 06:48 -------
That is actually a pretty good point -- the function that fails is the 
only one where the type of the argument is not deducted but explicitly 
specified as a template argument, namely int[2]. It would seem to be 
that it is indeed passed by value, which is what the compiler warns about. 
Running the program subsequently fails. 
 
In all the other cases, the deduced type for the argument should be a 
reference, and taking the address should and does yield the correct result. 
Likewise, if I change the argument of the failing function to take a  
reference F&, then the program succeeds. 
 
Nathan, what do you think? Was this just as oversight, or am I missing 
something? I believe that Andrew is actually right here. 
 
W. 

-- 


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


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

* [Bug c++/2892] array addresses corrupted when using template classes
       [not found] <20010521155602.2892.goyette@sgi.com>
                   ` (2 preceding siblings ...)
  2004-04-28  7:44 ` bangerth at dealii dot org
@ 2004-04-28  9:19 ` nathan at gcc dot gnu dot org
  2004-04-28 20:26 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: nathan at gcc dot gnu dot org @ 2004-04-28  9:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From nathan at gcc dot gnu dot org  2004-04-28 07:19 -------
I was unable to get 3.4 to give the warning that Andrew showed.  I agree with
Wolfgang, that it looks like the int[2] parameter of X::Foo is being
passed by value, rather than pointer -- which is what I said in attachment 6.



-- 


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


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

* [Bug c++/2892] array addresses corrupted when using template classes
       [not found] <20010521155602.2892.goyette@sgi.com>
                   ` (3 preceding siblings ...)
  2004-04-28  9:19 ` nathan at gcc dot gnu dot org
@ 2004-04-28 20:26 ` bangerth at dealii dot org
  2004-04-29  0:45 ` giovannibajo at libero dot it
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2004-04-28 20:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-04-28 18:57 -------
Alright: in Nathan's attachment to this PR, if I comment test 3 out, we 
fail in test 4, so these are equivalent. 
 
The question thus boils down to: in this snippet 
--------------- 
extern "C" void abort(); 
 
template <typename T>  
void *Foo (T arg) { return &arg[0]; } 
 
int main () { 
  int bry[2]; 
  if (Foo<int[2]>(bry) != bry) 
    abort(); 
} 
------------------ 
gcc aborts because it passes the arg to Foo by value, rather than by 
reference, and the returned value is to a temporary. gcc 3.5 even 
warns about this, as has been noted before. 
 
On the other hand, icc accepts the code. The question then is: is gcc 
wrong to pass by value? I believe this is sensible, but icc seems to 
disagree. Nathan, you seem to have a much better understanding of this: 
why do you believe we are wrong here? 
 
W. 
 

-- 


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


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

* [Bug c++/2892] array addresses corrupted when using template classes
       [not found] <20010521155602.2892.goyette@sgi.com>
                   ` (4 preceding siblings ...)
  2004-04-28 20:26 ` bangerth at dealii dot org
@ 2004-04-29  0:45 ` giovannibajo at libero dot it
  2005-02-25 19:47 ` [Bug c++/2892] No array-to-pointer decay happens for template functions pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2004-04-29  0:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-04-29 00:25 -------
(In reply to comment #12)

> The question then is: is gcc wrong to pass by value? 

Of course. After instantiation, the function signature is "void* Foo(int arg
[2])". There is nothing like "passing an array by value", and the automatic 
array-to-pointer decay should apply (so that the semantic of the call 
matches "void* Foo(int* arg)").

Notice that the instantion is still "T=int[2]", and thus different 
from "T=int*", but the call semantic would be same.

This is what Nathan says in comment #6: we don't do this decay for template 
functions, and this is our bug.

-- 


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


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

* [Bug c++/2892] No array-to-pointer decay happens for template functions
       [not found] <20010521155602.2892.goyette@sgi.com>
                   ` (5 preceding siblings ...)
  2004-04-29  0:45 ` giovannibajo at libero dot it
@ 2005-02-25 19:47 ` pinskia at gcc dot gnu dot org
  2005-03-09 18:53 ` mmitchel at gcc dot gnu dot org
  2005-03-16 13:17 ` reichelt at gcc dot gnu dot org
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-25 19:47 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |20208


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


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

* [Bug c++/2892] No array-to-pointer decay happens for template functions
       [not found] <20010521155602.2892.goyette@sgi.com>
                   ` (6 preceding siblings ...)
  2005-02-25 19:47 ` [Bug c++/2892] No array-to-pointer decay happens for template functions pinskia at gcc dot gnu dot org
@ 2005-03-09 18:53 ` mmitchel at gcc dot gnu dot org
  2005-03-16 13:17 ` reichelt at gcc dot gnu dot org
  8 siblings, 0 replies; 9+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-03-09 18:53 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 2892 depends on bug 20208, which changed state.

Bug 20208 Summary: [4.0/4.1 Regression] No array-to-pointer decay happens for template functions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20208

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
             Status|NEW                         |ASSIGNED
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

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


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

* [Bug c++/2892] No array-to-pointer decay happens for template functions
       [not found] <20010521155602.2892.goyette@sgi.com>
                   ` (7 preceding siblings ...)
  2005-03-09 18:53 ` mmitchel at gcc dot gnu dot org
@ 2005-03-16 13:17 ` reichelt at gcc dot gnu dot org
  8 siblings, 0 replies; 9+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-03-16 13:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2005-03-16 13:16 -------
Fixed in gcc 4.0.0 - probably by Mark's patch for PR 20208
which also includes a suitable testcase.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0


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


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

end of thread, other threads:[~2005-03-16 13:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20010521155602.2892.goyette@sgi.com>
2004-02-16  5:13 ` [Bug c++/2892] array addresses corrupted when using template classes pinskia at gcc dot gnu dot org
2004-04-28  1:57 ` pinskia at gcc dot gnu dot org
2004-04-28  7:44 ` bangerth at dealii dot org
2004-04-28  9:19 ` nathan at gcc dot gnu dot org
2004-04-28 20:26 ` bangerth at dealii dot org
2004-04-29  0:45 ` giovannibajo at libero dot it
2005-02-25 19:47 ` [Bug c++/2892] No array-to-pointer decay happens for template functions pinskia at gcc dot gnu dot org
2005-03-09 18:53 ` mmitchel at gcc dot gnu dot org
2005-03-16 13:17 ` reichelt at gcc dot gnu dot 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).