File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -121,8 +121,9 @@ void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
121121 hasAnyBase (hasType (cxxRecordDecl (has (fieldDecl ()))));
122122 Finder->addMatcher (
123123 initListExpr (
124- hasType (cxxRecordDecl (RestrictToPODTypes ? isPOD () : isAggregate (),
125- unless (HasBaseWithFields))
124+ hasType (cxxRecordDecl (
125+ RestrictToPODTypes ? isPOD () : isAggregate (),
126+ unless (anyOf (HasBaseWithFields, hasName (" ::std::array" ))))
126127 .bind (" type" )),
127128 IgnoreSingleElementAggregates ? hasMoreThanOneElement () : anything (),
128129 unless (isFullyDesignated ()))
Original file line number Diff line number Diff line change @@ -182,6 +182,10 @@ Changes in existing checks
182182 ``constexpr `` and ``static` `` values on member initialization and by detecting
183183 explicit casting of built-in types within member list initialization.
184184
185+ - Improved :doc: `modernize-use-designated-initializers
186+ <clang-tidy/checks/modernize/use-designated-initializers>` check by avoiding
187+ diagnosing designated initializers for ``std::array `` initializations.
188+
185189- Improved :doc: `modernize-use-ranges
186190 <clang-tidy/checks/modernize/use-ranges>` check by updating suppress
187191 warnings logic for ``nullptr `` in ``std::find ``.
Original file line number Diff line number Diff line change @@ -54,6 +54,9 @@ Options
5454
5555 The value `false ` specifies that even initializers for aggregate types with
5656 only a single element should be checked. The default value is `true `.
57+ ``std::array `` initializations are always excluded, as the type is a
58+ standard library abstraction and not intended to be initialized with
59+ designated initializers.
5760
5861.. option :: RestrictToPODTypes
5962
Original file line number Diff line number Diff line change @@ -209,3 +209,18 @@ struct S15{
209209 S15 (S14& d):d{d}{}
210210 S14& d;
211211};
212+
213+ // Issue #133715
214+ namespace std {
215+ template <typename T, unsigned int N>
216+ struct array {
217+ T __elems[N];
218+ };
219+ template <typename T, typename ... U>
220+ array (T, U...) -> array<T, 1 + sizeof ...(U)>;
221+ }
222+
223+ std::array a{1 ,2 ,3 };
224+ std::array<int ,2 > b{10 , 11 };
225+ using array = std::array<int , 2 >;
226+ array c{10 , 11 };
You can’t perform that action at this time.
0 commit comments