aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard@metafoo.co.uk>2020-04-28 23:41:11 -0700
committerRichard Smith <richard@metafoo.co.uk>2020-04-28 23:49:35 -0700
commit20df6038ee76f110640fc7c5fa9b96b84e373932 (patch)
tree3bbbc4bd71df2a3f8a914c60eec987216e2bf7e8
parentc35f3f8679050df77a32512a73a94ba856190089 (diff)
downloadllvm-20df6038ee76f110640fc7c5fa9b96b84e373932.zip
llvm-20df6038ee76f110640fc7c5fa9b96b84e373932.tar.gz
llvm-20df6038ee76f110640fc7c5fa9b96b84e373932.tar.bz2
Make -fno-char8_t disable the char8_t keyword, even in C++20.
This fixes a regression introduced in r354736, and makes our behavior compatible with that of Clang 8 and GCC.
-rw-r--r--clang/docs/ReleaseNotes.rst3
-rw-r--r--clang/include/clang/Basic/TokenKinds.def3
-rw-r--r--clang/lib/Basic/IdentifierTable.cpp2
-rw-r--r--clang/lib/Format/Format.cpp1
-rw-r--r--clang/lib/Lex/Preprocessor.cpp4
-rw-r--r--clang/test/Lexer/char8_t.cpp13
6 files changed, 23 insertions, 3 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9c22117..a35c966 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -127,6 +127,9 @@ Modified Compiler Flags
``-f[no-]sanitize-recover=undefined,integer`` and is no longer deprecated.
- The argument to ``-f[no-]sanitize-trap=...`` is now optional and defaults to
``all``.
+- ``-fno-char8_t`` now disables the ``char8_t`` keyword, not just the use of
+ ``char8_t`` as the character type of ``u8`` literals. This restores the
+ Clang 8 behavior that regressed in Clang 9 and 10.
New Pragmas in Clang
--------------------
diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def
index 462e160..0705896 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -388,9 +388,10 @@ MODULES_KEYWORD(module)
MODULES_KEYWORD(import)
// C++20 keywords.
-CXX20_KEYWORD(char8_t , CHAR8SUPPORT)
CXX20_KEYWORD(consteval , 0)
CXX20_KEYWORD(constinit , 0)
+// Not a CXX20_KEYWORD because it is disabled by -fno-char8_t.
+KEYWORD(char8_t , CHAR8SUPPORT)
// C11 Extension
KEYWORD(_Float16 , KEYALL)
diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp
index e88d939..d7ef159 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -146,6 +146,8 @@ static KeywordStatus getKeywordStatus(const LangOptions &LangOpts,
if (LangOpts.Coroutines && (Flags & KEYCOROUTINES)) return KS_Enabled;
if (LangOpts.ModulesTS && (Flags & KEYMODULES)) return KS_Enabled;
if (LangOpts.CPlusPlus && (Flags & KEYALLCXX)) return KS_Future;
+ if (LangOpts.CPlusPlus && !LangOpts.CPlusPlus20 && (Flags & CHAR8SUPPORT))
+ return KS_Future;
return KS_Disabled;
}
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index eead2b4..737e502 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2622,6 +2622,7 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) {
LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
+ LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
LangOpts.LineComment = 1;
bool AlternativeOperators = Style.isCpp();
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 961b55c..105aa66 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -774,6 +774,10 @@ static diag::kind getFutureCompatDiagKind(const IdentifierInfo &II,
#define CXX20_KEYWORD(NAME, FLAGS) \
.Case(#NAME, diag::warn_cxx20_keyword)
#include "clang/Basic/TokenKinds.def"
+ // char8_t is not modeled as a CXX20_KEYWORD because it's not
+ // unconditionally enabled in C++20 mode. (It can be disabled
+ // by -fno-char8_t.)
+ .Case("char8_t", diag::warn_cxx20_keyword)
;
llvm_unreachable(
diff --git a/clang/test/Lexer/char8_t.cpp b/clang/test/Lexer/char8_t.cpp
index 20f820e..d65597c 100644
--- a/clang/test/Lexer/char8_t.cpp
+++ b/clang/test/Lexer/char8_t.cpp
@@ -1,5 +1,14 @@
-// RUN: %clang_cc1 -std=c++2a -verify %s
-// RUN: %clang_cc1 -std=c++2a -verify %s -fchar8_t
+// RUN: %clang_cc1 -std=c++20 -verify %s -DCHAR8_T
+// RUN: %clang_cc1 -std=c++20 -verify %s -fchar8_t -DCHAR8_T
+// RUN: %clang_cc1 -std=c++17 -verify %s -fchar8_t -DCHAR8_T
+
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s -fno-char8_t
+// RUN: %clang_cc1 -std=c++20 -verify %s -fno-char8_t
+
+#if defined(__cpp_char8_t) != defined(CHAR8_T)
+#error wrong setting for __cpp_char_t
+#endif
#if defined(__cpp_char8_t) && __is_identifier(char8_t)
#error char8_t is an identifier under -fchar8_t