From Jason Turner

[diff.lex]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpbv0m3r8n/{from.md → to.md} +21 -20
tmp/tmpbv0m3r8n/{from.md → to.md} RENAMED
@@ -1,19 +1,19 @@
1
- ### Clause  [[lex]]: lexical conventions <a id="diff.lex">[[diff.lex]]</a>
2
 
3
- [[lex.key]] **Change:** New Keywords
4
  New keywords are added to C++; see [[lex.key]]. **Rationale:** These
5
  keywords were added in order to implement the new semantics of C++.
6
  **Effect on original feature:** Change to semantics of well-defined
7
  feature. Any ISO C programs that used any of these keywords as
8
  identifiers are not valid C++ programs. Syntactic transformation.
9
  Converting one specific program is easy. Converting a large collection
10
  of related programs takes more work. Common.
11
 
12
- [[lex.ccon]] **Change:** Type of character literal is changed from `int`
13
- to `char`. **Rationale:** This is needed for improved overloaded
14
- function argument type matching. For example:
15
 
16
  ``` cpp
17
  int function( int i );
18
  int function( char c );
19
 
@@ -29,30 +29,31 @@ sizeof('x') == sizeof(int)
29
  ```
30
 
31
  will not work the same as C++ programs. Simple. Programs which depend
32
  upon `sizeof('x')` are probably rare.
33
 
34
- Subclause [[lex.string]]: **Change:** String literals made const.
35
- The type of a string literal is changed from “array of `char`” to “array
36
- of `const char`”. The type of a `char16_t` string literal is changed
37
- from “array of *some-integer-type*” to “array of `const char16_t`”. The
38
- type of a `char32_t` string literal is changed from “array of
39
- *some-integer-type*” to “array of `const char32_t`”. The type of a wide
40
- string literal is changed from “array of `wchar_t`” to “array of
41
- `const wchar_t`”. **Rationale:** This avoids calling an inappropriate
42
- overloaded function, which might expect to be able to modify its
43
- argument. **Effect on original feature:** Change to semantics of
44
- well-defined feature. Syntactic transformation. The fix is to add a
45
- cast:
 
46
 
47
  ``` cpp
48
- char* p = "abc"; // valid in C, invalid in C++
49
  void f(char*) {
50
  char* p = (char*)"abc"; // OK: cast added
51
  f(p);
52
  f((char*)"def"); // OK: cast added
53
  }
54
  ```
55
 
56
- Programs that have a legitimate reason to treat string literals as
57
- pointers to potentially modifiable memory are probably rare.
58
 
 
1
+ ### [[lex]]: lexical conventions <a id="diff.lex">[[diff.lex]]</a>
2
 
3
+ **Change:** New Keywords
4
  New keywords are added to C++; see [[lex.key]]. **Rationale:** These
5
  keywords were added in order to implement the new semantics of C++.
6
  **Effect on original feature:** Change to semantics of well-defined
7
  feature. Any ISO C programs that used any of these keywords as
8
  identifiers are not valid C++ programs. Syntactic transformation.
9
  Converting one specific program is easy. Converting a large collection
10
  of related programs takes more work. Common.
11
 
12
+ **Change:** Type of *character-literal* is changed from `int` to `char`.
13
+ **Rationale:** This is needed for improved overloaded function argument
14
+ type matching. For example:
15
 
16
  ``` cpp
17
  int function( int i );
18
  int function( char c );
19
 
 
29
  ```
30
 
31
  will not work the same as C++ programs. Simple. Programs which depend
32
  upon `sizeof('x')` are probably rare.
33
 
34
+ **Change:** String literals made const.
35
+ The type of a *string-literal* is changed from “array of `char`” to
36
+ “array of `const char`”. The type of a UTF-8 string literal is changed
37
+ from “array of `char`” to “array of `const char8_t`”. The type of a
38
+ UTF-16 string literal is changed from “array of *some-integer-type*” to
39
+ “array of `const char16_t`”. The type of a UTF-32 string literal is
40
+ changed from “array of *some-integer-type*” to “array of
41
+ `const char32_t`”. The type of a wide string literal is changed from
42
+ “array of `wchar_t`” to “array of `const wchar_t`”. **Rationale:** This
43
+ avoids calling an inappropriate overloaded function, which might expect
44
+ to be able to modify its argument. **Effect on original feature:**
45
+ Change to semantics of well-defined feature. Syntactic transformation.
46
+ The fix is to add a cast:
47
 
48
  ``` cpp
49
+ char* p = "abc"; // valid in C, invalid in C++{}
50
  void f(char*) {
51
  char* p = (char*)"abc"; // OK: cast added
52
  f(p);
53
  f((char*)"def"); // OK: cast added
54
  }
55
  ```
56
 
57
+ Programs that have a legitimate reason to treat string literal objects
58
+ as potentially modifiable memory are probably rare.
59