Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Because an unevaluated operand in an expression is not evaluated, no side effects from that operand will be are triggered. Reliance on those side effects will result in unexpected behavior. Do not rely on side effects in unevaluated operands.

Note that unevaluated expression operands are used in situations were when the declaration of an object is required , but the definition of the object is not. For instance, in the following example below, the function f() is overloaded, which relies on the unevaluated expression operand to select the desired overload, which is then used to determine the result of the sizeof() expression:

Code Block
languagecpp
int f(int);
double f(double);
 
size_t size = sizeof(f(0));
Such a use is does not relying rely on the side effects of f(), and is conforming consequently conforms to this guideline.

Noncompliant Code Example (sizeof)

...

In this compliant solution, i is incremented outside of the decltype specifier , so that it is evaluated as desired:

...

EXP32-CPP-EX1: It is permissible for an expression with side effects to be used as an unevaluated operand in a macro definition or substitution failure is not an error (SFINAE) context. While Although these situations rely on the side effects to produce valid code, they typically do not rely on values produced as a result of the side effects.

...

The expansion of the macro m will result in the expression ++i being used as an unevaluated operand to sizeof(). However, however the expectation of the programmer at the expansion loci is that i is preincremented only once.

...

In an instantiation of is_incrementable, the use of the postfix increment operator generates side effects which that are used to determine whether the type is postfix incrementable. However, the value result of these side effects is discarded, so the side effects are used only used for SFINAE.

Risk Assessment

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

EXP52-CPP

Low

Unlikely

Low

P3

L3

Automated Detection

Tool

Version

Checker

Description

Clang
Include Page
Clang_V
Clang_V
-Wunevaluated-expression 

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...