brintos

brintos / llvm-project-archived public Read only

0
0
Text · 899 B · 78a903a Raw
40 lines · cpp
1// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init,hicpp-member-init,modernize-use-emplace,hicpp-use-emplace %t2 3namespace std {4 5template <typename T>6class vector {7public:8  void push_back(const T &) {}9  void push_back(T &&) {}10 11  template <typename... Args>12  void emplace_back(Args &&... args){};13};14} // namespace std15 16class Foo {17public:18  Foo() : _num1(0)19  // CHECK-MESSAGES: warning: constructor does not initialize these fields: _num2 [cppcoreguidelines-pro-type-member-init,hicpp-member-init]20  {21    _num1 = 10;22  }23 24  int use_the_members() const {25    return _num1 + _num2;26  }27 28private:29  int _num1;30  int _num2;31  // CHECK-FIXES: int _num2{};32};33 34void should_use_emplace(std::vector<Foo> &v) {35  v.push_back(Foo());36  // CHECK-FIXES: v.emplace_back();37  // CHECK-MESSAGES: warning: use emplace_back instead of push_back [hicpp-use-emplace,modernize-use-emplace]38}39 40