1 // RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init,hicpp-member-init,modernize-use-emplace,hicpp-use-emplace %t 2 3 namespace std { 4 5 template <typename T> 6 class vector { 7 public: push_back(const T &)8 void push_back(const T &) {} push_back(T &&)9 void push_back(T &&) {} 10 11 template <typename... Args> emplace_back(Args &&...args)12 void emplace_back(Args &&... args){}; 13 }; 14 } // namespace std 15 16 class Foo { 17 public: Foo()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 use_the_members() const24 int use_the_members() const { 25 return _num1 + _num2; 26 } 27 28 private: 29 int _num1; 30 int _num2; 31 // CHECK-FIXES: _num2{}; 32 }; 33 should_use_emplace(std::vector<Foo> & v)34int 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