@@ -126,6 +126,12 @@ void cpp_typecheckt::typecheck_expr_main(exprt &expr)
126126 {
127127 expr.type ().id (ID_initializer_list);
128128 }
129+ else if (
130+ expr.id () == ID_const_cast || expr.id () == ID_dynamic_cast ||
131+ expr.id () == ID_reinterpret_cast || expr.id () == ID_static_cast)
132+ {
133+ typecheck_cast_expr (expr);
134+ }
129135 else
130136 c_typecheck_baset::typecheck_expr_main (expr);
131137}
@@ -966,13 +972,8 @@ void cpp_typecheckt::typecheck_expr_explicit_constructor_call(exprt &expr)
966972 }
967973 else
968974 {
969- CHECK_RETURN (expr.type ().id () == ID_struct);
970-
971- struct_tag_typet tag (expr.type ().get (ID_name));
972- tag.add_source_location () = expr.source_location ();
973-
974975 exprt e=expr;
975- new_temporary (e.source_location (), tag , e.operands (), expr);
976+ new_temporary (e.source_location (), e. type () , e.operands (), expr);
976977 }
977978}
978979
@@ -1274,53 +1275,20 @@ void cpp_typecheckt::typecheck_expr_ptrmember(
12741275
12751276void cpp_typecheckt::typecheck_cast_expr (exprt &expr)
12761277{
1277- side_effect_expr_function_callt e =
1278- to_side_effect_expr_function_call (expr);
1279-
1280- if (e.arguments ().size () != 1 )
1278+ if (expr.operands ().size () != 1 )
12811279 {
12821280 error ().source_location =expr.find_source_location ();
12831281 error () << " cast expressions expect one operand" << eom;
12841282 throw 0 ;
12851283 }
12861284
1287- exprt &f_op=e.function ();
1288- exprt &cast_op=e.arguments ().front ();
1285+ exprt &cast_op = to_unary_expr (expr).op ();
12891286
12901287 add_implicit_dereference (cast_op);
12911288
1292- const irep_idt &id=
1293- f_op.get_sub ().front ().get (ID_identifier);
1294-
1295- if (f_op.get_sub ().size ()!=2 ||
1296- f_op.get_sub ()[1 ].id ()!=ID_template_args)
1297- {
1298- error ().source_location =expr.find_source_location ();
1299- error () << id << " expects template argument" << eom;
1300- throw 0 ;
1301- }
1302-
1303- irept &template_arguments=f_op.get_sub ()[1 ].add (ID_arguments);
1304-
1305- if (template_arguments.get_sub ().size ()!=1 )
1306- {
1307- error ().source_location =expr.find_source_location ();
1308- error () << id << " expects one template argument" << eom;
1309- throw 0 ;
1310- }
1311-
1312- irept &template_arg=template_arguments.get_sub ().front ();
1313-
1314- if (template_arg.id () != ID_type && template_arg.id () != ID_ambiguous)
1315- {
1316- error ().source_location =expr.find_source_location ();
1317- error () << id << " expects a type as template argument" << eom;
1318- throw 0 ;
1319- }
1320-
1321- typet &type=static_cast <typet &>(
1322- template_arguments.get_sub ().front ().add (ID_type));
1289+ const irep_idt &id = expr.id ();
13231290
1291+ typet &type = expr.type ();
13241292 typecheck_type (type);
13251293
13261294 source_locationt source_location=expr.source_location ();
@@ -1414,21 +1382,6 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
14141382 }
14151383 }
14161384
1417- if (expr.get_sub ().size ()>=1 &&
1418- expr.get_sub ().front ().id ()==ID_name)
1419- {
1420- const irep_idt &id=expr.get_sub ().front ().get (ID_identifier);
1421-
1422- if (id==ID_const_cast ||
1423- id==ID_dynamic_cast ||
1424- id==ID_reinterpret_cast ||
1425- id==ID_static_cast)
1426- {
1427- expr.id (ID_cast_expression);
1428- return ;
1429- }
1430- }
1431-
14321385 exprt symbol_expr=
14331386 resolve (
14341387 to_cpp_name (expr),
@@ -1555,14 +1508,6 @@ void cpp_typecheckt::typecheck_side_effect_function_call(
15551508
15561509 return ;
15571510 }
1558- else if (expr.function ().id () == ID_cast_expression)
1559- {
1560- // These are not really function calls,
1561- // but usually just type adjustments.
1562- typecheck_cast_expr (expr);
1563- add_implicit_dereference (expr);
1564- return ;
1565- }
15661511 else if (expr.function ().id () == ID_cpp_dummy_destructor)
15671512 {
15681513 // these don't do anything, e.g., (char*)->~char()
0 commit comments