================
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "RedundantLambdaParenthesesCheck.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+AST_MATCHER(LambdaExpr, hasRedundantParens) {
+  return Node.hasExplicitParameters() &&
+         Node.getCallOperator()->getNumParams() == 0;
+}
+
+} // namespace
+
+void RedundantLambdaParenthesesCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(lambdaExpr(hasRedundantParens()).bind("lambda"), this);
+}
+
+void RedundantLambdaParenthesesCheck::check(
+    const MatchFinder::MatchResult &Result) {
+  const auto *Lambda = Result.Nodes.getNodeAs<LambdaExpr>("lambda");
+
+  if (Lambda->getBeginLoc().isMacroID())
+    return;
+
+  const LangOptions &LangOpts = getLangOpts();
+
+  const auto FTL = Lambda->getCallOperator()->getFunctionTypeLoc();
+  const SourceLocation LParenLoc = FTL.getLParenLoc();
+  const SourceLocation RParenLoc = FTL.getRParenLoc();
+
+  if (LParenLoc.isInvalid() || RParenLoc.isInvalid())
+    return;
+
+  std::optional<Token> NextTok =
+      Lexer::findNextToken(RParenLoc, *Result.SourceManager, LangOpts);
+
+  // Attributes after '()' have different semantics depending on position.
+  if (NextTok && NextTok->is(tok::l_square))
----------------
localspook wrote:

Instead of repeatedly testing whether `NextTok` has a value (here and below), 
can we factor that out into a separate condition like:
```cpp
if (!NextTok)
  return;
```

https://github.com/llvm/llvm-project/pull/190438
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to