================ @@ -0,0 +1,212 @@ +//===----------------------------------------------------------------------===// +// +// 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 "UseAggregateCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclCXX.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::modernize { + +/// Check whether \p Ctor is a trivial forwarding constructor: each parameter +/// is used to initialise the corresponding member (in declaration order) and +/// the body is empty. +static bool isTrivialForwardingConstructor(const CXXConstructorDecl *Ctor) { + if (!Ctor || !Ctor->hasBody()) + return false; + + // Body must be an empty compound statement. + const auto *Body = dyn_cast<CompoundStmt>(Ctor->getBody()); + if (!Body || !Body->body_empty()) + return false; + + const CXXRecordDecl *Record = Ctor->getParent(); + + // Collect non-static data members in declaration order. + SmallVector<const FieldDecl *, 8> Fields; + for (const auto *Field : Record->fields()) + Fields.push_back(Field); + + // Number of parameters must match number of fields. + if (Ctor->getNumParams() != Fields.size()) + return false; + + // Number of member initializers must match number of fields (no base + // class inits, no extra inits). + unsigned NumMemberInits = 0; + for (const auto *Init : Ctor->inits()) ---------------- zeyi2 wrote:
Nit: Can we use `llvm::all_of` for this? https://github.com/llvm/llvm-project/pull/182061 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
