Skip to content

Commit 8ef7e92

Browse files
committed
Expand documentation of is_compile_time_constantt
C11 Section 6.6 "Constant expressions" defines what are required to be constant expressions, and permits implementations to pick additional constant expressions.
1 parent ec48f3c commit 8ef7e92

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ansi-c/c_typecheck_expr.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ Author: Daniel Kroening, [email protected]
4545
#include <sstream>
4646

4747
/// Architecturally similar to \ref can_forward_propagatet, but specialized for
48-
/// what is a constexpr, i.e., an expression that can be fully evaluated at
49-
/// compile time.
48+
/// what is an expression that can be fully evaluated at compile time within
49+
/// the limits of what the C standard permits. See 6.6 Constant expressions in
50+
/// C11.
5051
class is_compile_time_constantt
5152
{
5253
public:
@@ -67,16 +68,21 @@ class is_compile_time_constantt
6768
/// "constants"
6869
bool is_constant(const exprt &e) const
6970
{
71+
// non-standard numeric constant
7072
if(e.id() == ID_infinity)
7173
return true;
7274

75+
// numeric, character, or pointer-typed constant
7376
if(e.is_constant())
7477
return true;
7578

79+
// possibly an address constant
7680
if(e.id() == ID_address_of)
7781
{
7882
return is_constant_address_of(to_address_of_expr(e).object());
7983
}
84+
// we choose to accept the following expressions (over constant operands) as
85+
// constant expressions
8086
else if(
8187
e.id() == ID_typecast || e.id() == ID_array_of || e.id() == ID_plus ||
8288
e.id() == ID_mult || e.id() == ID_array || e.id() == ID_with ||

0 commit comments

Comments
 (0)