Consider an example:
template <char> struct foo { }; int main() { foo<""[0]?""[1]:'\0'>{}; }
The code compiles in both [gcc] and [clang] , but is it really so? I know that an expression ""[1]does not need to be evaluated as it shorts. But the standard is not very clear if an expression can really qualify as a basic constant expression. Relevant [expr.const] / 2 and especially the part:
""[1]
If e satisfies the constraints of the main constant expression, but evaluating e will evaluate the operation with undefined behavior specified in the [library] through the [thread] of this document, it is not known whether e is the main expression of the constant.
in doubt ...
, :
e , e undefined , [library] - [thread] , , e .
e
[library]
[thread]
""[0]?""[1]:'\0' undefined, ""[1] . , '\0' .
""[0]?""[1]:'\0'
'\0'
, , (, C++11 5.16 Conditional operator [expr.cond] /1:
C++11 5.16 Conditional operator [expr.cond] /1
. bool ( 4). , , , . .
bool
""[0] false , . :
""[0]
false ? (1/0) : 42
, .
, , :
e , , , :
, ([expr.cond]/1):
. bool. , , , . .
undefined, . , , , , .
Source: https://habr.com/ru/post/1689892/More articles:Get primary key id in inserted string in symfony - phpConditionally fill cells in certain columns with color depending on the value in another column - html-tableMongoDb for offline data storage - mongodbКак получить ключевое имя массива в представлении веточки - arraysWhat is the "postprocessing" block inside the "release" block in the gradle application level file in Android Studio? - androidSerilog configuration for non-logging Asp.Net Core 2.0.1 - jsonImageView selectableItemBackgroundBorderless is not out of view - androidSpring4d: Spring.Collections.IEnumerator и System.IEnumerator - delphihow to use a foreign key in a library for saving numbers - androidудалите шаблон перед цифрами и сохраните эти цифры - regexAll Articles