Namespaces
Variants
Actions

Talk:cpp/language/identifiers

From cppreference.com

"All identifiers with a double underscore anywhere are reserved" Where in the standard does it say this? I could only find language relating to identifiers beginning with a double underscore. Legalize (talk) 23:34, 4 July 2014 (PDT)

Ah, there is no such language in the C11 standard, but it is in the C++11 standard (17.6.4.3.2 [global.names]) and I was looking at the wrong one :-). Legalize (talk) 23:42, 4 July 2014 (PDT)

[edit] Compile Error

void f() {

 float x, &r = x;
 [=] {
 decltype(x) y1; // y1 has type float
 decltype((x)) y2 = y1; // y2 has type float const& because this lambda
 // is not mutable and x is an lvalue
 decltype(r) r1 = y1; // r1 has type float&
 decltype((r)) r2 = y2; // r2 has type float const&
 };

}

/mnt/d/source/cpp-learn/identifier_type.cpp:10:24: error: binding reference of type ‘float&’ to ‘const float’ discards qualifiers

 10 │ decltype((r)) r2 = y2; // r2 has type float const&
 │ ^~


Making the code above testable "locally":
Run this code
#include <iostream>
#include <boost/type_index.hpp>
 
int main() {
 
 float x, &r = x;
 [=] {
#if defined(__clang__)
 std::cout << "clang:\n";
#else
 std::cout << "gcc:\n";
#endif
 
# if false || defined(__clang__)
 decltype(x) y1; // y1 has type float
 decltype((x)) y2 = y1; // y2 has type float const& because this lambda
 // is not mutable and x is an lvalue
 decltype(r) r1 = y1; // r1 has type float&
 decltype((r)) r2 = y2; // r2 has type float const& (clang) or float& (gcc)
 
 [](auto...){}(y1, y2, r1, r2); // silences "unused" warnings
#endif
 
 using boost::typeindex::type_id_with_cvr;
 std::cout << "decltype(x) y1: " << type_id_with_cvr<decltype(x)>() << '\n'
 << "decltype((x)) y2: " << type_id_with_cvr<decltype((x))>() << '\n'
 << "decltype(r) r1: " << type_id_with_cvr<decltype(r)>() << '\n'
 << "decltype((r)) r2: " << type_id_with_cvr<decltype((r))>() << '\n';
 }();
}

Possible output:

clang compiles this w/o issuing an error; the output is:
 
clang:
decltype(x) y1: float
decltype((x)) y2: float const&
decltype(r) r1: float&
decltype((r)) r2: float const&
 
gcc:
decltype(x) y1: float
decltype((x)) y2: float const&
decltype(r) r1: float&
decltype((r)) r2: float&
 
gcc produces the error (if set #if true ...):
main.cpp: In lambda function:
main.cpp:12:23: error: binding reference of type 'float&' to 'const float' discards qualifiers
 12 │ decltype((r)) r2 = y2; // r2 has type float const&
 │ ^~
MSVC and Intel agree with GCC: error C2440: 'initializing': cannot convert from 'const float' to 'float &' and error: qualifiers dropped in binding reference of type "float &" to initializer of type "const float" - looks like clang is outvoted.. or rather, is the only one that implemented it. The standard has this example in expr.prim.id --Cubbi (talk) 10:46, 8 May 2021 (PDT)

[edit] XID_Start and XID_Continue already part of the C++ standard?

I rember vaguely that in the eldern days there was a long list of "allowed Unicode characters" in the Annex. And for C++20 or 23 there came up a proposal to get rid of that arbitrary list and bound the C++ standard to the Unicode standard and using the well-defined Unicode character properties XID_Start and XID_Continue. But AFAIK this proposal is not yet accepted, is it? --Roker (talk) 08:38, 1 November 2021 (PDT)

the proposal was p1949 and it was accepted in June 2021 as a DR, meaning it retroactively applies to previous C++ standard revisions. Here's the pull request that removed the table: https://github.com/cplusplus/draft/pull/4663/files Good riddance. --Cubbi (talk) 09:08, 1 November 2021 (PDT)
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=Talk:cpp/language/identifiers&oldid=135006"

AltStyle によって変換されたページ (->オリジナル) /