File tree 3 files changed +64
-0
lines changed
3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -1626,6 +1626,27 @@ class cppfront
1626
1626
auto emit (qualified_id_node const & n)
1627
1627
-> void
1628
1628
{
1629
+ // Check for some incorrect uses of :: or .
1630
+ if (auto decl = sema.get_declaration_of (n.get_first_token (), true );
1631
+ decl && std::ssize (n.ids ) > 1
1632
+ )
1633
+ {
1634
+ assert (decl->declaration );
1635
+
1636
+ if (
1637
+ decl->declaration ->is_object ()
1638
+ && n.ids [1 ].scope_op
1639
+ && n.ids [1 ].scope_op ->type () == lexeme::Scope
1640
+ )
1641
+ {
1642
+ errors.emplace_back (
1643
+ n.position (),
1644
+ " use '" + decl->identifier ->to_string (true ) + " .' to refer to an object member"
1645
+ );
1646
+ return ;
1647
+ }
1648
+ }
1649
+
1629
1650
// Implicit "cpp2::" qualification of "unique.new" and "shared.new"
1630
1651
if (
1631
1652
n.ids .size () == 2
@@ -2536,6 +2557,27 @@ class cppfront
2536
2557
assert (n.expr );
2537
2558
last_postfix_expr_was_pointer = false ;
2538
2559
2560
+ // Check for some incorrect uses of :: or .
2561
+ if (auto decl = sema.get_declaration_of (n.get_first_token_ignoring_this (), true );
2562
+ decl && !n.ops .empty ()
2563
+ )
2564
+ {
2565
+ assert (decl->declaration );
2566
+
2567
+ if (
2568
+ decl->declaration ->is_type ()
2569
+ && n.ops [0 ].op
2570
+ && n.ops [0 ].op ->type () == lexeme::Dot
2571
+ )
2572
+ {
2573
+ errors.emplace_back (
2574
+ n.position (),
2575
+ " use '" + decl->identifier ->to_string (true ) + " ::' to refer to a type member"
2576
+ );
2577
+ return ;
2578
+ }
2579
+ }
2580
+
2539
2581
// For a 'move that' parameter, track the members we already moved from
2540
2582
// so we can diagnose attempts to move from the same member twice
2541
2583
if (
Original file line number Diff line number Diff line change @@ -636,6 +636,16 @@ struct qualified_id_node
636
636
return {};
637
637
}
638
638
639
+ auto get_first_token () const
640
+ -> token const *
641
+ {
642
+ assert (
643
+ !ids.empty ()
644
+ && ids.front ().id
645
+ );
646
+ return ids.front ().id ->get_token ();
647
+ }
648
+
639
649
auto position () const
640
650
-> source_position
641
651
{
Original file line number Diff line number Diff line change @@ -263,6 +263,18 @@ class sema
263
263
264
264
// Get the declaration of t within the same named function or beyond it
265
265
//
266
+ auto get_declaration_of (
267
+ token const * t,
268
+ bool look_beyond_current_function = false
269
+ )
270
+ -> declaration_sym const *
271
+ {
272
+ if (!t) {
273
+ return {};
274
+ }
275
+ return get_declaration_of (*t, look_beyond_current_function);
276
+ }
277
+
266
278
auto get_declaration_of (
267
279
token const & t,
268
280
bool look_beyond_current_function = false
You can’t perform that action at this time.
0 commit comments