@@ -1568,6 +1568,37 @@ class cppfront
1568
1568
if (!decl || !decl->declaration )
1569
1569
return addr_cnt > deref_cnt;
1570
1570
1571
+ // if it is a function check if it returns pointer type
1572
+ if (auto * fun = std::get_if<declaration_node::function>(&decl->declaration ->type )) {
1573
+ if (auto * ret_id_expr = std::get_if<function_type_node::id>(&(*fun)->returns )) {
1574
+ if (auto * unqual = std::get_if<id_expression_node::unqualified>(&(*ret_id_expr)->id )){
1575
+ return is_it_pointer_declaration (*unqual, deref_cnt, addr_cnt);
1576
+ }
1577
+ }
1578
+ }
1579
+
1580
+ // if it is an object declaration check if we declare an pointer type
1581
+ if (auto * obj_id_expr = std::get_if<declaration_node::object>(&decl->declaration ->type )) {
1582
+ if (auto * unqual = std::get_if<id_expression_node::unqualified>(&(*obj_id_expr)->id )){
1583
+ return is_it_pointer_declaration (*unqual, deref_cnt, addr_cnt);
1584
+ }
1585
+ }
1586
+
1587
+ // if we initialize an object with a function check if it is initialized with a pointer type
1588
+ if (decl->initializer && decl->initializer ->suspicious_initialization ) {
1589
+ auto init_decl = sema.get_declaration_of (*decl->initializer ->suspicious_initialization , true );
1590
+ if (init_decl && init_decl->declaration ) {
1591
+ if (auto * fun = std::get_if<declaration_node::function>(&init_decl->declaration ->type )) {
1592
+ if (auto * ret_id_expr = std::get_if<function_type_node::id>(&(*fun)->returns )) {
1593
+ if (auto * unqual = std::get_if<id_expression_node::unqualified>(&(*ret_id_expr)->id )){
1594
+ return is_it_pointer_declaration (*unqual, deref_cnt, addr_cnt);
1595
+ }
1596
+ }
1597
+ }
1598
+ }
1599
+ }
1600
+
1601
+ // deduce if it is a pointer type based on number of dereferences and address of operations
1571
1602
if (decl->declaration ->dereference ) {
1572
1603
auto deref = sema.get_declaration_of (*decl->declaration ->dereference , true );
1573
1604
assert (deref && deref->declaration );
@@ -1604,18 +1635,9 @@ class cppfront
1604
1635
assert (unqual);
1605
1636
auto decl = sema.get_declaration_of (*unqual->identifier , true );
1606
1637
1607
- bool is_pointer = false ;
1608
- if (decl && decl->declaration ) {
1609
- if (auto * obj_id_expr = std::get_if<declaration_node::object>(&decl->declaration ->type )) {
1610
- if (auto * unqual = std::get_if<id_expression_node::unqualified>(&(*obj_id_expr)->id )){
1611
- is_pointer = !(*unqual)->pointer_declarators .empty ();
1612
- }
1613
- }
1614
- }
1615
-
1616
1638
// if initialized by something suspicious (that we have no information about) we need to add cpp1 safety checks
1617
1639
add_safetycheck = !decl && needs_safetycheck;
1618
- if (is_it_pointer_declaration (unqual) || !unqual-> pointer_declarators . empty () || is_pointer ) {
1640
+ if (is_it_pointer_declaration (unqual)) {
1619
1641
if (n.ops .empty ()) {
1620
1642
last_postfix_expr_was_pointer = true ;
1621
1643
}
0 commit comments