@@ -6109,6 +6109,15 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) {
61096109 SM.isInSystemMacro(D->getLocation());
61106110}
61116111
6112+ constexpr unsigned countCPlusPlusKeywords() {
6113+ unsigned Ret = 0;
6114+ #define MODULES_KEYWORD(NAME)
6115+ #define KEYWORD(NAME, FLAGS) ++Ret;
6116+ #define CXX_KEYWORD_OPERATOR(NAME, TOK) ++Ret;
6117+ #include "clang/Basic/TokenKinds.def"
6118+ return Ret;
6119+ }
6120+
61126121static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) {
61136122 if (!II)
61146123 return false;
@@ -6119,16 +6128,18 @@ static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) {
61196128 // or not. Note, this treats all keywords as being enabled, regardless of the
61206129 // setting of other language options. It intentionally disables the modules
61216130 // keywords because those are conditional keywords, so may be safe to use.
6122- static llvm::SmallVector<uintptr_t, 48> Keywords;
6123- if (Keywords.empty()) {
6131+ static std::array<uintptr_t, countCPlusPlusKeywords()> Keywords = {};
6132+ if (!Keywords[0]) {
6133+ unsigned Idx = 0;
61246134#define MODULES_KEYWORD(NAME)
61256135#define KEYWORD(NAME, FLAGS) \
6126- Keywords.push_back( reinterpret_cast<uint64_t>( \
6127- &S.getPreprocessor().getIdentifierTable().get(#NAME))) ;
6136+ Keywords[Idx++] = reinterpret_cast<uint64_t>( \
6137+ &S.getPreprocessor().getIdentifierTable().get(#NAME));
61286138#define CXX_KEYWORD_OPERATOR(NAME, TOK) \
6129- Keywords.push_back( reinterpret_cast<uint64_t>( \
6130- &S.getPreprocessor().getIdentifierTable().get(#NAME))) ;
6139+ Keywords[Idx++] = reinterpret_cast<uint64_t>( \
6140+ &S.getPreprocessor().getIdentifierTable().get(#NAME));
61316141#include "clang/Basic/TokenKinds.def"
6142+ assert(Idx == Keywords.size() && "expected to fill every member!");
61326143 llvm::sort(Keywords);
61336144 }
61346145
0 commit comments