File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -1626,6 +1626,27 @@ class cppfront
16261626 auto emit (qualified_id_node const & n)
16271627 -> void
16281628 {
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+
16291650 // Implicit "cpp2::" qualification of "unique.new" and "shared.new"
16301651 if (
16311652 n.ids .size () == 2
@@ -2536,6 +2557,27 @@ class cppfront
25362557 assert (n.expr );
25372558 last_postfix_expr_was_pointer = false ;
25382559
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+
25392581 // For a 'move that' parameter, track the members we already moved from
25402582 // so we can diagnose attempts to move from the same member twice
25412583 if (
Original file line number Diff line number Diff line change @@ -636,6 +636,16 @@ struct qualified_id_node
636636 return {};
637637 }
638638
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+
639649 auto position () const
640650 -> source_position
641651 {
Original file line number Diff line number Diff line change @@ -263,6 +263,18 @@ class sema
263263
264264 // Get the declaration of t within the same named function or beyond it
265265 //
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+
266278 auto get_declaration_of (
267279 token const & t,
268280 bool look_beyond_current_function = false
You can’t perform that action at this time.
0 commit comments