[Bug c++/2892] array addresses corrupted when using template classes

bangerth at dealii dot org gcc-bugzilla@gcc.gnu.org
Wed Apr 28 20:26:00 GMT 2004


------- 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



More information about the Gcc-bugs mailing list