- tmp/tmporgv2in8/{from.md → to.md} +152 -122
tmp/tmporgv2in8/{from.md → to.md}
RENAMED
|
@@ -10,126 +10,147 @@ during translation.
|
|
| 10 |
``` bnf
|
| 11 |
constant-expression:
|
| 12 |
conditional-expression
|
| 13 |
```
|
| 14 |
|
| 15 |
-
A *conditional-expression* is a *core constant expression* unless
|
| 16 |
-
|
| 17 |
-
[[
|
| 18 |
-
[[expr.log.and]]), logical OR ([[expr.log.or]]), and conditional (
|
| 19 |
-
[[expr.cond]]) operations that are not evaluated are not considered An
|
| 20 |
-
overloaded operator invokes a function.:
|
| 21 |
|
| 22 |
-
- `this` ([[expr.prim]])
|
| 23 |
-
|
| 24 |
-
implicit transformation in the body of a non-static member function (
|
| 25 |
-
[[class.mfct.non-static]]);
|
| 26 |
- an invocation of a function other than a `constexpr` constructor for a
|
| 27 |
-
literal class
|
|
|
|
| 28 |
[[over.match]]) is applied as usual ;
|
| 29 |
- an invocation of an undefined `constexpr` function or an undefined
|
| 30 |
-
`constexpr` constructor
|
| 31 |
-
|
| 32 |
-
- an invocation of a `constexpr` function with arguments that, when
|
| 33 |
-
substituted by function invocation substitution ([[dcl.constexpr]]),
|
| 34 |
-
do not produce a constant expression;
|
| 35 |
-
``` cpp
|
| 36 |
-
constexpr const int* addr(const int& ir) { return &ir; } // OK
|
| 37 |
-
static const int x = 5;
|
| 38 |
-
constexpr const int* xp = addr(x); // OK: (const int*)&(const int&)x is an
|
| 39 |
-
// address constant expression
|
| 40 |
-
constexpr const int* tp = addr(5); // error, initializer for constexpr variable not a constant
|
| 41 |
-
// expression; (const int*)&(const int&)5 is not a constant
|
| 42 |
-
// expression because it takes the address of a temporary
|
| 43 |
-
```
|
| 44 |
-
- an invocation of a `constexpr` constructor with arguments that, when
|
| 45 |
-
substituted by function invocation substitution ([[dcl.constexpr]]),
|
| 46 |
-
do not produce all constant expressions for the constructor calls and
|
| 47 |
-
full-expressions in the *mem-initializer*s;
|
| 48 |
-
``` cpp
|
| 49 |
-
int x; // not constant
|
| 50 |
-
struct A {
|
| 51 |
-
constexpr A(bool b) : m(b?42:x) { }
|
| 52 |
-
int m;
|
| 53 |
-
};
|
| 54 |
-
constexpr int v = A(true).m; // OK: constructor call initializes
|
| 55 |
-
// m with the value 42 after substitution
|
| 56 |
-
constexpr int w = A(false).m; // error: initializer for m is
|
| 57 |
-
// x, which is non-constant
|
| 58 |
-
```
|
| 59 |
-
- an invocation of a `constexpr` function or a `constexpr` constructor
|
| 60 |
-
that would exceed the implementation-defined recursion limits (see
|
| 61 |
Annex [[implimits]]);
|
| 62 |
-
-
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
- a *lambda-expression* ([[expr.prim.lambda]]);
|
| 65 |
- an lvalue-to-rvalue conversion ([[conv.lval]]) unless it is applied
|
| 66 |
to
|
| 67 |
-
- a glvalue of integral or enumeration type that refers
|
| 68 |
-
non-volatile const object with a preceding initialization,
|
| 69 |
-
initialized with a constant expression
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
- an lvalue-to-rvalue conversion ([[conv.lval]])
|
| 77 |
-
|
| 78 |
-
|
|
|
|
| 79 |
- an *id-expression* that refers to a variable or data member of
|
| 80 |
-
reference type unless the reference has a preceding initialization
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
- a dynamic cast ([[expr.dynamic.cast]]);
|
| 83 |
- a `reinterpret_cast` ([[expr.reinterpret.cast]]);
|
| 84 |
- a pseudo-destructor call ([[expr.pseudo]]);
|
| 85 |
-
-
|
| 86 |
-
[[expr.pre.incr]])
|
| 87 |
-
|
|
|
|
|
|
|
| 88 |
polymorphic class type;
|
| 89 |
- a *new-expression* ([[expr.new]]);
|
| 90 |
- a *delete-expression* ([[expr.delete]]);
|
| 91 |
-
- a subtraction ([[expr.add]]) where both operands are pointers;
|
| 92 |
- a relational ([[expr.rel]]) or equality ([[expr.eq]]) operator where
|
| 93 |
-
the result is unspecified;
|
| 94 |
-
- an assignment or a compound assignment ([[expr.ass]]); or
|
| 95 |
- a *throw-expression* ([[except.throw]]).
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
Although in some contexts constant expressions must be evaluated during
|
| 125 |
-
program translation, others may be evaluated during program execution.
|
| 126 |
Since this International Standard imposes no restrictions on the
|
| 127 |
accuracy of floating-point operations, it is unspecified whether the
|
| 128 |
evaluation of a floating-point expression during translation yields the
|
| 129 |
same result as the evaluation of the same expression (or the same
|
| 130 |
-
operations on the same values) during program execution.[^
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
bool f() {
|
| 134 |
char array[1 + int(1 + 0.2 - 0.1 - 0.1)]; // Must be evaluated during translation
|
| 135 |
int size = 1 + int(1 + 0.2 - 0.1 - 0.1); // May be evaluated at runtime
|
|
@@ -138,20 +159,20 @@ bool f() {
|
|
| 138 |
```
|
| 139 |
|
| 140 |
It is unspecified whether the value of `f()` will be `true` or `false`.
|
| 141 |
|
| 142 |
If an expression of literal class type is used in a context where an
|
| 143 |
-
integral constant expression is required, then that
|
| 144 |
-
|
| 145 |
-
unscoped enumeration type and
|
| 146 |
`constexpr`.
|
| 147 |
|
| 148 |
``` cpp
|
| 149 |
struct A {
|
| 150 |
constexpr A(int i) : val(i) { }
|
| 151 |
-
constexpr operator int() { return val; }
|
| 152 |
-
constexpr operator long() { return 43; }
|
| 153 |
private:
|
| 154 |
int val;
|
| 155 |
};
|
| 156 |
template<int> struct X { };
|
| 157 |
constexpr A a = 42;
|
|
@@ -171,12 +192,12 @@ int ary[a]; // error: ambiguous conversion
|
|
| 171 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 172 |
[basic.lookup.classref]: basic.md#basic.lookup.classref
|
| 173 |
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 174 |
[basic.lval]: basic.md#basic.lval
|
| 175 |
[basic.namespace]: dcl.md#basic.namespace
|
|
|
|
| 176 |
[basic.scope.class]: basic.md#basic.scope.class
|
| 177 |
-
[basic.scope.local]: basic.md#basic.scope.local
|
| 178 |
[basic.start.main]: basic.md#basic.start.main
|
| 179 |
[basic.stc.dynamic]: basic.md#basic.stc.dynamic
|
| 180 |
[basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
|
| 181 |
[basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
|
| 182 |
[basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
|
|
@@ -219,16 +240,16 @@ int ary[a]; // error: ambiguous conversion
|
|
| 219 |
[conv.prom]: conv.md#conv.prom
|
| 220 |
[conv.ptr]: conv.md#conv.ptr
|
| 221 |
[conv.qual]: conv.md#conv.qual
|
| 222 |
[dcl.align]: dcl.md#dcl.align
|
| 223 |
[dcl.array]: dcl.md#dcl.array
|
| 224 |
-
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 225 |
[dcl.dcl]: dcl.md#dcl.dcl
|
| 226 |
[dcl.enum]: dcl.md#dcl.enum
|
| 227 |
[dcl.fct]: dcl.md#dcl.fct
|
| 228 |
[dcl.fct.def]: dcl.md#dcl.fct.def
|
| 229 |
[dcl.fct.def.delete]: dcl.md#dcl.fct.def.delete
|
|
|
|
| 230 |
[dcl.fct.default]: dcl.md#dcl.fct.default
|
| 231 |
[dcl.init]: dcl.md#dcl.init
|
| 232 |
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 233 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 234 |
[dcl.init.ref]: dcl.md#dcl.init.ref
|
|
@@ -298,20 +319,22 @@ int ary[a]; // error: ambiguous conversion
|
|
| 298 |
[new.delete.single]: language.md#new.delete.single
|
| 299 |
[over]: over.md#over
|
| 300 |
[over.ass]: over.md#over.ass
|
| 301 |
[over.built]: over.md#over.built
|
| 302 |
[over.call]: over.md#over.call
|
|
|
|
| 303 |
[over.literal]: over.md#over.literal
|
| 304 |
[over.match]: over.md#over.match
|
| 305 |
[over.match.oper]: over.md#over.match.oper
|
| 306 |
[over.oper]: over.md#over.oper
|
| 307 |
[over.over]: over.md#over.over
|
| 308 |
[replacement.functions]: library.md#replacement.functions
|
| 309 |
[stmt.switch]: stmt.md#stmt.switch
|
| 310 |
[support.runtime]: language.md#support.runtime
|
| 311 |
[support.types]: language.md#support.types
|
| 312 |
[temp.arg]: temp.md#temp.arg
|
|
|
|
| 313 |
[temp.names]: temp.md#temp.names
|
| 314 |
[temp.res]: temp.md#temp.res
|
| 315 |
[temp.variadic]: temp.md#temp.variadic
|
| 316 |
[type.info]: language.md#type.info
|
| 317 |
|
|
@@ -330,53 +353,55 @@ int ary[a]; // error: ambiguous conversion
|
|
| 330 |
`(*this)` ([[class.mfct.non-static]]).
|
| 331 |
|
| 332 |
[^5]: This is true even if the subscript operator is used in the
|
| 333 |
following common idiom: `&x[0]`.
|
| 334 |
|
| 335 |
-
[^6]:
|
| 336 |
-
function.
|
| 337 |
-
|
| 338 |
-
[^7]: If the class member access expression is evaluated, the
|
| 339 |
subexpression evaluation happens even if the result is unnecessary
|
| 340 |
to determine the value of the entire postfix expression, for example
|
| 341 |
if the *id-expression* denotes a static member.
|
| 342 |
|
| 343 |
-
[^
|
| 344 |
|
| 345 |
-
[^
|
| 346 |
by `v` can contain other `B` objects as base classes, but these are
|
| 347 |
ignored.
|
| 348 |
|
| 349 |
-
[^
|
| 350 |
|
| 351 |
-
[^
|
| 352 |
`*(p)`, `((*p))`, `*((p))`, and so on all meet this requirement.
|
| 353 |
|
| 354 |
-
[^
|
| 355 |
function types) are never cv-qualified; see [[dcl.fct]].
|
| 356 |
|
| 357 |
-
[^
|
| 358 |
overall restriction that a `reinterpret_cast` cannot cast away
|
| 359 |
constness.
|
| 360 |
|
| 361 |
-
[^
|
| 362 |
overall restriction that a `reinterpret_cast` cannot cast away
|
| 363 |
constness.
|
| 364 |
|
| 365 |
-
[^
|
| 366 |
|
| 367 |
-
[^
|
| 368 |
|
| 369 |
is not limited to conversions that cast away a const-qualifier.
|
| 370 |
|
| 371 |
-
[^
|
| 372 |
|
| 373 |
-
[^
|
| 374 |
result of applying `sizeof` to the subobject, due to virtual base
|
| 375 |
classes and less strict padding requirements on base class
|
| 376 |
subobjects.
|
| 377 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
[^19]: This may include evaluating a *new-initializer* and/or calling a
|
| 379 |
constructor.
|
| 380 |
|
| 381 |
[^20]: A lambda expression with a *lambda-introducer* that consists of
|
| 382 |
empty square brackets can follow the `delete` keyword if the lambda
|
|
@@ -387,16 +412,21 @@ int ary[a]; // error: ambiguous conversion
|
|
| 387 |
|
| 388 |
[^22]: For non-zero-length arrays, this is the same as a pointer to the
|
| 389 |
first element of the array created by that *new-expression*.
|
| 390 |
Zero-length arrays do not have a first element.
|
| 391 |
|
| 392 |
-
[^23]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
function in a *new-expression*.
|
| 394 |
|
| 395 |
-
[^
|
| 396 |
|
| 397 |
-
[^
|
| 398 |
the pointer(s) to character pointer(s): In this scheme the integral
|
| 399 |
value of the expression added to or subtracted from the converted
|
| 400 |
pointer is first multiplied by the size of the object originally
|
| 401 |
pointed to, and the resulting pointer is converted back to the
|
| 402 |
original type. For pointer subtraction, the result of the difference
|
|
@@ -406,13 +436,13 @@ int ary[a]; // error: ambiguous conversion
|
|
| 406 |
When viewed in this way, an implementation need only provide one
|
| 407 |
extra byte (which might overlap another object in the program) just
|
| 408 |
after the end of the object in order to satisfy the “one past the
|
| 409 |
last element” requirements.
|
| 410 |
|
| 411 |
-
[^
|
| 412 |
ordinary function call; hence, the evaluations of its argument
|
| 413 |
expressions are unsequenced relative to one another (see
|
| 414 |
[[intro.execution]]).
|
| 415 |
|
| 416 |
-
[^
|
| 417 |
-
results, irrespective of whether the evaluation was
|
| 418 |
-
|
|
|
|
| 10 |
``` bnf
|
| 11 |
constant-expression:
|
| 12 |
conditional-expression
|
| 13 |
```
|
| 14 |
|
| 15 |
+
A *conditional-expression* `e` is a *core constant expression* unless
|
| 16 |
+
the evaluation of `e`, following the rules of the abstract machine (
|
| 17 |
+
[[intro.execution]]), would evaluate one of the following expressions:
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
- `this` ([[expr.prim.general]]), except in a `constexpr` function or a
|
| 20 |
+
`constexpr` constructor that is being evaluated as part of `e`;
|
|
|
|
|
|
|
| 21 |
- an invocation of a function other than a `constexpr` constructor for a
|
| 22 |
+
literal class, a `constexpr` function, or an implicit invocation of a
|
| 23 |
+
trivial destructor ([[class.dtor]]) Overload resolution (
|
| 24 |
[[over.match]]) is applied as usual ;
|
| 25 |
- an invocation of an undefined `constexpr` function or an undefined
|
| 26 |
+
`constexpr` constructor;
|
| 27 |
+
- an expression that would exceed the implementation-defined limits (see
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
Annex [[implimits]]);
|
| 29 |
+
- an operation that would have undefined behavior including, for
|
| 30 |
+
example, signed integer overflow (Clause [[expr]]), certain pointer
|
| 31 |
+
arithmetic ([[expr.add]]), division by zero ([[expr.mul]]), or
|
| 32 |
+
certain shift operations ([[expr.shift]]) ;
|
| 33 |
- a *lambda-expression* ([[expr.prim.lambda]]);
|
| 34 |
- an lvalue-to-rvalue conversion ([[conv.lval]]) unless it is applied
|
| 35 |
to
|
| 36 |
+
- a non-volatile glvalue of integral or enumeration type that refers
|
| 37 |
+
to a non-volatile const object with a preceding initialization,
|
| 38 |
+
initialized with a constant expression a string literal (
|
| 39 |
+
[[lex.string]]) corresponds to an array of such objects. , or
|
| 40 |
+
- a non-volatile glvalue that refers to a non-volatile object defined
|
| 41 |
+
with `constexpr`, or that refers to a non-mutable sub-object of such
|
| 42 |
+
an object, or
|
| 43 |
+
- a non-volatile glvalue of literal type that refers to a non-volatile
|
| 44 |
+
object whose lifetime began within the evaluation of `e`;
|
| 45 |
+
- an lvalue-to-rvalue conversion ([[conv.lval]]) or modification (
|
| 46 |
+
[[expr.ass]], [[expr.post.incr]], [[expr.pre.incr]]) that is applied
|
| 47 |
+
to a glvalue that refers to a non-active member of a union or a
|
| 48 |
+
subobject thereof;
|
| 49 |
- an *id-expression* that refers to a variable or data member of
|
| 50 |
+
reference type unless the reference has a preceding initialization and
|
| 51 |
+
either
|
| 52 |
+
- it is initialized with a constant expression or
|
| 53 |
+
- it is a non-static data member of an object whose lifetime began
|
| 54 |
+
within the evaluation of `e`;
|
| 55 |
+
- in a *lambda-expression*, a reference to `this` or to a variable with
|
| 56 |
+
automatic storage duration defined outside that *lambda-expression*,
|
| 57 |
+
where the reference would be an odr-use ([[basic.def.odr]],
|
| 58 |
+
[[expr.prim.lambda]]);
|
| 59 |
+
- a conversion from type cv `void *` to a pointer-to-object type;
|
| 60 |
- a dynamic cast ([[expr.dynamic.cast]]);
|
| 61 |
- a `reinterpret_cast` ([[expr.reinterpret.cast]]);
|
| 62 |
- a pseudo-destructor call ([[expr.pseudo]]);
|
| 63 |
+
- modification of an object ([[expr.ass]], [[expr.post.incr]],
|
| 64 |
+
[[expr.pre.incr]]) unless it is applied to a non-volatile lvalue of
|
| 65 |
+
literal type that refers to a non-volatile object whose lifetime began
|
| 66 |
+
within the evaluation of `e`;
|
| 67 |
+
- a typeid expression ([[expr.typeid]]) whose operand is a glvalue of a
|
| 68 |
polymorphic class type;
|
| 69 |
- a *new-expression* ([[expr.new]]);
|
| 70 |
- a *delete-expression* ([[expr.delete]]);
|
|
|
|
| 71 |
- a relational ([[expr.rel]]) or equality ([[expr.eq]]) operator where
|
| 72 |
+
the result is unspecified; or
|
|
|
|
| 73 |
- a *throw-expression* ([[except.throw]]).
|
| 74 |
|
| 75 |
+
``` cpp
|
| 76 |
+
int x; // not constant
|
| 77 |
+
struct A {
|
| 78 |
+
constexpr A(bool b) : m(b?42:x) { }
|
| 79 |
+
int m;
|
| 80 |
+
};
|
| 81 |
+
constexpr int v = A(true).m; // OK: constructor call initializes
|
| 82 |
+
// m with the value 42
|
| 83 |
+
constexpr int w = A(false).m; // error: initializer for m is
|
| 84 |
+
// x, which is non-constant
|
| 85 |
+
|
| 86 |
+
constexpr int f1(int k) {
|
| 87 |
+
constexpr int x = k; // error: x is not initialized by a
|
| 88 |
+
// constant expression because lifetime of k
|
| 89 |
+
// began outside the initializer of x
|
| 90 |
+
return x;
|
| 91 |
+
}
|
| 92 |
+
constexpr int f2(int k) {
|
| 93 |
+
int x = k; // OK: not required to be a constant expression
|
| 94 |
+
// because x is not constexpr
|
| 95 |
+
return x;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
constexpr int incr(int &n) {
|
| 99 |
+
return ++n;
|
| 100 |
+
}
|
| 101 |
+
constexpr int g(int k) {
|
| 102 |
+
constexpr int x = incr(k); // error: incr(k) is not a core constant
|
| 103 |
+
// expression because lifetime of k
|
| 104 |
+
// began outside the expression incr(k)
|
| 105 |
+
return x;
|
| 106 |
+
}
|
| 107 |
+
constexpr int h(int k) {
|
| 108 |
+
int x = incr(k); // OK: incr(k) is not required to be a core
|
| 109 |
+
// constant expression
|
| 110 |
+
return x;
|
| 111 |
+
}
|
| 112 |
+
constexpr int y = h(1); // OK: initializes y with the value 2
|
| 113 |
+
// h(1) is a core constant expression because
|
| 114 |
+
// the lifetime of k begins inside h(1)
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
An *integral constant expression* is an expression of integral or
|
| 118 |
+
unscoped enumeration type, implicitly converted to a prvalue, where the
|
| 119 |
+
converted expression is a core constant expression. Such expressions may
|
| 120 |
+
be used as array bounds ([[dcl.array]], [[expr.new]]), as bit-field
|
| 121 |
+
lengths ([[class.bit]]), as enumerator initializers if the underlying
|
| 122 |
+
type is not fixed ([[dcl.enum]]), and as alignments ([[dcl.align]]). A
|
| 123 |
+
*converted constant expression* of type `T` is an expression, implicitly
|
| 124 |
+
converted to a prvalue of type `T`, where the converted expression is a
|
| 125 |
+
core constant expression and the implicit conversion sequence contains
|
| 126 |
+
only user-defined conversions, lvalue-to-rvalue conversions (
|
| 127 |
+
[[conv.lval]]), integral promotions ([[conv.prom]]), and integral
|
| 128 |
+
conversions ([[conv.integral]]) other than narrowing conversions (
|
| 129 |
+
[[dcl.init.list]]). such expressions may be used in `new` expressions (
|
| 130 |
+
[[expr.new]]), as case expressions ([[stmt.switch]]), as enumerator
|
| 131 |
+
initializers if the underlying type is fixed ([[dcl.enum]]), as array
|
| 132 |
+
bounds ([[dcl.array]]), and as integral or enumeration non-type
|
| 133 |
+
template arguments ([[temp.arg]]).
|
| 134 |
+
|
| 135 |
+
A *constant expression* is either a glvalue core constant expression
|
| 136 |
+
whose value refers to an object with static storage duration or to a
|
| 137 |
+
function, or a prvalue core constant expression whose value is an object
|
| 138 |
+
where, for that object and its subobjects:
|
| 139 |
+
|
| 140 |
+
- each non-static data member of reference type refers to an object with
|
| 141 |
+
static storage duration or to a function, and
|
| 142 |
+
- if the object or subobject is of pointer type, it contains the address
|
| 143 |
+
of an object with static storage duration, the address past the end of
|
| 144 |
+
such an object ([[expr.add]]), the address of a function, or a null
|
| 145 |
+
pointer value.
|
| 146 |
|
|
|
|
|
|
|
| 147 |
Since this International Standard imposes no restrictions on the
|
| 148 |
accuracy of floating-point operations, it is unspecified whether the
|
| 149 |
evaluation of a floating-point expression during translation yields the
|
| 150 |
same result as the evaluation of the same expression (or the same
|
| 151 |
+
operations on the same values) during program execution.[^28]
|
| 152 |
|
| 153 |
``` cpp
|
| 154 |
bool f() {
|
| 155 |
char array[1 + int(1 + 0.2 - 0.1 - 0.1)]; // Must be evaluated during translation
|
| 156 |
int size = 1 + int(1 + 0.2 - 0.1 - 0.1); // May be evaluated at runtime
|
|
|
|
| 159 |
```
|
| 160 |
|
| 161 |
It is unspecified whether the value of `f()` will be `true` or `false`.
|
| 162 |
|
| 163 |
If an expression of literal class type is used in a context where an
|
| 164 |
+
integral constant expression is required, then that expression is
|
| 165 |
+
contextually implicitly converted (Clause [[conv]]) to an integral or
|
| 166 |
+
unscoped enumeration type and the selected conversion function shall be
|
| 167 |
`constexpr`.
|
| 168 |
|
| 169 |
``` cpp
|
| 170 |
struct A {
|
| 171 |
constexpr A(int i) : val(i) { }
|
| 172 |
+
constexpr operator int() const { return val; }
|
| 173 |
+
constexpr operator long() const { return 43; }
|
| 174 |
private:
|
| 175 |
int val;
|
| 176 |
};
|
| 177 |
template<int> struct X { };
|
| 178 |
constexpr A a = 42;
|
|
|
|
| 192 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 193 |
[basic.lookup.classref]: basic.md#basic.lookup.classref
|
| 194 |
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 195 |
[basic.lval]: basic.md#basic.lval
|
| 196 |
[basic.namespace]: dcl.md#basic.namespace
|
| 197 |
+
[basic.scope.block]: basic.md#basic.scope.block
|
| 198 |
[basic.scope.class]: basic.md#basic.scope.class
|
|
|
|
| 199 |
[basic.start.main]: basic.md#basic.start.main
|
| 200 |
[basic.stc.dynamic]: basic.md#basic.stc.dynamic
|
| 201 |
[basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
|
| 202 |
[basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
|
| 203 |
[basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
|
|
|
|
| 240 |
[conv.prom]: conv.md#conv.prom
|
| 241 |
[conv.ptr]: conv.md#conv.ptr
|
| 242 |
[conv.qual]: conv.md#conv.qual
|
| 243 |
[dcl.align]: dcl.md#dcl.align
|
| 244 |
[dcl.array]: dcl.md#dcl.array
|
|
|
|
| 245 |
[dcl.dcl]: dcl.md#dcl.dcl
|
| 246 |
[dcl.enum]: dcl.md#dcl.enum
|
| 247 |
[dcl.fct]: dcl.md#dcl.fct
|
| 248 |
[dcl.fct.def]: dcl.md#dcl.fct.def
|
| 249 |
[dcl.fct.def.delete]: dcl.md#dcl.fct.def.delete
|
| 250 |
+
[dcl.fct.def.general]: dcl.md#dcl.fct.def.general
|
| 251 |
[dcl.fct.default]: dcl.md#dcl.fct.default
|
| 252 |
[dcl.init]: dcl.md#dcl.init
|
| 253 |
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 254 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 255 |
[dcl.init.ref]: dcl.md#dcl.init.ref
|
|
|
|
| 319 |
[new.delete.single]: language.md#new.delete.single
|
| 320 |
[over]: over.md#over
|
| 321 |
[over.ass]: over.md#over.ass
|
| 322 |
[over.built]: over.md#over.built
|
| 323 |
[over.call]: over.md#over.call
|
| 324 |
+
[over.ics.user]: over.md#over.ics.user
|
| 325 |
[over.literal]: over.md#over.literal
|
| 326 |
[over.match]: over.md#over.match
|
| 327 |
[over.match.oper]: over.md#over.match.oper
|
| 328 |
[over.oper]: over.md#over.oper
|
| 329 |
[over.over]: over.md#over.over
|
| 330 |
[replacement.functions]: library.md#replacement.functions
|
| 331 |
[stmt.switch]: stmt.md#stmt.switch
|
| 332 |
[support.runtime]: language.md#support.runtime
|
| 333 |
[support.types]: language.md#support.types
|
| 334 |
[temp.arg]: temp.md#temp.arg
|
| 335 |
+
[temp.mem]: temp.md#temp.mem
|
| 336 |
[temp.names]: temp.md#temp.names
|
| 337 |
[temp.res]: temp.md#temp.res
|
| 338 |
[temp.variadic]: temp.md#temp.variadic
|
| 339 |
[type.info]: language.md#type.info
|
| 340 |
|
|
|
|
| 353 |
`(*this)` ([[class.mfct.non-static]]).
|
| 354 |
|
| 355 |
[^5]: This is true even if the subscript operator is used in the
|
| 356 |
following common idiom: `&x[0]`.
|
| 357 |
|
| 358 |
+
[^6]: If the class member access expression is evaluated, the
|
|
|
|
|
|
|
|
|
|
| 359 |
subexpression evaluation happens even if the result is unnecessary
|
| 360 |
to determine the value of the entire postfix expression, for example
|
| 361 |
if the *id-expression* denotes a static member.
|
| 362 |
|
| 363 |
+
[^7]: Note that `(*(E1))` is an lvalue.
|
| 364 |
|
| 365 |
+
[^8]: The most derived object ([[intro.object]]) pointed or referred to
|
| 366 |
by `v` can contain other `B` objects as base classes, but these are
|
| 367 |
ignored.
|
| 368 |
|
| 369 |
+
[^9]: The recommended name for such a class is `extended_type_info`.
|
| 370 |
|
| 371 |
+
[^10]: If `p` is an expression of pointer type, then `*p`, `(*p)`,
|
| 372 |
`*(p)`, `((*p))`, `*((p))`, and so on all meet this requirement.
|
| 373 |
|
| 374 |
+
[^11]: Function types (including those used in pointer to member
|
| 375 |
function types) are never cv-qualified; see [[dcl.fct]].
|
| 376 |
|
| 377 |
+
[^12]: The types may have different cv-qualifiers, subject to the
|
| 378 |
overall restriction that a `reinterpret_cast` cannot cast away
|
| 379 |
constness.
|
| 380 |
|
| 381 |
+
[^13]: `T1` and `T2` may have different cv-qualifiers, subject to the
|
| 382 |
overall restriction that a `reinterpret_cast` cannot cast away
|
| 383 |
constness.
|
| 384 |
|
| 385 |
+
[^14]: This is sometimes referred to as a *type pun*.
|
| 386 |
|
| 387 |
+
[^15]: `const_cast`
|
| 388 |
|
| 389 |
is not limited to conversions that cast away a const-qualifier.
|
| 390 |
|
| 391 |
+
[^16]: `sizeof(bool)` is not required to be `1`.
|
| 392 |
|
| 393 |
+
[^17]: The actual size of a base class subobject may be less than the
|
| 394 |
result of applying `sizeof` to the subobject, due to virtual base
|
| 395 |
classes and less strict padding requirements on base class
|
| 396 |
subobjects.
|
| 397 |
|
| 398 |
+
[^18]: If the conversion function returns a signed integer type, the
|
| 399 |
+
second standard conversion converts to the unsigned type
|
| 400 |
+
`std::size_t` and thus thwarts any attempt to detect a negative
|
| 401 |
+
value afterwards.
|
| 402 |
+
|
| 403 |
[^19]: This may include evaluating a *new-initializer* and/or calling a
|
| 404 |
constructor.
|
| 405 |
|
| 406 |
[^20]: A lambda expression with a *lambda-introducer* that consists of
|
| 407 |
empty square brackets can follow the `delete` keyword if the lambda
|
|
|
|
| 412 |
|
| 413 |
[^22]: For non-zero-length arrays, this is the same as a pointer to the
|
| 414 |
first element of the array created by that *new-expression*.
|
| 415 |
Zero-length arrays do not have a first element.
|
| 416 |
|
| 417 |
+
[^23]: If the static type of the object to be deleted is complete and is
|
| 418 |
+
different from the dynamic type, and the destructor is not virtual,
|
| 419 |
+
the size might be incorrect, but that case is already undefined, as
|
| 420 |
+
stated above.
|
| 421 |
+
|
| 422 |
+
[^24]: This includes implicit calls such as the call to an allocation
|
| 423 |
function in a *new-expression*.
|
| 424 |
|
| 425 |
+
[^25]: This is often called truncation towards zero.
|
| 426 |
|
| 427 |
+
[^26]: Another way to approach pointer arithmetic is first to convert
|
| 428 |
the pointer(s) to character pointer(s): In this scheme the integral
|
| 429 |
value of the expression added to or subtracted from the converted
|
| 430 |
pointer is first multiplied by the size of the object originally
|
| 431 |
pointed to, and the resulting pointer is converted back to the
|
| 432 |
original type. For pointer subtraction, the result of the difference
|
|
|
|
| 436 |
When viewed in this way, an implementation need only provide one
|
| 437 |
extra byte (which might overlap another object in the program) just
|
| 438 |
after the end of the object in order to satisfy the “one past the
|
| 439 |
last element” requirements.
|
| 440 |
|
| 441 |
+
[^27]: However, an invocation of an overloaded comma operator is an
|
| 442 |
ordinary function call; hence, the evaluations of its argument
|
| 443 |
expressions are unsequenced relative to one another (see
|
| 444 |
[[intro.execution]]).
|
| 445 |
|
| 446 |
+
[^28]: Nonetheless, implementations are encouraged to provide consistent
|
| 447 |
+
results, irrespective of whether the evaluation was performed during
|
| 448 |
+
translation and/or during program execution.
|