llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.13k stars 12.02k forks source link

clang-tidy "modernize-use-default-member-init" and redundant initializer of std::vector with 0 #43787

Open d97321dc-6cbe-4326-88f1-0c062d53aa69 opened 4 years ago

d97321dc-6cbe-4326-88f1-0c062d53aa69 commented 4 years ago
Bugzilla Link 44442
Version unspecified
OS Windows NT
CC @EugeneZelenko,@pepsiman

Extended Description

It would be great if clang-tidy "modernize-use-default-member-init" was flagging redundant initializers of std::vector with 0.

include

class TXX { public: explicit TXX() : m_1(0) {} private: std::vector m_1; };

pepsiman commented 4 years ago

Initialising a vector like that is redundant in all contexts, not just member initialisation.

Clang-tidy has a readability-redundant-string-init for string initialisation, maybe a similar check could be added for initialising containers.

PiotrZSL commented 1 year ago

Actually this is a bug, simply because it will lead to memory allocation of 0 bytes. And this is not in scope of this check. New check should be created.