You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The readability-redundant-member-init check issues warnings on initializers even when the relevant default constructor is marked explicit and is user-provided.
Example code (godbolt here) with clang-tidy args -checks=-*,readability-redundant-member-init:
structA
{
explicitA() {}
};
structB
{
A a1 {}; // Compiles, but tidy detects a redundant member init
A a2; // No warning from tidy, but does not compile
};
auto b = B{};
In the above example, clang-tidy flags the a1 line with:
<source>:8:10: warning: initializer for member 'a1' is redundant [readability-redundant-member-init]
8 | A a1 {}; // Compiles, but tidy detects a redundant member init
When I do what tidy wants in the a2 line, this fails to compile with:
<source>:12:12: error: chosen constructor is explicit in copy-initialization
12 | auto b = B{};
| ^
<source>:3:14: note: explicit constructor declared here
3 | explicit A() {}
| ^
<source>:9:7: note: in implicit initialization of field 'a2' with omitted initializer
9 | A a2; // No warning from tidy, but does not compile
| ^
1 error generated.
Compiler returned: 1
Interestingly, clang-tidy no longer warns if the constructor is instead explicitly defaulted, i.e., explicit A() = default;.
For context, I encountered this issue when working with boost::circular_buffer's default constructor (docs here):
It seems to me that readability-redundant-member-init should ignore instances where the initializer is invoking an explicit default constructor. Is that correct or am I doing something wrong?
The text was updated successfully, but these errors were encountered:
The `readability-redundant-member-init` check issues warnings on initializers even when the relevant default constructor is **marked `explicit`** and is **user-provided**.
Example code (godbolt here) with clang-tidy args -checks=-*,readability-redundant-member-init:
structA
{
explicitA() {}
};
structB
{
A a1 {}; // Compiles, but tidy detects a redundant member init
A a2; // No warning from tidy, but does not compile
};
auto b = B{};
In the above example, clang-tidy flags the a1 line with:
<source>:8:10: warning: initializer for member 'a1' is redundant [readability-redundant-member-init]
8 | A a1 {}; // Compiles, but tidy detects a redundant member init
When I do what tidy wants in the a2 line, this fails to compile with:
<source>:12:12: error: chosen constructor is explicit in copy-initialization
12 | auto b = B{};
| ^
<source>:3:14: note: explicit constructor declared here
3 | explicit A() {}
| ^
<source>:9:7: note: in implicit initialization of field 'a2' with omitted initializer
9 | A a2; // No warning from tidy, but does not compile
| ^
1 error generated.
Compiler returned: 1
Interestingly, clang-tidy no longer warns if the constructor is instead explicitly defaulted, i.e., explicit A() = default;.
For context, I encountered this issue when working with boost::circular_buffer's default constructor (docs here):
explicitcircular_buffer(const allocator_type & alloc = allocator_type()) noexcept;
It seems to me that readability-redundant-member-init should ignore instances where the initializer is invoking an explicit default constructor. Is that correct or am I doing something wrong?
The
readability-redundant-member-init
check issues warnings on initializers even when the relevant default constructor is markedexplicit
and is user-provided.Example code (godbolt here) with clang-tidy args
-checks=-*,readability-redundant-member-init
:In the above example, clang-tidy flags the
a1
line with:When I do what tidy wants in the
a2
line, this fails to compile with:Interestingly, clang-tidy no longer warns if the constructor is instead explicitly defaulted, i.e.,
explicit A() = default;
.For context, I encountered this issue when working with
boost::circular_buffer
's default constructor (docs here):It seems to me that
readability-redundant-member-init
should ignore instances where the initializer is invoking an explicit default constructor. Is that correct or am I doing something wrong?The text was updated successfully, but these errors were encountered: