Skip to content

Commit f00bd69

Browse files
committed
Remove support for ObjC, update release note
1 parent 082d94c commit f00bd69

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ C Language Changes
155155
diagnoses implicit conversion from ``void *`` to another pointer type as
156156
being incompatible with C++. (#GH17792)
157157
- Added ``-Wc++-keyword``, grouped under ``-Wc++-compat``, which diagnoses when
158-
a C++ keyword is used as an identifier in C. Partially addresses #GH21898.
158+
a C++ keyword is used as an identifier in C. (#GH21898)
159159
- Added ``-Wc++-hidden-decl``, grouped under ``-Wc++-compat``, which diagnoses
160160
use of tag types which are visible in C but not visible in C++ due to scoping
161161
rules. e.g.,

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,12 @@ static void AddKeyword(StringRef Keyword,
287287
// Don't add this keyword if disabled in this language and isn't otherwise
288288
// special.
289289
if (AddResult == KS_Disabled) {
290-
if (IsKeywordInCpp(Flags))
290+
// We do not consider any identifiers to be C++ keywords when in
291+
// Objective-C because @ effectively introduces a custom grammar where C++
292+
// keywords can be used (and similar for selectors). We could enable this
293+
// for Objective-C, but it would require more logic to ensure we do not
294+
// issue compatibility diagnostics in these cases.
295+
if (!LangOpts.ObjC && IsKeywordInCpp(Flags))
291296
MarkIdentifierAsKeywordInCpp(Table, Keyword);
292297
return;
293298
}

clang/lib/Lex/Preprocessor.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -836,23 +836,8 @@ bool Preprocessor::HandleIdentifier(Token &Identifier) {
836836

837837
// If this identifier would be a keyword in C++, diagnose as a compatibility
838838
// issue.
839-
if (II.IsKeywordInCPlusPlus() && !DisableMacroExpansion) {
840-
// Objective-C is special in that something like @class is two tokens,
841-
// where 'class' is an identifier. We don't want to diagnose @class as
842-
// using an identifier reserved in C++, but we do still want to diagnose
843-
// something like 'int class;'. In Objective-C, @ basically introduces an
844-
// entirely new grammar, so no identier should be flagged as reserved.
845-
bool Diagnose = true;
846-
if (getLangOpts().ObjC) {
847-
std::optional<Token> PrevTok =
848-
Lexer::findPreviousToken(Identifier.getLocation(), getSourceManager(),
849-
getLangOpts(), /*IncludeComments=*/false);
850-
Diagnose = !PrevTok || !PrevTok->is(tok::at);
851-
}
852-
853-
if (Diagnose)
854-
Diag(Identifier, diag::warn_pp_identifier_is_cpp_keyword) << &II;
855-
}
839+
if (II.IsKeywordInCPlusPlus() && !DisableMacroExpansion)
840+
Diag(Identifier, diag::warn_pp_identifier_is_cpp_keyword) << &II;
856841

857842
// If this is an extension token, diagnose its use.
858843
// We avoid diagnosing tokens that originate from macro definitions.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -Wc++-keyword %s
2+
// expected-no-diagnostics
23

3-
// Show that @class is not diagnosed as use of a C++ keyword in Objective-C,
4-
// but that other uses of class are diagnosed.
4+
// Show that we do not diagnose any C++ keywords in Objective-C.
55

66
@class Foo; // Okay, Objective-C @ keyword, not a regular identifier
77

8-
int class = 12; // expected-warning {{identifier 'class' conflicts with a C++ keyword}}
8+
// FIXME: it would be nice to diagnose this, but it is intentionally allowed
9+
// due to @ and selectors allowing C++ keywords in ways that are supposed to be
10+
// contextually compatible with C++.
11+
int class = 12;
912

0 commit comments

Comments
 (0)