Skip to content

Commit 7f98cb5

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 9f242cf commit 7f98cb5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ Author: Daniel Kroening, kroening@kroening.com
4444
#include <sstream>
4545

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

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

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

0 commit comments

Comments
 (0)