Skip to content

[clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers #134774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl()))));
Finder->addMatcher(
initListExpr(
hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
unless(HasBaseWithFields))
hasType(cxxRecordDecl(
RestrictToPODTypes ? isPOD() : isAggregate(),
unless(anyOf(HasBaseWithFields, hasName("::std::array"))))
.bind("type")),
IgnoreSingleElementAggregates ? hasMoreThanOneElement() : anything(),
unless(isFullyDesignated()))
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ Changes in existing checks
``constexpr`` and ``static``` values on member initialization and by detecting
explicit casting of built-in types within member list initialization.

- Improved :doc:`modernize-use-designated-initializers
<clang-tidy/checks/modernize/use-designated-initializers>` check by avoiding
diagnosing designated initializers for ``std::array`` initializations.

- Improved :doc:`modernize-use-ranges
<clang-tidy/checks/modernize/use-ranges>` check by updating suppress
warnings logic for ``nullptr`` in ``std::find``.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Options

The value `false` specifies that even initializers for aggregate types with
only a single element should be checked. The default value is `true`.
``std::array`` initializations are always excluded, as the type is a
standard library abstraction and not intended to be initialized with
designated initializers.

.. option:: RestrictToPODTypes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,18 @@ struct S15{
S15(S14& d):d{d}{}
S14& d;
};

//Issue #133715
namespace std {
template<typename T, unsigned int N>
struct array {
T __elems[N];
};
template<typename T, typename... U>
array(T, U...) -> array<T, 1 + sizeof...(U)>;
}

std::array a{1,2,3};
std::array<int,2> b{10, 11};
using array = std::array<int, 2>;
array c{10, 11};
Loading