Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -700,6 +700,9 @@ Improvements to Clang's diagnostics
return ptr + index < ptr; // warning
}

- 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 @@ -2222,8 +2222,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
Loading