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.
This commit is contained in:
Richard Smith 2020-04-28 23:41:11 -07:00
parent c35f3f8679
commit 20df6038ee
6 changed files with 23 additions and 3 deletions

View File

@ -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
--------------------

View File

@ -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)

View File

@ -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;
}

View File

@ -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();

View File

@ -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(

View File

@ -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