summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add the misc-init-local-variables check.Aaron Ballman2019-10-021-0/+3
| | | | | | | | This checks finds all primitive type local variables (integers, doubles, pointers) that are declared without an initial value. Includes fixit functionality to initialize said variables with a default value. This is zero for most types and NaN for floating point types. The use of NaNs is copied from the D programming language. Patch by Jussi Pakkanen. llvm-svn: 373489
* Fix file headers. NFCFangrui Song2019-03-011-1/+1
| | | | llvm-svn: 355188
* [clang-tidy] added cppcoreguidelines-explicit-virtual-functionsJonas Toth2019-02-281-0/+6
| | | | | | | | | | | | Addresses the bugzilla bug #30397. (https://bugs.llvm.org/show_bug.cgi?id=30397) modernize-use-override suggests that destructors require the override specifier and the CPP core guidelines do not recommend this. Patch by lewmpk. Differential Revision: https://reviews.llvm.org/D58731 llvm-svn: 355093
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clang-tidy] Avoid C arrays checkRoman Lebedev2018-11-141-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: [[ https://bugs.llvm.org/show_bug.cgi?id=39224 | PR39224 ]] As discussed, we can't always do the transform automatically due to that array-to-pointer decay of C array. In order to detect whether we can do said transform, we'd need to be able to see all usages of said array, which is, i would say, rather impossible if e.g. it is in the header. Thus right now no fixit exists. Exceptions: `extern "C"` code. References: * [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es27-use-stdarray-or-stack_array-for-arrays-on-the-stack | CPPCG ES.27: Use std::array or stack_array for arrays on the stack ]] * [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon1-prefer-using-stl-array-or-vector-instead-of-a-c-array | CPPCG SL.con.1: Prefer using STL array or vector instead of a C array ]] * HICPP `4.1.1 Ensure that a function argument does not undergo an array-to-pointer conversion` * MISRA `5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer` Reviewers: aaron.ballman, JonasToth, alexfh, hokein, xazax.hun Reviewed By: JonasToth Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D53771 llvm-svn: 346835
* [clang-tidy] implement cppcoreguidelines macro rulesJonas Toth2018-10-221-0/+3
| | | | | | | | | | | | | | | | Summary: In short macros are discouraged by multiple rules (and sometimes reference randomly). [Enum.1], [ES.30], [ES.31] This check allows only headerguards and empty macros for annotation. Reviewers: aaron.ballman, hokein Reviewed By: aaron.ballman Subscribers: jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D41648 llvm-svn: 344940
* [clang-tidy] Non-private member variables in classes (MISRA, ↵Roman Lebedev2018-10-181-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CppCoreGuidelines, HICPP) Summary: Finds classes that not only contain the data (non-static member variables), but also have logic (non-static member functions), and diagnoses all member variables that have any other scope other than `private`. They should be made `private`, and manipulated exclusively via the member functions. Optionally, classes with all member variables being `public` could be ignored, and optionally all `public` member variables could be ignored. Options ------- * IgnoreClassesWithAllMemberVariablesBeingPublic Allows to completely ignore classes if **all** the member variables in that class have `public` visibility. * IgnorePublicMemberVariables Allows to ignore (not diagnose) **all** the member variables with `public` visibility scope. References: * MISRA 11-0-1 Member data in non-POD class types shall be private. * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c2-use-class-if-the-class-has-an-invariant-use-struct-if-the-data-members-can-vary-independently * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-private * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-protected Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, zinovy.nis, cfe-commits, rnkovacs, nemanjai, mgorny, xazax.hun, kbarton Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52771 llvm-svn: 344757
* [clang-tidy] NFC reorder registering in CppCoreGuidelines moduleJonas Toth2018-10-031-2/+2
| | | | llvm-svn: 343673
* Add a new check to the readability module that flags uses of "magic numbers" ↵Aaron Ballman2018-08-121-0/+3
| | | | | | | | (both floating-point and integral). Patch by Florin Iucha <florin@signbit.net> llvm-svn: 339516
* [clang-tidy] new cppcoreguidelines-narrowing-conversions check.Clement Courbet2018-05-231-0/+3
| | | | | | | | | | | | | | | | | | | Summary: Checks for narrowing conversions, e.g. int i = 0; i += 0.1; This has what some might consider false positives for: i += ceil(d); Reviewers: alexfh, hokein Subscribers: srhines, nemanjai, mgorny, JDevlieghere, xazax.hun, kbarton Differential Revision: https://reviews.llvm.org/D38455 llvm-svn: 333066
* [clang-tidy] implement check for gotoJonas Toth2018-01-171-0/+3
| | | | | | | | | | | | | | | | | | | | The usage of `goto` is discourage in C++ since forever. This check implements a warning for every `goto`. Even though there are (rare) valid use cases for `goto`, better high level constructs should be used. `goto` is used sometimes in C programs to free resources at the end of functions in the case of errors. This pattern is better implemented with RAII in C++. Reviewers: aaron.ballman, alexfh, hokein Reviewed By: aaron.ballman Subscribers: lebedev.ri, jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D41815 llvm-svn: 322626
* [clang-tidy] Implement type-based check for `gsl::owner`Jonas Toth2017-09-121-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This check implements the typebased semantic of `gsl::owner`. Meaning, that - only `gsl::owner` is allowed to get `delete`d - `new` expression must be assigned to `gsl::owner` - function calls that expect `gsl::owner` as argument, must get either an owner or a newly created and recognized resource (in the moment only `new`ed memory) - assignment to `gsl::owner` must be either a resource or another owner - functions returning an `gsl::owner` are considered as factories, and their result must be assigned to an `gsl::owner` - classes that have an `gsl::owner`-member must declare a non-default destructor There are some problems that occur when typededuction is in place. For example `auto Var = function_that_returns_owner();` the type of `Var` will not be an `gsl::owner`. This case is catched, and explicitly noted. But cases like fully templated functions ``` template <typename T> void f(T t) { delete t; } // ... f(gsl::owner<int*>(new int(42))); ``` Will created false positive (the deletion is problematic), since the type deduction removes the wrapping `typeAlias`. Codereview in D36354 llvm-svn: 313067
* [clang-tidy] Revert Implement type-based check for gsl::ownerJonas Toth2017-09-121-3/+0
| | | | | | This should unbreak the buildbot for visual studio 2015 for now. llvm-svn: 313059
* [clang-tidy] Implement type-based check for `gsl::owner`Jonas Toth2017-09-121-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This check implements the typebased semantic of `gsl::owner`. Meaning, that - only `gsl::owner` is allowed to get `delete`d - `new` expression must be assigned to `gsl::owner` - function calls that expect `gsl::owner` as argument, must get either an owner or a newly created and recognized resource (in the moment only `new`ed memory) - assignment to `gsl::owner` must be either a resource or another owner - functions returning an `gsl::owner` are considered as factories, and their result must be assigned to an `gsl::owner` - classes that have an `gsl::owner`-member must declare a non-default destructor There are some problems that occur when typededuction is in place. For example `auto Var = function_that_returns_owner();` the type of `Var` will not be an `gsl::owner`. This case is catched, and explicitly noted. But cases like fully templated functions ``` template <typename T> void f(T t) { delete t; } // ... f(gsl::owner<int*>(new int(42))); ``` Will created false positive (the deletion is problematic), since the type deduction removes the wrapping `typeAlias`. Please give your comments :) llvm-svn: 313043
* [Clang-tidy] check for malloc, realloc and free callsAlexander Kornienko2016-12-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | Summary: This checker flags the use of C-style memory management functionality and notes about modern alternatives. In an earlier revision it tried to autofix some kind of patterns, but that was a bad idea. Since memory management can be so widespread in a program, manual updating is most likely necessary. Maybe for special cases, there could be later additions to this basic checker. This is the first checker I wrote and I never did something with clang (only compiling programs). So whenever I missed conventions or did plain retarded stuff, feel free to point it out! I am willing to fix them and write a better checker. I hope the patch does work, I never did this either. On a testapply in my repository it did, but I am pretty unconfident in my patching skills :) Reviewers: aaron.ballman, hokein, alexfh, malcolm.parsons Subscribers: cfe-commits, JDevlieghere, nemanjai, Eugene.Zelenko, Prazek, mgorny, modocache Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D26167 Patch by Jonas Toth! llvm-svn: 289546
* [clang-tools-extra] Format sources with clang-format. NFC.Mandeep Singh Grang2016-11-081-3/+2
| | | | | | | | | | | | | | | | Summary: Ran clang-format on all .c/.cpp/.h files in clang-tools-extra. Excluded the test, unittests, clang-reorder-fields, include-fixer, modularize and pptrace directories. Reviewers: klimek, alexfh Subscribers: nemanjai Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D26329 llvm-svn: 286221
* [clang-tidy] add check cppcoreguidelines-special-member-functionsJonathan Coe2016-07-301-0/+3
| | | | | | | | | | | | | | | | | | | Summary: Check for classes that violate the rule of five and zero as specified in CppCoreGuidelines: "If a class defines or deletes a default operation then it should define or delete them all." https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-default-operation-define-or-delete-them-all. Reviewers: alexfh, sbenza, aaron.ballman Subscribers: Prazek, Eugene.Zelenko, cfe-commits, ericLemanissier, nemanjai Projects: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D22513 llvm-svn: 277262
* Revert "Revert "[clang-tidy] new cppcoreguidelines-slicing""Clement Courbet2016-07-221-0/+3
| | | | | | Second try for r276408 llvm-svn: 276415
* Revert "[clang-tidy] new cppcoreguidelines-slicing"Clement Courbet2016-07-221-3/+0
| | | | | | Tests fail on clang-x64-ninja-win7 due to too narrow expectation. llvm-svn: 276413
* [clang-tidy] new cppcoreguidelines-slicingClement Courbet2016-07-221-0/+3
| | | | | | | | | | | | Flags slicing of member variables or vtable. See: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es63-dont-slice https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c145-access-polymorphic-objects-through-pointers-and-references Differential revision: http://reviews.llvm.org/D21974 llvm-svn: 276408
* [clang-tidy] New: checker misc-unconventional-assign-operator replacing ↵Gabor Horvath2016-05-041-2/+2
| | | | | | | | | | | | | | misc-assign-operator-signature Summary: Finds return statements in assign operator bodies where the return value is different from '*this'. Only assignment operators with correct return value Class& are checked. Reviewers: aaron.ballman, alexfh, sbenza Subscribers: o.gyorgy, baloghadamsoftware, LegalizeAdulthood, aaron.ballman, Eugene.Zelenko, xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D18265 llvm-svn: 268492
* [clang-tidy] cppcoreguidelines-interfaces-global-initAlexander Kornienko2016-04-081-0/+3
| | | | | | | | | | | | | | | | Summary: This check flags initializers of globals that access extern objects, and therefore can lead to order-of-initialization problems (this recommandation is part of CPP core guidelines). Note that this only checks half of the guideline for now (it does not enforce using constexpr functions). Reviewers: aaron.ballman, alexfh Subscribers: aaron.ballman, etienneb, Eugene.Zelenko, cfe-commits Patch by Clement Courbet! Differential Revision: http://reviews.llvm.org/D18649 llvm-svn: 265774
* [clang-tidy] ClangTidy check to flag uninitialized builtin and pointer fields.Felix Berger2016-02-151-0/+3
| | | | | | | | | | | | | | | | | | | | | Summary: This patch is a continuation of http://reviews.llvm.org/D10553 by Jonathan B Coe. The main additions are: 1. For C++11 the check suggests in-class field initialization as fix. This makes the fields future proof towards the addition of new constructors. 2 For older language versions the fields are added in the right position in the initializer list with more tests. 3. User documentation. Reviewers: alexfh, jbcoe Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D16517 llvm-svn: 260873
* [clang-tidy] add check cppcoreguidelines-pro-bounds-constant-array-indexMatthias Gehre2015-12-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is http://reviews.llvm.org/D13746 but instead of including <array>, a stub is provided. This check flags all array subscriptions on static arrays and std::arrays that either have a non-compile-time-constant index or are out of bounds. Dynamic accesses into arrays are difficult for both tools and humans to validate as safe. array_view is a bounds-checked, safe type for accessing arrays of data. at() is another alternative that ensures single accesses are bounds-checked. If iterators are needed to access an array, use the iterators from an array_view constructed over the array. This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds2-only-index-into-arrays-using-constant-expressions Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15030 llvm-svn: 255470
* Revert r253401, "[clang-tidy] add check ↵NAKAMURA Takumi2015-11-181-3/+0
| | | | | | | | cppcoreguidelines-pro-bounds-constant-array-index" cppcoreguidelines-pro-bounds-constant-array-index.cpp is failing in several hosts. llvm-svn: 253428
* [clang-tidy] add check cppcoreguidelines-pro-bounds-constant-array-indexMatthias Gehre2015-11-171-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This check flags all array subscriptions on static arrays and std::arrays that either have a non-compile-time-constant index or are out of bounds. Dynamic accesses into arrays are difficult for both tools and humans to validate as safe. array_view is a bounds-checked, safe type for accessing arrays of data. at() is another alternative that ensures single accesses are bounds-checked. If iterators are needed to access an array, use the iterators from an array_view constructed over the array. This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds2-only-index-into-arrays-using-constant-expressions Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13746 llvm-svn: 253401
* [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-castMatthias Gehre2015-11-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This check flags all use of c-style casts that perform a static_cast downcast, const_cast, or reinterpret_cast. Use of these casts can violate type safety and cause the program to access a variable that is actually of type X to be accessed as if it were of an unrelated type Z. Note that a C-style (T)expression cast means to perform the first of the following that is possible: a const_cast, a static_cast, a static_cast followed by a const_cast, a reinterpret_cast, or a reinterpret_cast followed by a const_cast. This rule bans (T)expression only when used to perform an unsafe cast. This rule is part of the "Type safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type4-dont-use-c-style-texpression-casts-that-would-perform-a-static_cast-downcast-const_cast-or-reinterpret_cast. Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D14096 llvm-svn: 252425
* [clang-tidy] Add new check cppcoreguidelines-pro-bounds-array-to-pointer-decayMatthias Gehre2015-10-261-0/+3
| | | | | | | | | | | | | | | | | | | | Summary: This check flags all array to pointer decays. Pointers should not be used as arrays. array_view is a bounds-checked, safe alternative to using pointers to access arrays. This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds3-no-array-to-pointer-decay Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13640 llvm-svn: 251358
* [clang-tidy] add check cppcoreguidelines-pro-type-varargMatthias Gehre2015-10-211-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This check flags all calls to c-style vararg functions and all use of va_list, va_start and va_arg. Passing to varargs assumes the correct type will be read. This is fragile because it cannot generally be enforced to be safe in the language and so relies on programmer discipline to get it right. This rule is part of the "Type safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type8-avoid-reading-from-varargs-or-passing-vararg-arguments-prefer-variadic-template-parameters-instead This commits also reverts "[clang-tidy] add cert's VariadicFunctionDefCheck as cppcoreguidelines-pro-type-vararg-def" because that check makes the SFINAE use of vararg functions impossible. Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13787 llvm-svn: 250939
* [clang-tidy] add check cppcoreguidelines-pro-type-union-accessMatthias Gehre2015-10-161-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This check flags all access to members of unions. Passing unions as a whole is not flagged. Reading from a union member assumes that member was the last one written, and writing to a union member assumes another member with a nontrivial destructor had its destructor called. This is fragile because it cannot generally be enforced to be safe in the language and so relies on programmer discipline to get it right. This rule is part of the "Type safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type7-avoid-accessing-members-of-raw-unions-prefer-variant-instead Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13784 llvm-svn: 250537
* [clang-tidy] add cert's VariadicFunctionDefCheck as ↵Matthias Gehre2015-10-151-0/+3
| | | | | | | | | | | | | | | | | cppcoreguidelines-pro-type-vararg-def Summary: Import the cert check for variadic function definitions into cppcoreguidelines module to check part of https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type8-avoid-reading-from-varargs-or-passing-vararg-arguments-prefer-variadic-template-parameters-instead Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13785 llvm-svn: 250468
* Expose the clang-tidy misc-assign-operator-signature checker as ↵Aaron Ballman2015-10-131-0/+3
| | | | | | cppcoreguidelines-c-copy-assignment-signature. llvm-svn: 250165
* [clang-tidy] new check cppcoreguidelines-pro-bounds-pointer-arithmeticMatthias Gehre2015-10-121-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This check flags all usage of pointer arithmetic, because it could lead to an invalid pointer. Subtraction of two pointers is not flagged by this check. Pointers should only refer to single objects, and pointer arithmetic is fragile and easy to get wrong. array_view is a bounds-checked, safe type for accessing arrays of data. This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds1-dont-use-pointer-arithmetic-use-array_view-instead Depends on D13313 Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13311 llvm-svn: 250116
* [clang-tidy] add check cppcoreguidelines-pro-type-static-cast-downcastMatthias Gehre2015-10-121-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This check flags all usages of static_cast, where a base class is casted to a derived class. In those cases, a fixit is provided to convert the cast to a dynamic_cast. Use of these casts can violate type safety and cause the program to access a variable that is actually of type X to be accessed as if it were of an unrelated type Z. This rule is part of the "Type safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type2-dont-use-static_cast-downcasts-use-dynamic_cast-instead Depends on D13313 Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13368 llvm-svn: 250098
* Test commitMatthias Gehre2015-10-111-0/+1
| | | | llvm-svn: 250002
* Add checker for the C++ Core Guidelines: cppcoreguidelines-pro-type-const-cast.Aaron Ballman2015-10-071-0/+3
| | | | | | Patch by Matthias Gehre! llvm-svn: 249540
* Add a new module for the C++ Core Guidelines, and the first checker for ↵Aaron Ballman2015-10-061-0/+38
those guidelines: cppcoreguidelines-pro-type-reinterpret-cast. Patch by Matthias Gehre! llvm-svn: 249399
OpenPOWER on IntegriCloud