@@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com
1515#include < util/config.h>
1616#include < util/expr_initializer.h>
1717#include < util/range.h>
18+ #include < util/string_constant.h>
1819
1920#include " ansi_c_declaration.h"
2021
@@ -102,9 +103,24 @@ void c_typecheck_baset::typecheck_code(codet &code)
102103 }
103104 else if (statement==ID_static_assert)
104105 {
105- assert (code.operands ().size ()==2 );
106+ PRECONDITION (code.operands ().size () == 2 );
107+
106108 typecheck_expr (code.op0 ());
107109 typecheck_expr (code.op1 ());
110+
111+ implicit_typecast_bool (code.op0 ());
112+ make_constant (code.op0 ());
113+
114+ if (code.op0 ().is_false ())
115+ {
116+ // failed
117+ error ().source_location = code.find_source_location ();
118+ error () << " static assertion failed" ;
119+ if (code.op1 ().id () == ID_string_constant)
120+ error () << " : " << to_string_constant (code.op1 ()).get_value ();
121+ error () << eom;
122+ throw 0 ;
123+ }
108124 }
109125 else if (statement==ID_CPROVER_try_catch ||
110126 statement==ID_CPROVER_try_finally)
@@ -247,7 +263,6 @@ void c_typecheck_baset::typecheck_decl(codet &code)
247263
248264 if (declaration.get_is_static_assert ())
249265 {
250- assert (declaration.operands ().size ()==2 );
251266 codet new_code (ID_static_assert);
252267 new_code.add_source_location ()=code.source_location ();
253268 new_code.operands ().swap (declaration.operands ());
0 commit comments