Cv-qualifications of prvalues in C++14

后端 未结 1 1323
慢半拍i
慢半拍i 2021-01-02 02:07

It appears that C++11 and C++14 treat cv-qualifications of prvalues differently.

C++11 sticks to the \"classic\" approach that has been around since C++98: according

1条回答
  •  清酒与你
    2021-01-02 02:42

    According to the commit on github, this was done to resolve CWG1261: Explicit handling of cv-qualification with non-class prvalues

    Based on comments to the question it seems there was room for surprising variations in type category of this (formally a prvalue) and that gcc formerly and MSVC currently instead used a const lvalue.

    The wording tightens up the hole to be explicit that, e.g., even if this is by some compiler-internal magic a prvalue of type X* const, prior to any further analysis it is adjusted to X*.

    Similarly, your given example does look like a gcc bug. Possibly decltype isn't looking at the value type before applying the c-style cast.

    The reason it's now a note in [basic.lval]/4 is that it's now a consequence of the new text in [expr]/6, rather than specifying the rule in [basic.lval]/4.

    Full credit to T.C. for having basically answered this in the comments on the question, including the reference to the gcc bug-fix, and various other examples of previously under-specified behaviours for cv-qualified non-class non-array prvalues.

    0 讨论(0)
提交回复
热议问题