Author: Richard Smith Date: 2020-04-28T23:49:35-07:00 New Revision: 20df6038ee76f110640fc7c5fa9b96b84e373932
URL: https://github.com/llvm/llvm-project/commit/20df6038ee76f110640fc7c5fa9b96b84e373932 DIFF: https://github.com/llvm/llvm-project/commit/20df6038ee76f110640fc7c5fa9b96b84e373932.diff LOG: 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. Added: Modified: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/TokenKinds.def clang/lib/Basic/IdentifierTable.cpp clang/lib/Format/Format.cpp clang/lib/Lex/Preprocessor.cpp clang/test/Lexer/char8_t.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c2211780b77..a35c966a8b4f 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 462e160b1351..07058962fc85 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 e88d93993294..d7ef159743b0 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 eead2b4a520a..737e5028bf0b 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 961b55c9387d..105aa6683c8b 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 20f820e24015..d65597c68d8b 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits