[PATCH] D50852: abseil-auto-make-unique
lebedev.ri added reviewers: aaron.ballman, zinovy.nis. lebedev.ri added a comment. In https://reviews.llvm.org/D50852#1203009, @hugoeg wrote: > In https://reviews.llvm.org/D50852#1202774, @lebedev.ri wrote: > > > 1. Please always upload all patches with full context. > > 2. There already is `modernize-use-auto`. Does it handle this case? Then > > this should be just an alias to that check. Else, i think it would be best > > to extend that one, and still alias. > > > since this check checks for absl::make_unique primarily > if we move it to the general check, it'd be weird to check for > absl::make_unique Why do you think it would be weird? That list should/would be a user-configurable config option anyway. > right now our main goal is to release checks tailored specifically to abseil > users, so if we can we would like to release this check separately in the > abseil directory Just checking, was there some memo i missed that abseil-related checks are exempt from all the usual guidelines? Because this check is really not abseil-library-specific. https://reviews.llvm.org/D50852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50852: abseil-auto-make-unique
hugoeg added a comment. In https://reviews.llvm.org/D50852#1202774, @lebedev.ri wrote: > 1. Please always upload all patches with full context. > 2. There already is `modernize-use-auto`. Does it handle this case? Then this > should be just an alias to that check. Else, i think it would be best to > extend that one, and still alias. since this check checks for absl::make_unique primarily if we move it to the general check, it'd be weird to check for absl::make_unique right now our main goal is to release checks tailored specifically to abseil users, so if we can we would like to release this check separately in the abseil directory https://reviews.llvm.org/D50852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50852: abseil-auto-make-unique
lebedev.ri added a comment. In https://reviews.llvm.org/D50852#1202781, @hugoeg wrote: > what do you mean by "with full context"? `-U9` when generating the diff. https://reviews.llvm.org/D50852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50852: abseil-auto-make-unique
hugoeg added a comment. what do you mean by "with full context"? https://reviews.llvm.org/D50852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50852: abseil-auto-make-unique
lebedev.ri added a comment. 1. Please always upload all patches with full context. 2. There already is `modernize-use-auto`. Does it handle this case? Then this should be just an alias to that check. Else, i think it would be best to extend that one, and still alias. https://reviews.llvm.org/D50852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50852: abseil-auto-make-unique
hugoeg created this revision. hugoeg added reviewers: alexfh, hokein. hugoeg added a project: clang-tools-extra. Herald added a subscriber: mgorny. warns to use 'auto' to avoid repeating the type name and fixes the issue Replace: std::unique_ptr x = make_unique(...); with: auto x = make_unique(...); https://reviews.llvm.org/D50852 Files: clang-tidy/abseil/AbseilTidyModule.cpp clang-tidy/abseil/AutoMakeUniqueCheck.cpp clang-tidy/abseil/AutoMakeUniqueCheck.h clang-tidy/abseil/CMakeLists.txt docs/ReleaseNotes.rst docs/clang-tidy/checks/abseil-auto-make-unique.rst docs/clang-tidy/checks/list.rst test/clang-tidy/abseil-auto-make-unique.cpp Index: test/clang-tidy/abseil-auto-make-unique.cpp === --- test/clang-tidy/abseil-auto-make-unique.cpp +++ test/clang-tidy/abseil-auto-make-unique.cpp @@ -0,0 +1,115 @@ +// RUN: %check_clang_tidy %s abseil-auto-make-unique %t + +namespace std { +template +struct default_delete {}; + +template > +class unique_ptr { + public: + unique_ptr(); + ~unique_ptr(); + explicit unique_ptr(T*); + template + unique_ptr(unique_ptr&&); +}; +template +unique_ptr make_unique(Args&&...); +} // namespace std + +namespace absl { +template +std::unique_ptr MakeUnique(Args&&...); +template +std::unique_ptr make_unique(Args&&...); +} // namespace absl +using absl::make_unique; + +typedef int integer; + +struct Base {}; +struct Derived : public Base {}; + +void Primitive() { + std::unique_ptr x = absl::make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto x = absl::make_unique(); + + std::unique_ptr< int >y = absl::make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto y = absl::make_unique(); + + const std::unique_ptr z = absl::make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: const auto z = absl::make_unique(); + + std::unique_ptr t = absl::make_unique(); +} + +void Typedefs() { + std::unique_ptr x = absl::make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto x = absl::make_unique(); + + std::unique_ptr y = absl::make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto y = absl::make_unique(); + + std::unique_ptr z = absl::make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto z = absl::make_unique(); +} + +void Class() { + std::unique_ptr base = make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto base = make_unique(); + + std::unique_ptr base2(make_unique()); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto base2(make_unique()); + + // Different type. No change. + std::unique_ptr z = make_unique(); + std::unique_ptr z2(make_unique()); +} + +template +void f() { + std::unique_ptr x = make_unique(); +} + +void Negatives() { + // Different deleter. No change. + struct MyDeleter {}; + std::unique_ptr z3 = make_unique(); + std::unique_ptr z4(make_unique()); + + f(); +} + +std::unique_ptr global_var = make_unique(); +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'auto' to avoid repeating the type name +// CHECK-FIXES: auto global_var = make_unique(); + +struct Struct { + static std::unique_ptr static_field; +}; +// This code with "auto" replaced doesn't compile in GCC. +std::unique_ptr Struct::static_field = make_unique(); + +void FunctionWithStatic() { + static std::unique_ptr static_var = make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto static_var = make_unique(); +} + +void OtherNames() { + std::unique_ptr x = absl::MakeUnique(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto x = absl::MakeUnique(); + + std::unique_ptr y = std::make_unique(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating the type name + // CHECK-FIXES: auto y = std::make_unique(); +} Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -4,6 +4,7 @@ = .. toctree:: + abseil-auto-make-unique abseil-string-find-startswith android-cloexec-accept android-cloexec-accept4 Index: docs/clang-tidy/checks/abseil-auto-make-unique.rst === --- docs/clang-tidy/checks/abseil-auto-make-unique.rst +++