[diff.cpp17.lex] (original) (raw)

Annex C (informative) Compatibility [diff]

C.3 C++ and ISO C++ 2017 [diff.cpp17]

C.3.2 [lex]: lexical conventions [diff.cpp17.lex]

Affected subclauses: [lex.pptoken], [module.unit], [module.import], [cpp.pre], [cpp.module], and [cpp.import]

Change: New identifiers with special meaning.

Rationale: Required for new features.

Effect on original feature: Logical lines beginning withmodule or import may be interpreted differently in this revision of C++.

[Example 1: class module {};module m1; module *m2; class import {};import j1; ::import j2; — _end example_]

Affected subclause: [lex.header]

Change: tokens are formed in more contexts.

Rationale: Required for new features.

Effect on original feature: When the identifier importis followed by a < character, a token may be formed.

[Example 2: template<typename> class import {};import<int> f(); ::import<int> g(); — _end example_]

Affected subclause: [lex.key]

Change: New keywords.

Rationale: Required for new features.

Effect on original feature: Valid C++ 2017 code usingchar8_t,concept,consteval,constinit,co_await, co_yield, co_return, or requiresas an identifier is not valid in this revision of C++.

Affected subclause: [lex.operators]

Change: New operator <=>.

Rationale: Necessary for new functionality.

Effect on original feature: Valid C++ 2017 code that contains a <= token immediately followed by a > token may be ill-formed or have different semantics in this revision of C++.

[Example 3: namespace N { struct X {};bool operator<=(X, X);template<bool(X, X)> struct Y {}; Y<operator<=> y; } — _end example_]

Affected subclause: [lex.literal]

Change: Type of UTF-8 string and character literals.

Rationale: Required for new features.

The changed types enable function overloading, template specialization, and type deduction to distinguish ordinary and UTF-8 string and character literals.

Effect on original feature: Valid C++ 2017 code that depends on UTF-8 string literals having type “array of const char” and UTF-8 character literals having type “char” is not valid in this revision of C++.

[Example 4: const auto *u8s = u8"text"; const char *ps = u8s; auto u8c = u8'c'; char *pc = &u8c; std::string s = u8"text"; void f(const char *s); f(u8"text"); template<typename> struct ct;template<> struct ct<char> { using type = char;}; ct<decltype(u8'c')>::type x; — _end example_]