cprover
cpp_typecheck_static_assert.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: C++ Language Type Checking
4 
5 Author: Daniel Kroening, kroening@cs.cmu.edu
6 
7 \*******************************************************************/
8 
11 
12 #include "cpp_typecheck.h"
13 
14 #include <util/std_types.h>
15 #include <util/string_constant.h>
16 
18 {
19  typecheck_expr(cpp_static_assert.op0());
20  typecheck_expr(cpp_static_assert.op1());
21 
22  cpp_static_assert.op0() =
23  typecast_exprt::conditional_cast(cpp_static_assert.op0(), bool_typet());
24  make_constant(cpp_static_assert.op0());
25 
26  if(cpp_static_assert.op0().is_true())
27  {
28  // ok
29  }
30  else if(cpp_static_assert.op0().is_false())
31  {
32  // failed
33  error().source_location=cpp_static_assert.source_location();
34  error() << "static assertion failed";
35  if(cpp_static_assert.op1().id()==ID_string_constant)
36  error() << ": "
37  << to_string_constant(cpp_static_assert.op1()).get_value();
38  error() << eom;
39  throw 0;
40  }
41  else
42  {
43  // not true or false
44  error().source_location=cpp_static_assert.source_location();
45  error() << "static assertion is not constant" << eom;
46  throw 0;
47  }
48 }
cpp_typecheckt::convert
void convert(cpp_linkage_spect &)
Definition: cpp_typecheck_linkage_spec.cpp:14
typecast_exprt::conditional_cast
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition: std_expr.h:2021
to_string_constant
const string_constantt & to_string_constant(const exprt &expr)
Definition: string_constant.h:31
string_constant.h
bool_typet
The Boolean type.
Definition: std_types.h:37
messaget::eom
static eomt eom
Definition: message.h:297
exprt::is_true
bool is_true() const
Return whether the expression is a constant representing true.
Definition: expr.cpp:92
exprt::is_false
bool is_false() const
Return whether the expression is a constant representing false.
Definition: expr.cpp:101
c_typecheck_baset::make_constant
virtual void make_constant(exprt &expr)
Definition: c_typecheck_expr.cpp:3552
messaget::error
mstreamt & error() const
Definition: message.h:399
messaget::mstreamt::source_location
source_locationt source_location
Definition: message.h:247
std_types.h
Pre-defined types.
irept::id
const irep_idt & id() const
Definition: irep.h:418
cpp_typecheck.h
C++ Language Type Checking.
cpp_typecheckt::typecheck_expr
void typecheck_expr(exprt &) override
Definition: cpp_typecheck_expr.cpp:2251
cpp_static_assertt
Definition: cpp_static_assert.h:18
binary_exprt::op1
exprt & op1()
Definition: expr.h:105
exprt::source_location
const source_locationt & source_location() const
Definition: expr.h:254
string_constantt::get_value
const irep_idt & get_value() const
Definition: string_constant.h:22
binary_exprt::op0
exprt & op0()
Definition: expr.h:102