[clang-tools-extra] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-13 Thread Danny Mösch via cfe-commits

SimplyDanny wrote:

Thank you, @JoverZhang!

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] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-13 Thread via cfe-commits

github-actions[bot] wrote:



@JoverZhang Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-13 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny closed 
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] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-13 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


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] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-13 Thread via cfe-commits

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/4] [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/4] 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/4] 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] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-13 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny approved this pull request.


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] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-13 Thread Danny Mösch via cfe-commits


@@ -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.

SimplyDanny wrote:

```suggestion
  `if consteval` statements, for which the `else` branch must not be removed.
```

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] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-13 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.


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] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

https://github.com/JoverZhang 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