Skip to content

[clang] Improved isSimpleTypeSpecifier #79037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ class Sema final {

void DiagnoseUseOfUnimplementedSelectors();

bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
bool isSimpleTypeSpecifier(const Token &Tok) const;

ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
Scope *S, CXXScopeSpec *SS = nullptr,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
if (TryAnnotateTypeOrScopeToken())
return ExprError();

if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
if (!Actions.isSimpleTypeSpecifier(Tok))
// We are trying to parse a simple-type-specifier but might not get such
// a token after error recovery.
return ExprError();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseObjc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
tok::annot_cxxscope))
TryAnnotateTypeOrScopeToken();

if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) {
if (!Actions.isSimpleTypeSpecifier(Tok)) {
// objc-receiver:
// expression
// Make sure any typos in the receiver are corrected or diagnosed, so that
Expand Down
25 changes: 10 additions & 15 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ class TypeNameValidatorCCC final : public CorrectionCandidateCallback {
} // end anonymous namespace

/// Determine whether the token kind starts a simple-type-specifier.
bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
switch (Kind) {
// FIXME: Take into account the current language when deciding whether a
// token kind is a valid type specifier
bool Sema::isSimpleTypeSpecifier(const Token &Tok) const {
switch (Tok.getKind()) {
case tok::annot_typename:
case tok::annot_decltype:
case tok::annot_pack_indexing_type:
return true;

case tok::kw_short:
case tok::kw_long:
case tok::kw___int64:
Expand All @@ -150,31 +153,23 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
case tok::kw___ibm128:
case tok::kw_wchar_t:
case tok::kw_bool:
case tok::kw__Bool:
case tok::kw__Accum:
case tok::kw__Fract:
case tok::kw__Sat:
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
#include "clang/Basic/TransformTypeTraits.def"
case tok::kw___auto_type:
return true;

case tok::annot_typename:
case tok::kw_char16_t:
case tok::kw_char32_t:
case tok::kw_typeof:
case tok::annot_decltype:
case tok::annot_pack_indexing_type:
case tok::kw_decltype:
return getLangOpts().CPlusPlus;

case tok::kw_char8_t:
return getLangOpts().Char8;
return Tok.getIdentifierInfo()->isKeyword(getLangOpts());

default:
break;
return false;
}

return false;
}

namespace {
Expand Down