File tree 6 files changed +37
-17
lines changed
pointer_to_member_conversion1
pointer_to_member_conversion2
6 files changed +37
-17
lines changed Original file line number Diff line number Diff line change 1
- KNOWNBUG
1
+ CORE
2
2
main.cpp
3
3
4
4
^EXIT=0$
5
5
^SIGNAL=0$
6
- ^VERIFICATION SUCCESSFUL$
7
6
--
8
7
^warning: ignoring
9
- --
10
- should exercise cpp_typecheckt::standard_conversion_pointer_to_member, cpp/cpp_typecheck_conversion.cpp:610 once other bugs are fixed
Original file line number Diff line number Diff line change 1
- KNOWNBUG
1
+ CORE
2
2
main.cpp
3
3
4
4
^EXIT=(64|1)$
5
5
^SIGNAL=0$
6
- invalid implicit conversion
6
+ pointer-to-member type error
7
7
^CONVERSION ERROR$
8
8
--
9
9
^warning: ignoring
10
- --
11
- should exercise cpp_typecheckt::standard_conversion_pointer_to_member, cpp/cpp_typecheck_conversion.cpp:610 once other bugs are fixed
Original file line number Diff line number Diff line change @@ -1595,9 +1595,11 @@ bool cpp_typecheckt::cast_away_constness(
1595
1595
1596
1596
if (is_reference (nt1))
1597
1597
nt1.remove (ID_C_reference);
1598
+ nt1.remove (" to-member" );
1598
1599
1599
1600
if (is_reference (nt2))
1600
1601
nt2.remove (ID_C_reference);
1602
+ nt2.remove (" to-member" );
1601
1603
1602
1604
// substitute final subtypes
1603
1605
std::vector<typet> snt1;
@@ -2021,6 +2023,21 @@ bool cpp_typecheckt::static_typecast(
2021
2023
return true ;
2022
2024
}
2023
2025
}
2026
+ else if (
2027
+ type.find (" to-member" ).is_nil () &&
2028
+ e.type ().find (" to-member" ).is_not_nil ())
2029
+ {
2030
+ if (type.subtype () != e.type ().subtype ())
2031
+ return false ;
2032
+
2033
+ struct_typet from_struct = to_struct_type (
2034
+ follow (static_cast <const typet &>(e.type ().find (" to-member" ))));
2035
+
2036
+ new_expr = e;
2037
+ new_expr.type ().add (" to-member" ) = from_struct;
2038
+
2039
+ return true ;
2040
+ }
2024
2041
else
2025
2042
return false ;
2026
2043
}
Original file line number Diff line number Diff line change @@ -748,6 +748,13 @@ void cpp_typecheckt::typecheck_expr_address_of(exprt &expr)
748
748
}
749
749
}
750
750
}
751
+ else if (
752
+ expr.op0 ().id () == ID_ptrmember && expr.op0 ().op0 ().id () == " cpp-this" )
753
+ {
754
+ expr.type () = pointer_type (expr.op0 ().type ());
755
+ expr.type ().add (" to-member" ) = expr.op0 ().op0 ().type ().subtype ();
756
+ return ;
757
+ }
751
758
752
759
// the C front end does not know about references
753
760
const bool is_ref=is_reference (expr.type ());
@@ -2626,13 +2633,6 @@ void cpp_typecheckt::convert_pmop(exprt &expr)
2626
2633
throw 0 ;
2627
2634
}
2628
2635
2629
- if (expr.op1 ().type ().subtype ().id ()!=ID_code)
2630
- {
2631
- error ().source_location =expr.find_source_location ();
2632
- error () << " pointers to data member are not supported" << eom;
2633
- throw 0 ;
2634
- }
2635
-
2636
2636
typecheck_expr_main (expr.op1 ());
2637
2637
2638
2638
if (expr.op0 ().type ().id ()!=ID_pointer)
Original file line number Diff line number Diff line change @@ -133,6 +133,9 @@ void cpp_typecheckt::convert_initializer(symbolt &symbol)
133
133
134
134
typecheck_expr (symbol.value );
135
135
136
+ if (symbol.value .type ().find (" to-member" ).is_not_nil ())
137
+ symbol.type .add (" to-member" ) = symbol.value .type ().find (" to-member" );
138
+
136
139
if (symbol.value .id ()==ID_initializer_list ||
137
140
symbol.value .id ()==ID_string_constant)
138
141
{
Original file line number Diff line number Diff line change @@ -309,11 +309,16 @@ exprt cpp_typecheck_resolvet::convert_identifier(
309
309
}
310
310
else
311
311
{
312
- // this has to be a method
312
+ // this has to be a method or form a pointer-to-member expression
313
313
if (identifier.is_method )
314
314
e=cpp_symbol_expr (cpp_typecheck.lookup (identifier.identifier ));
315
315
else
316
- e.make_nil ();
316
+ {
317
+ e.id (ID_ptrmember);
318
+ e.copy_to_operands (
319
+ exprt (" cpp-this" , pointer_type (compound_symbol.type )));
320
+ e.type () = type;
321
+ }
317
322
}
318
323
}
319
324
}
You can’t perform that action at this time.
0 commit comments