reference collapsing and cv-qualifiers

Skip to first unread message

Russell Yanofsky

Sep 24, 2005, 4:46:55 PM9/24/05
The proposed "reference collapsing" solution to CWG Defect 106 [1]
treats cv-qualifiers on reference types differently than other parts of
the language. Consider the following function declaration:

typedef int &int_ref;
void foo(int_ref const); // equivalent to void foo(int &);

The current C++ standard in 8.3.2p1 requires that the const qualifier
on the int_ref type be ignored. Now consider a similar declaration
which would be allowed under DR106:

typedef int &int_ref;
void foo(int_ref const &); // equivalent to void foo(int const &);

In this case, DR106 requires that the const qualifier be applied. So,
in one case, the const qualifier is applied, in the other it isn't,
even though the two declarations are identical except for a redundant &

I don't see why it needs to be this way. It'd be better if DR-106 were
either scaled back so cv-qualifiers on references were consistently
ignored throughout the language, or broadened so they could be
consistently applied.

Also, this inconsistency can make implementing DR-106 a PITA for
compiler writers, because you can longer interpret type expressions
"int_ref const &" straight from left to right. You used to be able know
what the "const" on "int_ref const" was supposed to do as soon as you
encountered it, whereas now you have to peek ahead for "&" operators to
know whether or not to apply it. At least that was my experience trying
to implement DR106 for GCC. I wonder if the author/authors of this
proposal were aware of 8.3.2p1 and how it conflicts (conceptually) with
the behavior they specify for reference collapsing.

- Russ


[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: ]

Russell Yanofsky

Sep 24, 2005, 4:46:55 PM9/24/05
Reply all
Reply to author
0 new messages