From Jason Turner

[diff.expr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpihdu7lpy/{from.md → to.md} +44 -20
tmp/tmpihdu7lpy/{from.md → to.md} RENAMED
@@ -1,23 +1,47 @@
1
- ### Clause [[expr]]: expressions <a id="diff.expr">[[diff.expr]]</a>
2
 
3
- [[expr.call]] **Change:** Implicit declaration of functions is not
4
- allowed. **Rationale:** The type-safe nature of C++. **Effect on
5
- original feature:** Deletion of semantically well-defined feature. Note:
6
- the original feature was labeled as “obsolescent” in ISO C. Syntactic
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  transformation. Facilities for producing explicit function declarations
8
  are fairly widespread commercially. Common.
9
 
10
- [[expr.post.incr]], [[expr.pre.incr]] **Change:** Decrement operator is
11
- not allowed with `bool` operand. **Rationale:** Feature with surprising
12
- semantics. **Effect on original feature:** A valid ISO C expression
13
- utilizing the decrement operator on a `bool` lvalue (for instance, via
14
- the C typedef in `<stdbool.h>`) is ill-formed in this International
15
- Standard.
16
 
17
- [[expr.sizeof]], [[expr.cast]] **Change:** Types must be defined in
18
- declarations, not in expressions.
19
  In C, a sizeof expression or cast expression may define a new type. For
20
  example,
21
 
22
  ``` cpp
23
  p = (void*)(struct x {int i;} *)0;
@@ -26,17 +50,17 @@ p = (void*)(struct x {int i;} *)0;
26
  defines a new type, struct `x`. **Rationale:** This prohibition helps to
27
  clarify the location of definitions in the source code. **Effect on
28
  original feature:** Deletion of semantically well-defined feature.
29
  Syntactic transformation. Seldom.
30
 
31
- [[expr.cond]], [[expr.ass]], [[expr.comma]] **Change:** The result of a
32
- conditional expression, an assignment expression, or a comma expression
33
- may be an lvalue. **Rationale:** C++is an object-oriented language,
34
- placing relatively more emphasis on lvalues. For example, functions may
35
- return lvalues. **Effect on original feature:** Change to semantics of
36
- well-defined feature. Some C expressions that implicitly rely on
37
- lvalue-to-rvalue conversions will yield different results. For example,
38
 
39
  ``` cpp
40
  char arr[100];
41
  sizeof(0, arr)
42
  ```
 
1
+ ### [[expr]]: expressions <a id="diff.expr">[[diff.expr]]</a>
2
 
3
+ **Change:** Converting `void*` to a pointer-to-object type requires
4
+ casting.
5
+
6
+ ``` cpp
7
+ char a[10];
8
+ void* b=a;
9
+ void foo() {
10
+ char* c=b;
11
+ }
12
+ ```
13
+
14
+ ISO C will accept this usage of pointer to void being assigned to a
15
+ pointer to object type. C++ will not. **Rationale:** C++ tries harder
16
+ than C to enforce compile-time type safety. **Effect on original
17
+ feature:** Deletion of semantically well-defined feature. Could be
18
+ automated. Violations will be diagnosed by the C++ translator. The fix
19
+ is to add a cast. For example:
20
+
21
+ ``` cpp
22
+ char* c = (char*) b;
23
+ ```
24
+
25
+ This is fairly widely used but it is good programming practice to add
26
+ the cast when assigning pointer-to-void to pointer-to-object. Some ISO C
27
+ translators will give a warning if the cast is not used.
28
+
29
+ **Change:** Implicit declaration of functions is not allowed.
30
+ **Rationale:** The type-safe nature of C++. **Effect on original
31
+ feature:** Deletion of semantically well-defined feature. Note: the
32
+ original feature was labeled as “obsolescent” in ISO C. Syntactic
33
  transformation. Facilities for producing explicit function declarations
34
  are fairly widespread commercially. Common.
35
 
36
+ **Change:** Decrement operator is not allowed with `bool` operand.
37
+ **Rationale:** Feature with surprising semantics. **Effect on original
38
+ feature:** A valid ISO C expression utilizing the decrement operator on
39
+ a `bool` lvalue (for instance, via the C typedef in ) is ill-formed in
40
+ this International Standard.
 
41
 
42
+ **Change:** Types must be defined in declarations, not in expressions.
 
43
  In C, a sizeof expression or cast expression may define a new type. For
44
  example,
45
 
46
  ``` cpp
47
  p = (void*)(struct x {int i;} *)0;
 
50
  defines a new type, struct `x`. **Rationale:** This prohibition helps to
51
  clarify the location of definitions in the source code. **Effect on
52
  original feature:** Deletion of semantically well-defined feature.
53
  Syntactic transformation. Seldom.
54
 
55
+ **Change:** The result of a conditional expression, an assignment
56
+ expression, or a comma expression may be an lvalue. **Rationale:** C++
57
+ is an object-oriented language, placing relatively more emphasis on
58
+ lvalues. For example, function calls may yield lvalues. **Effect on
59
+ original feature:** Change to semantics of well-defined feature. Some C
60
+ expressions that implicitly rely on lvalue-to-rvalue conversions will
61
+ yield different results. For example,
62
 
63
  ``` cpp
64
  char arr[100];
65
  sizeof(0, arr)
66
  ```