This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16335] passing non-const pointer to const pointer reference causes copy


------- Additional Comments From bangerth at dealii dot org  2004-07-02 20:54 -------
gccs behavior seems correct to me: the constructor expects a 
reference to const int*, whereas you provide it with an int*. 
The latter is not a const-qualified version of the former, but 
they are convertible to the former type, so the compiler  
generates a temporary of type const int* and takes the reference 
to this temporary. (Note that here you are on thin ice anyway, 
since you store the address of a temporary, which invokes undefined 
behavior.) 
 
To fix your code, present the constructor with a const int*, like so 
  const int *p = &a; 
With this, you get the desired output. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]