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

Reply via email to