最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Where is it defined that references can be converted into more cv-qualified references? - Stack Overflow

programmeradmin3浏览0评论

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
Share Improve this question asked Feb 16 at 10:14 Thomas WellerThomas Weller 59.4k23 gold badges136 silver badges253 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 6

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

发布评论

评论列表(0)

  1. 暂无评论