[clang-tools-extra] [clang-tidy] Add modernize-use-aggregate check (PR #182061)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 9 04:38:06 PDT 2026
================
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEAGGREGATECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEAGGREGATECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::modernize {
+
+/// Finds classes that could be aggregates if their trivial constructors
+/// were removed.
+///
+/// A constructor is considered trivial when it simply forwards each parameter
+/// to a member in declaration order and has an empty body. Removing such
+/// constructors enables aggregate initialization, which is often clearer and
+/// supports designated initializers (C++20).
+///
+/// For the user-facing documentation see:
+/// https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-aggregate.html
+class UseAggregateCheck : public ClangTidyCheck {
+public:
+ UseAggregateCheck(StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+ return LangOpts.CPlusPlus;
----------------
zeyi2 wrote:
I think we need to handle C++11 differently:
> Aggregate
An aggregate is one of the following types:
> - array types
> - class types that has no [default member initializers](https://en.cppreference.com/w/cpp/language/data_members.html#Member_initialization)
(since C++11)
(until C++14)
https://en.cppreference.com/w/cpp/language/aggregate_initialization.html
Or we can raise the barrier to C++14, I think there is a `LangOpts` for it.
https://github.com/llvm/llvm-project/pull/182061
More information about the cfe-commits
mailing list