summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [ClangTidy] Separate tests for infrastructure and checkersDmitri Gribenko2019-10-111-570/+0
| | | | | | | | | | | | | | | | | | | | Summary: This change moves tests for checkers and infrastructure into separate directories, making it easier to find infrastructure tests. Tests for checkers are already easy to find because they are named after the checker. Tests for infrastructure were difficult to find because they were outnumbered by tests for checkers. Now they are in a separate directory. Reviewers: jfb, jdoerfert, lebedev.ri Subscribers: srhines, nemanjai, aheejin, kbarton, christof, mgrang, arphaman, jfb, lebedev.ri, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68807 llvm-svn: 374540
* [clang-tidy] Fix make-unique tests on C++2a.Haojian Wu2019-06-061-60/+1
| | | | | | | | | | | | | | | | Summary: These test cases are illgal in C++2a ("new Foo{}" needs to see the default constructor), so move them to the C++14-only tests. Reviewers: gribozavr Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62845 llvm-svn: 362679
* [clang-tidy] Fix make-unique check to work in C++17 mode.Haojian Wu2019-06-031-6/+6
| | | | | | | | | | | | | | | | | | | | Summary: Previously, we intended to omit the check fix to the case when constructor has any braced-init-list argument. But the HasListInitializedArgument was not correct to handle all cases (Foo(Bar{1, 2}) will return false in C++14 mode). This patch fixes it, corrects the tests, and makes the check to run at C++17 mode. Reviewers: gribozavr Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62736 llvm-svn: 362361
* Run ClangTidy tests in all C++ language modesDmitri Gribenko2019-05-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | Summary: I inspected every test and did one of the following: - changed the test to run in all language modes, - added a comment explaining why the test is only applicable in a certain mode, - limited the test to language modes where it passes and added a FIXME to fix the checker or the test. Reviewers: alexfh, lebedev.ri Subscribers: nemanjai, kbarton, arphaman, jdoerfert, lebedev.ri, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62125 llvm-svn: 361131
* [clang-tidy] Do not show incorrect fix in modernize-make-uniqueIlya Biryukov2019-05-081-0/+8
| | | | | | | | | | | | | | | | | | Summary: The case when initialize_list hides behind an implicit case was not handled before. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61642 llvm-svn: 360231
* [clang-tidy] No warning for auto new expression in smart checkHaojian Wu2018-11-261-0/+3
| | | | | | | | | | | | Summary: The fix for `auto` new expression is illegal. Reviewers: aaron.ballman Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D54832 llvm-svn: 347551
* [clang-tidy] Don't generate incorrect fixes for class with deleted copy ↵Haojian Wu2018-11-261-0/+59
| | | | | | | | | | | | | | | | | constructor in smart_ptr check. Summary: The fix for aggregate initialization (`std::make_unique<Foo>(Foo {1, 2})` needs to see Foo copy constructor, otherwise we will have a compiler error. So we only emit the check warning. Reviewers: JonasToth, aaron.ballman Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D54745 llvm-svn: 347537
* [clang-tidy] Don't generate incorrect fixes for class constructed from ↵Haojian Wu2018-11-201-0/+32
| | | | | | | | | | | | | | | | | | | | | | | list-initialized arguments Summary: Currently the smart_ptr check (modernize-make-unique) generates the fixes that cannot compile for cases like below -- because brace list can not be deduced in `make_unique`. ``` struct Bar { int a, b; }; struct Foo { Foo(Bar); }; auto foo = std::unique_ptr<Foo>(new Foo({1, 2})); ``` Reviewers: aaron.ballman Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D54704 llvm-svn: 347315
* [clang-tidy] Ignore a case where the fix of make_unique check introduces ↵Haojian Wu2018-10-181-8/+5
| | | | | | | | | | | | | | | | | | | | side effect. Summary: Previously, ptr.reset(new char[5]) will be replaced with `p = make_unique<char[]>(5)`, the fix has side effect -- doing default initialization, it may cause performace regression (we are bitten by this rececntly) The check should be conservative for these cases. Reviewers: alexfh Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D53377 llvm-svn: 344733
* [clang-tidy] Fix handling of parens around new expressions in ↵Alexander Kornienko2018-10-091-0/+13
| | | | | | | | | | | | | | | | | | make_<smartptr> checks. Summary: Extra parentheses around a new expression result in incorrect code after applying fixes. Reviewers: hokein Reviewed By: hokein Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D52989 llvm-svn: 344058
* [clang-tidy][modernize-make-unique] Checks c++14 flag before using ↵Alexander Kornienko2018-03-211-1/+1
| | | | | | | | | | | | | | | | | | | | std::make_unique Summary: For a c++11 code, the clang-tidy rule "modernize-make-unique" should return immediately, as std::make_unique is not supported. Reviewers: hokein, aaron.ballman, ilya-biryukov, alexfh Reviewed By: hokein, aaron.ballman, alexfh Subscribers: Quuxplusone, xazax.hun, cfe-commits Tags: #clang-tools-extra Patch by Frederic Tingaud! Differential Revision: https://reviews.llvm.org/D43766 llvm-svn: 328101
* [clang-tidy] Fix one corner case in make-unique check.Haojian Wu2018-03-061-0/+8
| | | | | | | | | | | | | | | | | Summary: Previously, we tried to cover all "std::initializer_list" implicit conversion cases in the code, but there are some corner cases that not covered (see newly-added test in the patch). Sipping all implicit AST nodes is a better way to filter out all these cases. Reviewers: ilya-biryukov Subscribers: klimek, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D44137 llvm-svn: 326799
* [clang-tidy] Don't generate fixes for invalid new expr location in ↵Haojian Wu2018-01-231-0/+9
| | | | | | | | | | | | | | modernize-make-unique. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D42363 llvm-svn: 323191
* [clang-tidy] Don't generate fix for argument constructed from ↵Haojian Wu2018-01-181-0/+13
| | | | | | | | | | | | | | | | | | | | | | std::initializer_list. Summary: A follow-up fix of rL311652. The previous `vector` in our test is different with `std::vector`, so The check still generates fixes for std::vector (`auto p = std::unique_ptr<Foo>(new Foo({1,2,3}))`) in real world, the patch makes the vector behavior in test align with std::vector (both AST nodes are the same now). Reviewers: ilya-biryukov, alexfh Reviewed By: ilya-biryukov Subscribers: klimek, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D41852 llvm-svn: 322822
* [clang-tidy] A follow-up fix of braced-init-list constructors in make-unique ↵Haojian Wu2017-08-241-0/+22
| | | | | | | | | | | | | | check. Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D37066 llvm-svn: 311652
* [clang-tidy] Ignore statements inside a template instantiation.Haojian Wu2017-08-171-0/+12
| | | | | | | | | | | | Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36822 llvm-svn: 311086
* [clang-tidy] Don't generate fixes for initializer_list constructor in ↵Haojian Wu2017-08-171-7/+30
| | | | | | | | | | | | | | | | | | | | | make_unique check. Summary: The current fix will break the compilation -- because braced list is not deducible in std::make_unique (with the use of forwarding) without specifying the type explicitly. We could support it in the future. Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36786 llvm-svn: 311078
* [clang-tidy] Fix another crash in make-unique check.Haojian Wu2017-08-091-0/+13
| | | | | | | | | | | | | | | | | Summary: The crash happens when calling `reset` method without any preceding operation like "->" or ".", this could happen in a subclass of the "std::unique_ptr". Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36452 llvm-svn: 310496
* [clang-tidy] Ignore macros in make-unique check.Haojian Wu2017-08-041-0/+11
| | | | | | | | | | | | | | | | Summary: The check doesn't fully support smart-ptr usages inside macros, which may cause incorrect fixes, or even crashes, ignore them for now. Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36264 llvm-svn: 310050
* [clang-tidy] Support initializer-list constructor cases in ↵Haojian Wu2017-08-041-0/+68
| | | | | | | | | | | | | | modernize-make-unique. Reviewers: alexfh Reviewed By: alexfh Subscribers: malcolm.parsons, JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36016 llvm-svn: 310035
* [clang-tidy] Add "MakeSmartPtrFunction" option to ↵Haojian Wu2017-07-051-28/+4
| | | | | | | | | | | | | | modernize-make-shared/unique checks. Reviewers: alexfh, aaron.ballman Reviewed By: alexfh Subscribers: JDevlieghere, Eugene.Zelenko, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34206 llvm-svn: 307130
* [clang-tidy] Handle new array expressions in modernize-make-unique check.Haojian Wu2017-06-271-0/+31
| | | | | | | | | | | | Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34674 llvm-svn: 306421
* [clang-tidy] Fix type names in modernize-use-unique/shared_ptr checks.Haojian Wu2017-06-271-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: If the class being created in unique_ptr is in anonymous nampespace, the anonymous namespace will be included in the apply-fixes. This patch fix this. ``` namespace { class Foo {}; } std::unique_ptr<Foo> f; f.reset(new Foo()); // Before the change: f = std::make_unique<(annonymous namespace)::Foo>(); // After the change: f = std::make_unique<Foo>(); ``` Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34286 llvm-svn: 306378
* [clang-tidy] Enhance modernize-make-unique to handle unique_ptr.reset()Malcolm Parsons2016-10-311-11/+85
| | | | | | | | | | | | | | | Summary: Avoid naked new in unique_ptr.reset() by using make_unique Fixes http://llvm.org/PR27383 Reviewers: alexfh, aaron.ballman Subscribers: Prazek, cfe-commits Differential Revision: https://reviews.llvm.org/D25898 llvm-svn: 285589
* [clang-tidy] modernize-make-{smart_ptr} private ctor bugfixPiotr Padlewski2016-08-311-0/+32
| | | | | | | | | | | | | | | Summary: Bugfix for 27321. When the constructor of stored pointer type is private then it is invalid to change it to make_shared or make_unique. Reviewers: alexfh, aaron.ballman, hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D23343 llvm-svn: 280180
* Improve modernize-make-unique matcher.Angel Garcia Gomez2015-11-041-0/+6
| | | | | | | | | | | | Summary: "std::unique_ptr<int>" is not the same type as "std::unique_ptr<int, std::default_delete<int>>", unless we insert a "hasCanonicalType" in the middle. Probably it also happens in other cases related to default template argument. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D14291 llvm-svn: 252041
* Correctly print the type in modernize-make-unique.Angel Garcia Gomez2015-10-221-0/+12
| | | | | | | | | | | | Summary: Take into account the current LangOptions the check has to add back the template argument. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13983 llvm-svn: 251013
* Add %check_clang_tidy and %clang_tidy_diff.Manuel Klimek2015-10-221-1/+1
| | | | | | | | | | With this, site specific lit configs can inject parameters into the test scripts if they need site specific parameters. Next up: enable check_clang_tidy to take a resource dir to enable non-standard locations for builtin includes. llvm-svn: 251010
* Use __SIZE_TYPE__ to fix buildbot failures.Angel Garcia Gomez2015-10-141-1/+1
| | | | | | | | | | | | Summary: Use __SIZE_TYPE__ to fix buildbot failures. Reviewers: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13720 llvm-svn: 250288
* Support every kind of initialization.Angel Garcia Gomez2015-10-141-17/+77
| | | | | | | | | | | | Summary: modernize-make-unique now correctly supports the different kinds of list initialization. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D13590 llvm-svn: 250283
* Use better mocks in modernize-make-unique, and fix matcher.Angel Garcia Gomez2015-10-051-1/+4
| | | | | | | | | | | | Summary: Add the second template argument to the unique_ptr mock, and update the matcher so that it only matches against cases where the second argument is the default. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13433 llvm-svn: 249305
* Create modernize-make-unique check.Angel Garcia Gomez2015-09-291-0/+122
Summary: create a check that replaces 'std::unique_ptr<type>(new type(args...))' with 'std::make_unique<type>(args...)'. It was on the list of "Ideas for new Tools". It needs to be tested more carefully, but first I wanted to know if you think it is worth the effort. Reviewers: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13166 llvm-svn: 248785
OpenPOWER on IntegriCloud