summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/cppcoreguidelines
Commit message (Collapse)AuthorAgeFilesLines
* [clang-tidy] Fix false positive for cppcoreguidelines-init-variablesNathan James2020-02-101-5/+9
| | | | | | | | | | | | | | | | Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=44746 | False positive for cppcoreguidelines-init-variables in range based for loop in template function ]] Reviewers: aaron.ballman, alexfh, hokein, JonasToth, gribozavr2 Reviewed By: aaron.ballman Subscribers: merge_guards_bot, xazax.hun, wuzish, nemanjai, kbarton, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D73843 (cherry picked from commit efcd09cea9a51c522954aa24e4b5513266daf6c3)
* NFC: Fix trivial typos in commentsKazuaki Ishizaki2020-01-042-3/+3
|
* [NFC] Fixes -Wrange-loop-analysis warningsMark de Wever2020-01-011-1/+1
| | | | | | This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D71857
* Add the misc-init-local-variables check.Aaron Ballman2019-10-024-0/+151
| | | | | | | | 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
* Remove \brief commands from doxygen comments.Dmitri Gribenko2019-08-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Summary: We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done [This is analogous to LLVM r331272 and CFE r331834] Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66578 llvm-svn: 369643
* [clang-tools-extra] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-142-2/+2
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368944
* [clang-tidy] Add option "LiteralInitializers" to ↵Matthias Gehre2019-05-242-2/+59
| | | | | | | | cppcoreguidelines-pro-type-member-init Differential Revision: D24892 llvm-svn: 361601
* [clang-tidy] Don't issue cppcoreguidelines-macro-usage on builtin macrosAlexander Kornienko2019-04-171-1/+2
| | | | | | | | | | | | | | | | | Before the patch calling clang-tidy with -header-filter=.* -system-headers would result in a few hundred useless warnings: warning: macro '_GNU_SOURCE' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] warning: macro '_LP64' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] warning: macro '__ATOMIC_ACQUIRE' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] warning: macro '__ATOMIC_ACQ_REL' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] warning: macro '__ATOMIC_CONSUME' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] warning: macro '__ATOMIC_RELAXED' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] warning: macro '__ATOMIC_RELEASE' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] warning: macro '__ATOMIC_SEQ_CST' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] warning: macro '__BIGGEST_ALIGNMENT__' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] ... and so on llvm-svn: 358621
* [clang-tidy] Move all checks to the new registerPPCallbacks APIAlexander Kornienko2019-03-224-11/+13
| | | | llvm-svn: 356796
* 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-1937-148/+111
| | | | | | | | | | | | | | | | | 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
* Add explicit dependency on clangSerialization after rC348911Fangrui Song2018-12-121-0/+1
| | | | llvm-svn: 348916
* [clang-tidy] Improving narrowing conversionsGuillaume Chatelet2018-11-262-33/+476
| | | | | | | | | | | | | | | | | | | | | Summary: Newly flagged narrowing conversions: - integer to narrower signed integer (this is compiler implementation defined), - integer - floating point narrowing conversions, - floating point - integer narrowing conversions, - constants with narrowing conversions (even in ternary operator). Reviewers: hokein, alexfh, aaron.ballman, JonasToth Reviewed By: aaron.ballman, JonasToth Subscribers: lebedev.ri, courbet, nemanjai, xazax.hun, kbarton, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D53488 llvm-svn: 347570
* A bit of AST matcher cleanup, NFC.Alexander Kornienko2018-11-252-37/+33
| | | | | | | | | Removed the uses of the allOf() matcher inside node matchers that are implicit allOf(). Replaced uses of allOf() with the explicit node matcher where it makes matchers more readable. Replace anyOf(hasName(), hasName(), ...) with the more efficient and readable hasAnyName(). llvm-svn: 347520
* [clang-tidy] Avoid C arrays checkRoman Lebedev2018-11-142-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] fix PR39583 - ignoring ParenCast for string-literals in ↵Jonas Toth2018-11-091-4/+5
| | | | | | | | | | | | | | | | | | | pro-bounds-array-to-pointer-decay Summary: The fix to the issue that `const char* p = ("foo")` is diagnosed as decay is to ignored the ParenCast. Resolves PR39583 Reviewers: aaron.ballman, alexfh, hokein Reviewed By: aaron.ballman Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D54281 llvm-svn: 346555
* [clang-tidy] cppcoreguidelines-macro-usage: print macro namesRoman Lebedev2018-10-302-16/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The macro may not have location (or more generally, the location may not exist), e.g. if it originates from compiler's command-line. The check complains on all the macros, even those without the location info. Which means, it only says it does not like it. What is 'it'? I have no idea. If we don't print the name, then there is no way to deal with that situation. And in general, not printing name here forces the user to try to understand, given, the macro definition location, what is the macro name? This isn't fun. Also, ignores-by-default the macros originating from command-line, with an option to not ignore those. I suspect some more issues may crop up later. Reviewers: JonasToth, aaron.ballman, hokein, xazax.hun, alexfh Reviewed By: JonasToth, aaron.ballman Subscribers: nemanjai, kbarton, rnkovacs, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D53817 llvm-svn: 345610
* [clang-tidy] tryfix windows buildJonas Toth2018-10-221-0/+1
| | | | llvm-svn: 344947
* [clang-tidy] implement cppcoreguidelines macro rulesJonas Toth2018-10-224-0/+147
| | | | | | | | | | | | | | | | 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 refactor lexer-utils to be usable without ASTContextJonas Toth2018-10-051-2/+4
| | | | | | | | | | | | | | | | | | | Summary: This patch is a small refactoring necessary for 'readability-isolate-declaration' and does not introduce functional changes. It allows to use the utility functions without a full `ASTContext` and requires only the `SourceManager` and the `LangOpts`. Reviewers: alexfh, aaron.ballman, hokein Reviewed By: alexfh Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52684 llvm-svn: 343850
* [clang-tidy] NFC reorder registering in CppCoreGuidelines moduleJonas Toth2018-10-031-2/+2
| | | | llvm-svn: 343673
* [Clang-tidy] Alphabetical sort of files/checks. Add space after clang-tidy ↵Eugene Zelenko2018-09-201-1/+1
| | | | | | in source code headers. llvm-svn: 342601
* Adding the readability module to the list of dependencies for the C++ Core ↵Aaron Ballman2018-08-121-0/+1
| | | | | | Guidelines module. Amends r339516 for a failing bot. llvm-svn: 339517
* 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
* Port getLocEnd -> getEndLocStephen Kelly2018-08-093-3/+3
| | | | | | | | Subscribers: nemanjai, ioeric, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D50355 llvm-svn: 339401
* Port getLocStart -> getBeginLocStephen Kelly2018-08-096-28/+28
| | | | | | | | | | Reviewers: javed.absar Subscribers: nemanjai, kbarton, ilya-biryukov, ioeric, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50354 llvm-svn: 339400
* [clang-tidy] fix PR36489 - respect deduced pointer types from auto as wellJonas Toth2018-07-231-2/+6
| | | | | | | | | | | | | | | | | | | | Summary: The cppcoreguidelines-pro-bounds-pointer-arithmetic warns on all occassion where pointer arithmetic is used, but does not check values where the pointer types is deduced via `auto`. This patch adjusts this behaviour and solved PR36489. I accidentally commited a wrong patch, this Differential is meant to have a correct revision description and code attached to it. Because the patch was accepted by aaron.ballman already, i will just commit it. See https://reviews.llvm.org/D48717 for the old differntial (contains wrong code from the mixup) Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D49682 llvm-svn: 337716
* [clang-tidy] new cppcoreguidelines-narrowing-conversions check.Clement Courbet2018-05-234-0/+111
| | | | | | | | | | | | | | | | | | | 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
* [tidy] Move private ast matchers into anonymous namespaces to avoid ODR ↵Benjamin Kramer2018-02-182-0/+4
| | | | | | | | conflicts. No functionality change intended. llvm-svn: 325467
* Removed Unicode BOM.Alexander Kornienko2018-01-251-1/+1
| | | | llvm-svn: 323431
* [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init if ↵Malcolm Parsons2018-01-231-2/+3
| | | | | | | | | | | | | | | | | | using C++2a Summary: C++2a allows bitfields to have default member initializers. Add support for this to clang-tidy's cppcoreguidelines-pro-type-member-init check. Reviewers: aaron.ballman, alexfh Reviewed By: aaron.ballman Subscribers: klimek, nemanjai, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D42426 llvm-svn: 323227
* [clang-tidy] implement check for gotoJonas Toth2018-01-174-0/+95
| | | | | | | | | | | | | | | | | | | | 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] introduce legacy resource functions to ↵Jonas Toth2017-10-182-4/+91
| | | | | | | | | | | | | | | | | | | | | | | | | 'cppcoreguidelines-owning-memory' Summary: This patch introduces support for legacy C-style resource functions that must obey the 'owner<>' semantics. - added legacy creators like malloc,fopen,... - added legacy consumers like free,fclose,... This helps codes that mostly benefit from owner: Legacy, C-Style code that isn't feasable to port directly to RAII but needs a step in between to identify actual resource management and just using the resources. Reviewers: aaron.ballman, alexfh, hokein Reviewed By: aaron.ballman Subscribers: nemanjai, JDevlieghere, xazax.hun, kbarton Differential Revision: https://reviews.llvm.org/D38396 llvm-svn: 316092
* [clang-tidy] Emit note for variable declaration that are later deletedJonas Toth2017-10-041-4/+14
| | | | | | | | | | This patch introduces a note for variable declaration that are later deleted. Adds FIXME notes for possible automatic type-rewriting positions as well. Reviewed by aaron.ballman Differential: https://reviews.llvm.org/D38411 llvm-svn: 314913
* [clang-tidy] Implement type-based check for `gsl::owner`Jonas Toth2017-09-124-0/+364
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-124-363/+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-124-0/+363
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [cppcoreguidelines] Don't rely on SmallPtrSet iteration order.Benjamin Kramer2017-08-301-15/+14
| | | | | | | The fixit emission breaks if the iteration order changes and also missed to emit fixits for some edge cases. llvm-svn: 312166
* [clang-tidy] test commit for granted accessJonas Toth2017-08-301-1/+1
| | | | llvm-svn: 312102
* [clang-tidy] Unify the way IncludeStyle and HeaderFileExtesions options are usedAlexander Kornienko2017-07-201-1/+1
| | | | llvm-svn: 308605
* [clang-tidy] Resolve cppcoreguidelines-pro-type-member-init false positiveJonas Devlieghere2017-07-031-0/+3
| | | | | | | | | | | | | | | | Summary: https://bugs.llvm.org/show_bug.cgi?id=33557 Reviewers: Eugene.Zelenko, alexfh, aaron.ballman, hokein Reviewed By: aaron.ballman, hokein Subscribers: cfe-commits, nemanjai, xazax.hun, kbarton Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D34932 llvm-svn: 307040
* Spelling mistakes in comments. NFCI.Simon Pilgrim2017-03-301-3/+3
| | | | | | Based on corrections mentioned in patch for clang for PR27635 llvm-svn: 299074
* Reverting r298421 due to using a header that's unavailable to all systems ↵Aaron Ballman2017-03-221-23/+4
| | | | | | and some other post-commit review feedback. llvm-svn: 298470
* Apply clang-tidy's performance-unnecessary-value-param to clang-tidy.Benjamin Kramer2017-03-211-1/+1
| | | | | | No functionality change intended. llvm-svn: 298442
* Don't make unqualified calls to functions that could well be found viaChandler Carruth2017-03-211-2/+2
| | | | | | | | | | | | | | | ADL as reasonable extension points. All of this would be cleaner if this code followed the more usual LLVM convention of not having deeply nested namespaces inside of .cpp files and instead having a `using namespace ...;` at the top. Then the static function would be in the global namespace and easily referred to as `::join`. Instead we have to write a fairly contrived qualified name. I figure the authors can clean this up with a less ambiguous name, using the newly provided LLVM `join` function, or any other solution, but this at least fixes the build. llvm-svn: 298434
* Prevent cppcoreguidelines-pro-bounds-array-to-pointer-decay from diagnosing ↵Aaron Ballman2017-03-211-4/+23
| | | | | | | | array to pointer decay stemming from system macros. Patch by Breno Rodrigues Guimaraes. llvm-svn: 298421
* Add the 'AllowSoleDefaultDtor' and 'AllowMissingMoveFunctions' options to ↵Aaron Ballman2017-03-132-31/+92
| | | | | | | | the cppcoreguidelines-special-member-functions check. Patch by Florian Gross. llvm-svn: 297671
* [clang-tidy] Function names configurable for cppcoreguidelines-nomalloc - ↵Alexander Kornienko2017-03-022-9/+47
| | | | | | | | | | | | | | | | | | | | | | | | checker Summary: Hello everybody, this is an incremental patch for the NoMalloc-Checker I wrote. It allows to configure the memory-management functions, that are checked, This might be helpful for a code base with custom functions in use, or non-standard functionality, like posix_memalign. Reviewers: aaron.ballman, hokein, alexfh Reviewed By: aaron.ballman, alexfh Subscribers: sbenza, nemanjai, JDevlieghere Tags: #clang-tools-extra Patch by Jonas Toth! Differential Revision: https://reviews.llvm.org/D28239 llvm-svn: 296734
OpenPOWER on IntegriCloud