C++98/03 reference collapsing and cv qualifiers

后端 未结 2 785
忘掉有多难
忘掉有多难 2021-01-18 06:50

The code below compiles (gcc 4.7.2 or icc 13) and produces \"1 2\" output. Which means that const qualifier is dropped, i. e., f ha

2条回答
  •  春和景丽
    2021-01-18 07:19

    Here is 1770 where the quote in question seems to originate:

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1770.html

    14.3.1 - Template type arguments

    -4- If a template-argument for a template-parameter T names a type "lvalue-reference to cv1 S," an attempt to create the type "(lvalue or rvalue) reference to cv2 T" creates the type "lvalue-reference to cv12 S," where cv12 is the union of the cv-qualifiers cv1 and cv2. If the template-argument names a type "rvalue-reference to cv1 S," an attempt to create the type "lvalue-reference to cv2 T" creates the type "lvalue-reference to cv12 S." If the template-argument names a type "rvalue-reference to cv1 S," an attempt to create the type "rvalue-reference to cv2 T" creates the type "rvalue-reference to cv12 S." Redundant cv-qualifiers are ignored.

    Here is 2118 where the quote has been struck out:

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html

    14.3.1 - Template type arguments

    -4- If a template-argument for a template-parameter T names a type "reference to cv1 S" that is a reference to a type A, an attempt to create the type "reference to cv2 T" "lvalue-reference to cv T" creates the type "reference to cv12 S", where cv12 is the union of the cv-qualifiers cv1 and cv2. Redundant cv-qualifiers are ignored "lvalue-reference to A", while an attempt to create the type "rvalue-reference to cv T" creates the type T.

    What you are quoting seems to be obsolete wording.

提交回复
热议问题