Skip to content

[clang][ObjectiveC] Fix Parsing the :: Optional Scope Specifier (#119908) #9782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,9 @@ Improvements to Clang's diagnostics
- Clang now diagnoses dangling references to fields of temporary objects. Fixes #GH81589.


- Fixed a bug where Clang hung on an unsupported optional scope specifier ``::`` when parsing
Objective-C. Clang now emits a diagnostic message instead of hanging.

Improvements to Clang's time-trace
----------------------------------

Expand Down
9 changes: 8 additions & 1 deletion clang/lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2231,8 +2231,15 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
}
}

if (SS.isEmpty())
if (SS.isEmpty()) {
if (getLangOpts().ObjC && !getLangOpts().CPlusPlus &&
Tok.is(tok::coloncolon)) {
// ObjectiveC does not allow :: as as a scope token.
Diag(ConsumeToken(), diag::err_expected_type);
return true;
}
return false;
}

// A C++ scope specifier that isn't followed by a typename.
AnnotateScopeToken(SS, IsNewScope);
Expand Down
19 changes: 19 additions & 0 deletions clang/test/Parser/objc-coloncolon.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %clang_cc1 -x objective-c -fsyntax-only -Wno-objc-root-class -verify %s

int GV = 42;

@interface A
+ (int) getGV;
- (instancetype)init:(::A *) foo; // expected-error {{expected a type}}
@end

@implementation A
- (void)performSelector:(SEL)selector {}
- (void)double:(int)firstArg :(int)secondArg colon:(int)thirdArg {}
- (void)test {
// The `::` below should not trigger an error.
[self performSelector:@selector(double::colon:)];
}
+ (int) getGV { return ::GV; } // expected-error {{expected a type}}
- (instancetype)init:(::A *) foo { return self; } // expected-error {{expected a type}}
@end
9 changes: 9 additions & 0 deletions clang/test/Parser/objcxx-coloncolon.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Test to make sure the parser does not get stuck on the optional
// scope specifier on the type B.
// RUN: %clang_cc1 -fsyntax-only %s

class B;

@interface A
- (void) init:(::B *) foo;
@end