[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
JoverZhang wrote: > Please add an entry to the release notes here: > > https://github.com/llvm/llvm-project/blob/502e77df1fc4aa859db6709e14e93af6207e4dc4/clang-tools-extra/docs/ReleaseNotes.rst?plain=1#L176 > > > do note that the entries are sorted by their check names. > Otherwise looks good. Okay, I added. https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
https://github.com/JoverZhang updated https://github.com/llvm/llvm-project/pull/91588 >From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Thu, 9 May 2024 20:56:51 +0800 Subject: [PATCH 1/3] [clang-tidy] Ignore `if consteval` in else-after-return --- .../clang-tidy/readability/ElseAfterReturnCheck.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 1e85caf688355..3ee09b2e6442c 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } + if (If->isConsteval()) { +return; + } + DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); >From 2a394ddde92b23f9407ca74e597b569bb01da35f Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Sun, 12 May 2024 22:40:14 +0800 Subject: [PATCH 2/3] Add test case --- .../readability/ElseAfterReturnCheck.cpp| 8 ++-- .../else-after-return-if-consteval.cpp | 17 + 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 3ee09b2e6442c..2b185e7594add 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) { } static void removeElseAndBrackets(DiagnosticBuilder , ASTContext , - const Stmt *Else, SourceLocation ElseLoc) { + const Stmt *Else, SourceLocation ElseLoc) { auto Remap = [&](SourceLocation Loc) { return Context.getSourceManager().getExpansionLoc(Loc); }; @@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) { breakStmt().bind(InterruptingStr), cxxThrowExpr().bind(InterruptingStr))); Finder->addMatcher( compoundStmt( - forEach(ifStmt(unless(isConstexpr()), + forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()), hasThen(stmt( anyOf(InterruptsControlFlow, compoundStmt(has(InterruptsControlFlow), @@ -317,10 +317,6 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } - if (If->isConsteval()) { -return; - } - DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp new file mode 100644 index 0..6235d8623ca7b --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t + +// Consteval if is an exception to the rule, we cannot remove the else. +void f() { + if (sizeof(int) > 4) { +return; + } else { +return; + } + // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return' + + if consteval { +return; + } else { +return; + } +} >From 1e88302ea84491967ad61e6c32ad87c15e02f3bf Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Mon, 13 May 2024 10:09:04 +0800 Subject: [PATCH 3/3] Add a release note --- clang-tools-extra/docs/ReleaseNotes.rst | 4 .../checkers/readability/else-after-return-if-consteval.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6a2b8d3b6ded6..aba5102b32efb 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -337,6 +337,10 @@ Changes in existing checks ` check by excluding include directives that form the filename using macro. +- Improved :doc:`readability-else-after-return + ` check to ignore + `consteval if` condition, where need to retain the else statement. + - Improved :doc:`readability-identifier-naming ` check in `GetConfigPerFile` mode by resolving symbolic links to header files. Fixed handling of Hungarian diff --git
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
https://github.com/JoverZhang updated https://github.com/llvm/llvm-project/pull/91588 >From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Thu, 9 May 2024 20:56:51 +0800 Subject: [PATCH 1/3] [clang-tidy] Ignore `if consteval` in else-after-return --- .../clang-tidy/readability/ElseAfterReturnCheck.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 1e85caf688355..3ee09b2e6442c 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } + if (If->isConsteval()) { +return; + } + DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); >From 2a394ddde92b23f9407ca74e597b569bb01da35f Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Sun, 12 May 2024 22:40:14 +0800 Subject: [PATCH 2/3] Add test case --- .../readability/ElseAfterReturnCheck.cpp| 8 ++-- .../else-after-return-if-consteval.cpp | 17 + 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 3ee09b2e6442c..2b185e7594add 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) { } static void removeElseAndBrackets(DiagnosticBuilder , ASTContext , - const Stmt *Else, SourceLocation ElseLoc) { + const Stmt *Else, SourceLocation ElseLoc) { auto Remap = [&](SourceLocation Loc) { return Context.getSourceManager().getExpansionLoc(Loc); }; @@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) { breakStmt().bind(InterruptingStr), cxxThrowExpr().bind(InterruptingStr))); Finder->addMatcher( compoundStmt( - forEach(ifStmt(unless(isConstexpr()), + forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()), hasThen(stmt( anyOf(InterruptsControlFlow, compoundStmt(has(InterruptsControlFlow), @@ -317,10 +317,6 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } - if (If->isConsteval()) { -return; - } - DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp new file mode 100644 index 0..6235d8623ca7b --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t + +// Consteval if is an exception to the rule, we cannot remove the else. +void f() { + if (sizeof(int) > 4) { +return; + } else { +return; + } + // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return' + + if consteval { +return; + } else { +return; + } +} >From 1e88302ea84491967ad61e6c32ad87c15e02f3bf Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Mon, 13 May 2024 10:09:04 +0800 Subject: [PATCH 3/3] Add a release note --- clang-tools-extra/docs/ReleaseNotes.rst | 4 .../checkers/readability/else-after-return-if-consteval.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6a2b8d3b6ded6..aba5102b32efb 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -337,6 +337,10 @@ Changes in existing checks ` check by excluding include directives that form the filename using macro. +- Improved :doc:`readability-else-after-return + ` check to ignore + `consteval if` condition, where need to retain the else statement. + - Improved :doc:`readability-identifier-naming ` check in `GetConfigPerFile` mode by resolving symbolic links to header files. Fixed handling of Hungarian diff --git
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
@@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t 5chmidti wrote: While `consteval` was added in C++20, `if consteval` is a C++23 feature. Please use `-std=c++23` https://en.cppreference.com/w/cpp/language/if#Consteval_if https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
https://github.com/5chmidti commented: Please add an entry to the release notes here: https://github.com/llvm/llvm-project/blob/502e77df1fc4aa859db6709e14e93af6207e4dc4/clang-tools-extra/docs/ReleaseNotes.rst?plain=1#L176 do note that the entries are sorted by their check names. Otherwise looks good. https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Jover (JoverZhang) Changes Fixes #91561. --- Full diff: https://github.com/llvm/llvm-project/pull/91588.diff 2 Files Affected: - (modified) clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp (+2-2) - (added) clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp (+17) ``diff diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 1e85caf688355..2b185e7594add 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) { } static void removeElseAndBrackets(DiagnosticBuilder , ASTContext , - const Stmt *Else, SourceLocation ElseLoc) { + const Stmt *Else, SourceLocation ElseLoc) { auto Remap = [&](SourceLocation Loc) { return Context.getSourceManager().getExpansionLoc(Loc); }; @@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) { breakStmt().bind(InterruptingStr), cxxThrowExpr().bind(InterruptingStr))); Finder->addMatcher( compoundStmt( - forEach(ifStmt(unless(isConstexpr()), + forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()), hasThen(stmt( anyOf(InterruptsControlFlow, compoundStmt(has(InterruptsControlFlow), diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp new file mode 100644 index 0..6235d8623ca7b --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t + +// Consteval if is an exception to the rule, we cannot remove the else. +void f() { + if (sizeof(int) > 4) { +return; + } else { +return; + } + // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return' + + if consteval { +return; + } else { +return; + } +} `` https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
https://github.com/JoverZhang ready_for_review https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
JoverZhang wrote: > Thanks for your patch! Would you be able to add a test case for this please? Yes, thanks. I added a test case. https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
https://github.com/JoverZhang updated https://github.com/llvm/llvm-project/pull/91588 >From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Thu, 9 May 2024 20:56:51 +0800 Subject: [PATCH 1/2] [clang-tidy] Ignore `if consteval` in else-after-return --- .../clang-tidy/readability/ElseAfterReturnCheck.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 1e85caf688355..3ee09b2e6442c 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } + if (If->isConsteval()) { +return; + } + DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); >From 2a394ddde92b23f9407ca74e597b569bb01da35f Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Sun, 12 May 2024 22:40:14 +0800 Subject: [PATCH 2/2] Add test case --- .../readability/ElseAfterReturnCheck.cpp| 8 ++-- .../else-after-return-if-consteval.cpp | 17 + 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 3ee09b2e6442c..2b185e7594add 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) { } static void removeElseAndBrackets(DiagnosticBuilder , ASTContext , - const Stmt *Else, SourceLocation ElseLoc) { + const Stmt *Else, SourceLocation ElseLoc) { auto Remap = [&](SourceLocation Loc) { return Context.getSourceManager().getExpansionLoc(Loc); }; @@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) { breakStmt().bind(InterruptingStr), cxxThrowExpr().bind(InterruptingStr))); Finder->addMatcher( compoundStmt( - forEach(ifStmt(unless(isConstexpr()), + forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()), hasThen(stmt( anyOf(InterruptsControlFlow, compoundStmt(has(InterruptsControlFlow), @@ -317,10 +317,6 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } - if (If->isConsteval()) { -return; - } - DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp new file mode 100644 index 0..6235d8623ca7b --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t + +// Consteval if is an exception to the rule, we cannot remove the else. +void f() { + if (sizeof(int) > 4) { +return; + } else { +return; + } + // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return' + + if consteval { +return; + } else { +return; + } +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
https://github.com/JoverZhang updated https://github.com/llvm/llvm-project/pull/91588 >From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Thu, 9 May 2024 20:56:51 +0800 Subject: [PATCH 1/2] [clang-tidy] Ignore `if consteval` in else-after-return --- .../clang-tidy/readability/ElseAfterReturnCheck.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 1e85caf688355..3ee09b2e6442c 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } + if (If->isConsteval()) { +return; + } + DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); >From 2a394ddde92b23f9407ca74e597b569bb01da35f Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Sun, 12 May 2024 22:40:14 +0800 Subject: [PATCH 2/2] Add test case --- .../readability/ElseAfterReturnCheck.cpp| 8 ++-- .../else-after-return-if-consteval.cpp | 17 + 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 3ee09b2e6442c..2b185e7594add 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) { } static void removeElseAndBrackets(DiagnosticBuilder , ASTContext , - const Stmt *Else, SourceLocation ElseLoc) { + const Stmt *Else, SourceLocation ElseLoc) { auto Remap = [&](SourceLocation Loc) { return Context.getSourceManager().getExpansionLoc(Loc); }; @@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) { breakStmt().bind(InterruptingStr), cxxThrowExpr().bind(InterruptingStr))); Finder->addMatcher( compoundStmt( - forEach(ifStmt(unless(isConstexpr()), + forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()), hasThen(stmt( anyOf(InterruptsControlFlow, compoundStmt(has(InterruptsControlFlow), @@ -317,10 +317,6 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } - if (If->isConsteval()) { -return; - } - DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp new file mode 100644 index 0..6235d8623ca7b --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t + +// Consteval if is an exception to the rule, we cannot remove the else. +void f() { + if (sizeof(int) > 4) { +return; + } else { +return; + } + // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return' + + if consteval { +return; + } else { +return; + } +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
cjdb wrote: Thanks for your patch! Would you be able to add a test case for this please? https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/91588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)
https://github.com/JoverZhang created https://github.com/llvm/llvm-project/pull/91588 Fixes #91561. >From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001 From: Jover Zhang Date: Thu, 9 May 2024 20:56:51 +0800 Subject: [PATCH] [clang-tidy] Ignore `if consteval` in else-after-return --- .../clang-tidy/readability/ElseAfterReturnCheck.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp index 1e85caf688355..3ee09b2e6442c 100644 --- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult ) { return; } + if (If->isConsteval()) { +return; + } + DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage) << ControlFlowInterruptor << SourceRange(ElseLoc); removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits