File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) {
113113}
114114
115115static void removeElseAndBrackets (DiagnosticBuilder &Diag, ASTContext &Context,
116- const Stmt *Else, SourceLocation ElseLoc) {
116+ const Stmt *Else, SourceLocation ElseLoc) {
117117 auto Remap = [&](SourceLocation Loc) {
118118 return Context.getSourceManager ().getExpansionLoc (Loc);
119119 };
@@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
172172 breakStmt ().bind (InterruptingStr), cxxThrowExpr ().bind (InterruptingStr)));
173173 Finder->addMatcher (
174174 compoundStmt (
175- forEach (ifStmt (unless (isConstexpr ()),
175+ forEach (ifStmt (unless (isConstexpr ()), unless ( isConsteval ()),
176176 hasThen (stmt (
177177 anyOf (InterruptsControlFlow,
178178 compoundStmt (has (InterruptsControlFlow))))),
Original file line number Diff line number Diff line change @@ -339,6 +339,10 @@ Changes in existing checks
339339 <clang-tidy/checks/readability/duplicate-include>` check by excluding include
340340 directives that form the filename using macro.
341341
342+ - Improved :doc: `readability-else-after-return
343+ <clang-tidy/checks/readability/else-after-return>` check to ignore
344+ `if consteval ` statements, for which the `else ` branch must not be removed.
345+
342346- Improved :doc: `readability-identifier-naming
343347 <clang-tidy/checks/readability/identifier-naming>` check in `GetConfigPerFile `
344348 mode by resolving symbolic links to header files. Fixed handling of Hungarian
Original file line number Diff line number Diff line change 1+ // RUN: %check_clang_tidy -std=c++23 %s readability-else-after-return %t
2+
3+ // Consteval if is an exception to the rule, we cannot remove the else.
4+ void f () {
5+ if (sizeof (int ) > 4 ) {
6+ return ;
7+ } else {
8+ return ;
9+ }
10+ // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return'
11+
12+ if consteval {
13+ return ;
14+ } else {
15+ return ;
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments