clang-tools 22.0.0git
clang::tidy::readability::BracesAroundStatementsCheck Class Reference

Checks that bodies of if statements and loops (for, range-for, do-while, and while) are inside braces. More...

#include <BracesAroundStatementsCheck.h>

Inheritance diagram for clang::tidy::readability::BracesAroundStatementsCheck:
[legend]

Public Member Functions

 BracesAroundStatementsCheck (StringRef Name, ClangTidyContext *Context)
void storeOptions (ClangTidyOptions::OptionMap &Opts) override
void registerMatchers (ast_matchers::MatchFinder *Finder) override
void check (const ast_matchers::MatchFinder::MatchResult &Result) override
void onEndOfTranslationUnit () override

Detailed Description

Checks that bodies of if statements and loops (for, range-for, do-while, and while) are inside braces.

Before:

if (condition)
statement;

After:

if (condition) {
statement;
}

Additionally, one can define an option ShortStatementLines defining the minimal number of lines that the statement should have in order to trigger this check.

The number of lines is counted from the end of condition or initial keyword (do/else) until the last line of the inner statement. Default value 0 means that braces will be added to all statements (not having them already).

Definition at line 41 of file BracesAroundStatementsCheck.h.

Constructor & Destructor Documentation

◆ BracesAroundStatementsCheck()

clang::tidy::readability::BracesAroundStatementsCheck::BracesAroundStatementsCheck ( StringRef Name,
ClangTidyContext * Context )

Definition at line 50 of file BracesAroundStatementsCheck.cpp.

Member Function Documentation

◆ check()

void clang::tidy::readability::BracesAroundStatementsCheck::check ( const ast_matchers::MatchFinder::MatchResult & Result)
override

Definition at line 69 of file BracesAroundStatementsCheck.cpp.

◆ onEndOfTranslationUnit()

void clang::tidy::readability::BracesAroundStatementsCheck::onEndOfTranslationUnit ( )
override

Definition at line 167 of file BracesAroundStatementsCheck.cpp.

◆ registerMatchers()

void clang::tidy::readability::BracesAroundStatementsCheck::registerMatchers ( ast_matchers::MatchFinder * Finder)
override

Definition at line 61 of file BracesAroundStatementsCheck.cpp.

◆ storeOptions()

void clang::tidy::readability::BracesAroundStatementsCheck::storeOptions ( ClangTidyOptions::OptionMap & Opts)
override

Definition at line 56 of file BracesAroundStatementsCheck.cpp.


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