Why can’t I create a link to 'decltype (auto)'

int main(){
    decltype(auto)&& a = 100;
}

Above code, bug in GCC and Clang.

int main(){
    decltype(int)&& a = 100;
}

This code is correct.

In N4296

In § 8.3.2 / 6

If typedef (7.1.3), a type parameter template (14.3.1), or decltype specifier (7.1.6.2) indicates the type TR is a reference to type T, an attempt to create the type "lvalue reference to cv TR" creates the type "lvalue reference to T ", while trying to create a type of" rvalue reference to cv TR "creates a type of TR.

decltype-specifier in 7.1.6.2

decltype specifier:
decltype (expression)
decltype (auto)

I think that § 8.3.2 / 6 is a problem with the wording.

Why the link to decltype (auto) is not allowed. Please tell me the wording of the relevant standard. Sorry for the bad english. Thank.

+4
1

. 7.1.6.4 [dcl.spec.auto]

decltype (auto), . , , 7.1.6.2, decltype.

, :

decltype(auto) a = 100;

:

decltype(auto)& a = 100;

:

decltype(auto)&& a = 100;

, , decltype(auto), , (, decltype /)


, decltype(auto):

int i;
int&& f();
auto x3a = i;                  // decltype(x3a) is int
decltype(auto) x3d = i;        // decltype(x3d) is int
auto x4a = (i);                // decltype(x4a) is int
decltype(auto) x4d = (i);      // decltype(x4d) is int&
auto x5a = f();                // decltype(x5a) is int
decltype(auto) x5d = f();      // decltype(x5d) is int&&
auto x6a = { 1, 2 };           // decltype(x6a) is std::initializer_list<int>
decltype(auto) x6d = { 1, 2 }; // error, { 1, 2 } is not an expression
auto *x7a = &i;                // decltype(x7a) is int*
decltype(auto)*x7d = &i;       // error, declared type is not plain decltype(auto)
+3

Source: https://habr.com/ru/post/1569888/


All Articles