Namespaces
Variants
Actions

Talk:cpp/language/auto

From cppreference.com

The example says auto m{5}; // OK: type of m is int as of C++17, initializer_list<int> before, but this appears to be deduced as int in all compilers I've tried in C++11 mode, presumably this was DR'd by something --Ybab321 (talk) 04:36, 16 March 2021 (PDT)

gcc 4.9.3 and clang 3.7.1 are the last versions that make it an initializer_list in C++11 mode, seems you're right --Cubbi (talk) 10:56, 16 March 2021 (PDT)

[edit] Question on explanation of decltype(auto)

It is said that

If the placeholder type specifier is decltype(auto) or type-constraint decltype(auto)(since C++20), the deduced type is decltype(expr), where expr is the initializer.

(since C++14)

and before C++20, lambda expressions are forbidden in unevaluated expressions such as in decltype(expr).

But I tested via godbolt on both gcc and clang in c++14 mode, and following code compiles successfully

decltype(auto) f() {
    return []{};
}
 
int main() {
    decltype(auto) x = []{};
}

Doesn't this example construct a decltype([]{}) implicitly? Or our explanation is inaccurate? --Yaossg (talk) 06:38, 8 May 2023 (PDT)

the C++17 wording was "as though e had been the operand of the decltype" so cppreference matches the standard, even if prim.lambda/2 said it shall not appear there. Seems compilers didn't think "as though" meant "literally" even before it became allowed. --Cubbi (talk) 07:58, 8 May 2023 (PDT)