clang-tools 24.0.0git
clang::tidy::modernize::UseToUnderlyingCheck Class Reference

Finds casts from a scoped enumeration to its underlying integer type and replaces them with a call to std::to_underlying (C++23). More...

#include <UseToUnderlyingCheck.h>

Inheritance diagram for clang::tidy::modernize::UseToUnderlyingCheck:
[legend]

Public Types

enum class  ImpreciseCastsKind { Ignore , Warn , PreserveType , UseUnderlyingType }
 How to treat an imprecise cast, i.e. More...

Public Member Functions

 UseToUnderlyingCheck (StringRef Name, ClangTidyContext *Context)
bool isLanguageVersionSupported (const LangOptions &LangOpts) const override
void registerPPCallbacks (const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
void storeOptions (ClangTidyOptions::OptionMap &Opts) override
void registerMatchers (ast_matchers::MatchFinder *Finder) override
void check (const ast_matchers::MatchFinder::MatchResult &Result) override
std::optional< TraversalKind > getCheckTraversalKind () const override

Detailed Description

Finds casts from a scoped enumeration to its underlying integer type and replaces them with a call to std::to_underlying (C++23).

For the user-facing documentation see: https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-to-underlying.html

Definition at line 23 of file UseToUnderlyingCheck.h.

Member Enumeration Documentation

◆ ImpreciseCastsKind

How to treat an imprecise cast, i.e.

a cast whose destination type is an integer type other than the enumeration's underlying type.

Enumerator
Ignore 

Do not diagnose imprecise casts.

Warn 

Diagnose imprecise casts but do not offer a fix-it.

PreserveType 

Wrap the operand in a call to the replacement function, preserving the original destination type.

UseUnderlyingType 

Replace the whole cast with a call to the replacement function, changing the resulting type to the underlying type.

Definition at line 27 of file UseToUnderlyingCheck.h.

Constructor & Destructor Documentation

◆ UseToUnderlyingCheck()

clang::tidy::modernize::UseToUnderlyingCheck::UseToUnderlyingCheck ( StringRef Name,
ClangTidyContext * Context )

Definition at line 39 of file UseToUnderlyingCheck.cpp.

References Warn.

Member Function Documentation

◆ check()

void clang::tidy::modernize::UseToUnderlyingCheck::check ( const ast_matchers::MatchFinder::MatchResult & Result)
override

Definition at line 99 of file UseToUnderlyingCheck.cpp.

References Ignore, UseUnderlyingType, and Warn.

◆ getCheckTraversalKind()

std::optional< TraversalKind > clang::tidy::modernize::UseToUnderlyingCheck::getCheckTraversalKind ( ) const
inlineoverride

Definition at line 47 of file UseToUnderlyingCheck.h.

◆ isLanguageVersionSupported()

bool clang::tidy::modernize::UseToUnderlyingCheck::isLanguageVersionSupported ( const LangOptions & LangOpts) const
override

Definition at line 59 of file UseToUnderlyingCheck.cpp.

◆ registerMatchers()

void clang::tidy::modernize::UseToUnderlyingCheck::registerMatchers ( ast_matchers::MatchFinder * Finder)
override

Definition at line 82 of file UseToUnderlyingCheck.cpp.

◆ registerPPCallbacks()

void clang::tidy::modernize::UseToUnderlyingCheck::registerPPCallbacks ( const SourceManager & SM,
Preprocessor * PP,
Preprocessor * ModuleExpanderPP )
override

Definition at line 69 of file UseToUnderlyingCheck.cpp.

◆ storeOptions()

void clang::tidy::modernize::UseToUnderlyingCheck::storeOptions ( ClangTidyOptions::OptionMap & Opts)
override

Definition at line 75 of file UseToUnderlyingCheck.cpp.


The documentation for this class was generated from the following files: