Skip to content

Commit 7460056

Browse files
authored
[ObjC] Stop hard-coding the list of keywords that are allowed in selectors (#138952)
The design intent is that ObjC selector pieces can be arbitrary keywords, including basic C keywords like `if`, and the grammar permits this and makes it unambiguous. Allow any token that has an identifier (except `__attribute__`) to be part of a selector. rdar://150383689
1 parent e9ce752 commit 7460056

File tree

2 files changed

+11
-72
lines changed

2 files changed

+11
-72
lines changed

clang/lib/Parse/ParseObjc.cpp

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,6 @@ Decl *Parser::ParseObjCMethodPrototype(tok::ObjCKeywordKind MethodImplKind,
10671067
IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
10681068

10691069
switch (Tok.getKind()) {
1070-
default:
1071-
return nullptr;
10721070
case tok::colon:
10731071
// Empty selector piece uses the location of the ':'.
10741072
SelectorLoc = Tok.getLocation();
@@ -1094,77 +1092,13 @@ IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
10941092
return nullptr;
10951093
}
10961094

1097-
case tok::identifier:
1098-
case tok::kw_asm:
1099-
case tok::kw_auto:
1100-
case tok::kw_bool:
1101-
case tok::kw_break:
1102-
case tok::kw_case:
1103-
case tok::kw_catch:
1104-
case tok::kw_char:
1105-
case tok::kw_class:
1106-
case tok::kw_const:
1107-
case tok::kw_const_cast:
1108-
case tok::kw_continue:
1109-
case tok::kw_default:
1110-
case tok::kw_delete:
1111-
case tok::kw_do:
1112-
case tok::kw_double:
1113-
case tok::kw_dynamic_cast:
1114-
case tok::kw_else:
1115-
case tok::kw_enum:
1116-
case tok::kw_explicit:
1117-
case tok::kw_export:
1118-
case tok::kw_extern:
1119-
case tok::kw_false:
1120-
case tok::kw_float:
1121-
case tok::kw_for:
1122-
case tok::kw_friend:
1123-
case tok::kw_goto:
1124-
case tok::kw_if:
1125-
case tok::kw_inline:
1126-
case tok::kw_int:
1127-
case tok::kw_long:
1128-
case tok::kw_mutable:
1129-
case tok::kw_namespace:
1130-
case tok::kw_new:
1131-
case tok::kw_operator:
1132-
case tok::kw_private:
1133-
case tok::kw_protected:
1134-
case tok::kw_public:
1135-
case tok::kw_register:
1136-
case tok::kw_reinterpret_cast:
1137-
case tok::kw_restrict:
1138-
case tok::kw_return:
1139-
case tok::kw_short:
1140-
case tok::kw_signed:
1141-
case tok::kw_sizeof:
1142-
case tok::kw_static:
1143-
case tok::kw_static_cast:
1144-
case tok::kw_struct:
1145-
case tok::kw_switch:
1146-
case tok::kw_template:
1147-
case tok::kw_this:
1148-
case tok::kw_throw:
1149-
case tok::kw_true:
1150-
case tok::kw_try:
1151-
case tok::kw_typedef:
1152-
case tok::kw_typeid:
1153-
case tok::kw_typename:
1154-
case tok::kw_typeof:
1155-
case tok::kw_union:
1156-
case tok::kw_unsigned:
1157-
case tok::kw_using:
1158-
case tok::kw_virtual:
1159-
case tok::kw_void:
1160-
case tok::kw_volatile:
1161-
case tok::kw_wchar_t:
1162-
case tok::kw_while:
1163-
case tok::kw__Bool:
1164-
case tok::kw__Complex:
1165-
case tok::kw___alignof:
1166-
case tok::kw___auto_type:
1095+
case tok::kw___attribute:
1096+
return nullptr;
1097+
1098+
default:
11671099
IdentifierInfo *II = Tok.getIdentifierInfo();
1100+
if (!II)
1101+
return nullptr;
11681102
SelectorLoc = ConsumeToken();
11691103
return II;
11701104
}

clang/test/SemaObjCXX/cxxoperator-selector.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ - (id) and{return 0; };
1919
- (id) xor{return 0; };
2020
- (id) or{return 0; };
2121

22+
- (void)decltype {}
23+
- (void)constexpr {}
24+
- (void)noexcept {}
25+
- (void)nullptr {}
26+
2227
- (void)dataSetForValuesBetween:(NSDate *)startDate and:(NSDate *)endDate { return; }
2328
@end

0 commit comments

Comments
 (0)