In C++, I can add cv-qualifiers to a reference:
int main()
{
int i = 5;
const volatile int & ri = i;
}
but not remove cv-qualifiers:
int main()
{
const volatile int i = 5;
int & ri = i;
}
Where in the standard is that defined (both, adding is allowed and removing is not allowed)?
I found a definition of "more cv-qualified" in C++23 N4928 §6.8.5 (5), [basic.type.qualifier] or on eel.is.
I then searched for usages of "more cv-qualified", but none of them seems to match references:
- §7.3.6 (4) [conv.qual] is only a note and is about pointers.
- §12.2.4.3 (3.2.6) [over.ics.rank] seems to be about overload resolution with implicit conversions
- §13.10.3.2 (4.1) [temp.deduct.call] is about templates
- §13.10.3.5 (6) and (9.2) [temp.deduct.partial] is about templates
In C++, I can add cv-qualifiers to a reference:
int main()
{
int i = 5;
const volatile int & ri = i;
}
but not remove cv-qualifiers:
int main()
{
const volatile int i = 5;
int & ri = i;
}
Where in the standard is that defined (both, adding is allowed and removing is not allowed)?
I found a definition of "more cv-qualified" in C++23 N4928 §6.8.5 (5), [basic.type.qualifier] or on eel.is.
I then searched for usages of "more cv-qualified", but none of them seems to match references:
- §7.3.6 (4) [conv.qual] is only a note and is about pointers.
- §12.2.4.3 (3.2.6) [over.ics.rank] seems to be about overload resolution with implicit conversions
- §13.10.3.2 (4.1) [temp.deduct.call] is about templates
- §13.10.3.5 (6) and (9.2) [temp.deduct.partial] is about templates
1 Answer
Reset to default 6The standard uses "reference-compatible with" instead of "more/less cv-qualified" for reference initialization.
This is described by [dcl.init.ref]/4
and [dcl.init.ref]/5
.
The definition of "reference-compatible" boils down to is the same conversion legal for pointers, which is in turn defined in [conv.qual]/3
.