public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26011]  New: References to const pointers to const objects don't work as expected.
@ 2006-01-29  0:38 ciprian dot craciun at gmail dot com
  2006-01-29  0:41 ` [Bug c++/26011] " ciprian dot craciun at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ciprian dot craciun at gmail dot com @ 2006-01-29  0:38 UTC (permalink / raw)
  To: gcc-bugs

I think the best way to describe the problem is giving a simple piece of code:

int t1;
int t2;

int * a = &t1;
int const * const & b = a;

a = &t2;

printf ("test 2: %x %x\n", a, b);
if (a != b)
        printf ("UPS!!!\n");

    My gcc -v outputs:

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.3 20051201 (prerelease) (Debian 4.0.2-5)


-- 
           Summary: References to const pointers to const objects don't work
                    as expected.
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ciprian dot craciun at gmail dot com
 GCC build triplet: 4.0.3
GCC target triplet: i486-linux-gnu


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


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

* [Bug c++/26011] References to const pointers to const objects don't work as expected.
  2006-01-29  0:38 [Bug c++/26011] New: References to const pointers to const objects don't work as expected ciprian dot craciun at gmail dot com
@ 2006-01-29  0:41 ` ciprian dot craciun at gmail dot com
  2006-01-29  0:42 ` ciprian dot craciun at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ciprian dot craciun at gmail dot com @ 2006-01-29  0:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ciprian dot craciun at gmail dot com  2006-01-29 00:41 -------
Created an attachment (id=10752)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10752&action=view)
The preprocessed file that exemplifies the bug.


-- 


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


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

* [Bug c++/26011] References to const pointers to const objects don't work as expected.
  2006-01-29  0:38 [Bug c++/26011] New: References to const pointers to const objects don't work as expected ciprian dot craciun at gmail dot com
  2006-01-29  0:41 ` [Bug c++/26011] " ciprian dot craciun at gmail dot com
@ 2006-01-29  0:42 ` ciprian dot craciun at gmail dot com
  2006-01-29  1:38 ` pinskia at gcc dot gnu dot org
  2006-01-29  9:31 ` ciprian dot craciun at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: ciprian dot craciun at gmail dot com @ 2006-01-29  0:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ciprian dot craciun at gmail dot com  2006-01-29 00:42 -------
Created an attachment (id=10753)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10753&action=view)
The original source code file that exemplifies the bug.


-- 


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


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

* [Bug c++/26011] References to const pointers to const objects don't work as expected.
  2006-01-29  0:38 [Bug c++/26011] New: References to const pointers to const objects don't work as expected ciprian dot craciun at gmail dot com
  2006-01-29  0:41 ` [Bug c++/26011] " ciprian dot craciun at gmail dot com
  2006-01-29  0:42 ` ciprian dot craciun at gmail dot com
@ 2006-01-29  1:38 ` pinskia at gcc dot gnu dot org
  2006-01-29  9:31 ` ciprian dot craciun at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-29  1:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-01-29 01:38 -------
int t1;
int t2;

int * a = &t1;
int const * const & b = a;
----
This does something different than you think.
It creates a temparory variable for the type, "const int *" as you need to
first convert a to that and then to "const int * const" as "const int * const"
is not compatiable with "int *".


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/26011] References to const pointers to const objects don't work as expected.
  2006-01-29  0:38 [Bug c++/26011] New: References to const pointers to const objects don't work as expected ciprian dot craciun at gmail dot com
                   ` (2 preceding siblings ...)
  2006-01-29  1:38 ` pinskia at gcc dot gnu dot org
@ 2006-01-29  9:31 ` ciprian dot craciun at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: ciprian dot craciun at gmail dot com @ 2006-01-29  9:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ciprian dot craciun at gmail dot com  2006-01-29 09:31 -------
(In reply to comment #3)
> int t1;
> int t2;
> 
> int * a = &t1;
> int const * const & b = a;
> ----
> This does something different than you think.
> It creates a temparory variable for the type, "const int *" as you need to
> first convert a to that and then to "const int * const" as "const int * const"
> is not compatiable with "int *".
> 

    Please scuse me to bother you, but your explanation doesn't seem right.
    If I try:

int * a = 0;
int const * const b = a;

    it compiles and even using the -Wall option the compiler does'nt complain.

    Also if I try:

int t1;
int * a = &t1;
int const * & b = a;

    it gives a compile time error... But I think the code is corect.
    You said that int * is not compatible with int const * const (I know they
are compatible), but here I use int * as a int const *, which to my knowledge
are compatible (and used without & it compiles without errors).

    These situations are exemplified in the file (bug-01.cpp) I have atached...

    All I want to do is declare an alias to a variable, and weaken the access
to this alias. This is a valid operation. This is done in a class:

class astring { // ascii string
public :
    astring (void) : length (actual_length), chars (actual_chars) {}

    size_t const * length; // an alias to actual_length
    char const * const & chars; // an alias to actual_chars
private :
    size_t actual_length;
    char * actual_chars;
};

    length works fine when I update actual_length. Only chars don't get updated
when I update actual_chars.


-- 

ciprian dot craciun at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ciprian dot craciun at gmail
                   |                            |dot com


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


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

end of thread, other threads:[~2006-01-29  9:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-29  0:38 [Bug c++/26011] New: References to const pointers to const objects don't work as expected ciprian dot craciun at gmail dot com
2006-01-29  0:41 ` [Bug c++/26011] " ciprian dot craciun at gmail dot com
2006-01-29  0:42 ` ciprian dot craciun at gmail dot com
2006-01-29  1:38 ` pinskia at gcc dot gnu dot org
2006-01-29  9:31 ` ciprian dot craciun at gmail dot com

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