Skip to content

Commit f0fad9f

Browse files
authored
Revert "[clang-tidy] fix misc-const-correctness to work with function-try-blocks" (#100069)
Reverts #99925
1 parent 0a6233a commit f0fad9f

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
9393
// shall be run.
9494
const auto FunctionScope =
9595
functionDecl(
96-
hasBody(stmt(forEachDescendant(
97-
declStmt(containsAnyDeclaration(
98-
LocalValDecl.bind("local-value")),
99-
unless(has(decompositionDecl())))
100-
.bind("decl-stmt")))
101-
.bind("scope")))
96+
hasBody(
97+
compoundStmt(forEachDescendant(
98+
declStmt(containsAnyDeclaration(
99+
LocalValDecl.bind("local-value")),
100+
unless(has(decompositionDecl())))
101+
.bind("decl-stmt")))
102+
.bind("scope")))
102103
.bind("function-decl");
103104

104105
Finder->addMatcher(FunctionScope, this);
@@ -108,7 +109,7 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
108109
enum class VariableCategory { Value, Reference, Pointer };
109110

110111
void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
111-
const auto *LocalScope = Result.Nodes.getNodeAs<Stmt>("scope");
112+
const auto *LocalScope = Result.Nodes.getNodeAs<CompoundStmt>("scope");
112113
const auto *Variable = Result.Nodes.getNodeAs<VarDecl>("local-value");
113114
const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("function-decl");
114115

@@ -197,7 +198,7 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
197198
}
198199
}
199200

200-
void ConstCorrectnessCheck::registerScope(const Stmt *LocalScope,
201+
void ConstCorrectnessCheck::registerScope(const CompoundStmt *LocalScope,
201202
ASTContext *Context) {
202203
auto &Analyzer = ScopesCache[LocalScope];
203204
if (!Analyzer)

clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
3232
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3333

3434
private:
35-
void registerScope(const Stmt *LocalScope, ASTContext *Context);
35+
void registerScope(const CompoundStmt *LocalScope, ASTContext *Context);
3636

3737
using MutationAnalyzer = std::unique_ptr<ExprMutationAnalyzer>;
38-
llvm::DenseMap<const Stmt *, MutationAnalyzer> ScopesCache;
38+
llvm::DenseMap<const CompoundStmt *, MutationAnalyzer> ScopesCache;
3939
llvm::DenseSet<SourceLocation> TemplateDiagnosticsCache;
4040

4141
const bool AnalyzeValues;

clang-tools-extra/docs/ReleaseNotes.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ Changes in existing checks
381381
- Improved :doc:`misc-const-correctness
382382
<clang-tidy/checks/misc/const-correctness>` check by avoiding infinite recursion
383383
for recursive functions with forwarding reference parameters and reference
384-
variables which refer to themselves. Also adapted the check to work with
385-
function-try-blocks.
384+
variables which refer to themselves.
386385

387386
- Improved :doc:`misc-definitions-in-headers
388387
<clang-tidy/checks/misc/definitions-in-headers>` check by replacing the local

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ void some_function(double np_arg0, wchar_t np_arg1) {
5656
np_local6--;
5757
}
5858

59-
int function_try_block() try {
60-
int p_local0 = 0;
61-
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
62-
// CHECK-FIXES: int const p_local0
63-
return p_local0;
64-
} catch (...) {
65-
return 0;
66-
}
67-
6859
void nested_scopes() {
6960
int p_local0 = 2;
7061
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'

0 commit comments

Comments
 (0)