aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-09[clang-tidy][NFC] run clang-format over clang-tidy checks and tool code. ↵Baranov Victor1-1/+1
(#143324)
2025-03-21Reland: [clang] preserve class type sugar when taking pointer to member ↵Matheus Izvekov1-2/+1
(#132401) Original PR: #130537 Originally reverted due to revert of dependent commit. Relanding with no changes. This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the base class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntatically, and they represent the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements.
2025-03-20Revert "Reland: [clang] preserve class type sugar when taking pointer to ↵Matheus Izvekov1-1/+2
member" (#132280) Reverts llvm/llvm-project#132234 Needs to be reverted due to dependency. This blocks reverting another PR, see here: https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-20Reland: [clang] preserve class type sugar when taking pointer to member ↵Matheus Izvekov1-2/+1
(#132234) Original PR: #130537 Reland after updating lldb too. This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the base class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntatically, and they represent the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements.
2025-03-20Revert "[clang] improve class type sugar preservation in pointers to ↵Matheus Izvekov1-1/+2
members" (#132215) Reverts llvm/llvm-project#130537 This missed updating lldb, which we didn't notice due to lack of pre-commit CI.
2025-03-20[clang] improve class type sugar preservation in pointers to members (#130537)Matheus Izvekov1-2/+1
This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntactically, and it also represents the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements, and removing some duplications, for example CheckBaseClassAccess is deduplicated from across SemaAccess and SemaCast.
2024-09-25[clang-tidy] modernize-use-nullptr matches "NULL" in templates (#109169)Thomas Köppe1-1/+11
Make modernize-use-nullptr matcher also match "NULL", but not "0", when it appears on a substituted type of a template specialization. Previously, any matches on a substituted type were excluded, but this meant that a situation like the following is not diagnosed: ```c++ template <typename T> struct X { T val; X() { val = NULL; } // should diagnose }; ``` When the user says `NULL`, we expect that the destination type is always meant to be a pointer type, so this should be converted to `nullptr`. By contrast, we do not propose changing a literal `0` in that case, which appears as initializers of both pointer and integer specializations in reasonable real code. (If `NULL` is used erroneously in such a situation, it should be changed to `0` or `{}`.)
2023-09-10[clang-tidy] Add IgnoreTypes option to modernize-use-nullptrPiotr Zegar1-5/+14
New option added and configured in a way, so types related to std::strong_ordering would be ignored. Fixes: #63478 Reviewed By: ccotter Differential Revision: https://reviews.llvm.org/D158928
2023-08-27[clang-tidy][NFC] Fix modernize-use-default-member-init findingsPiotr Zegar1-9/+7
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27[clang-tidy][NFC] Fix readability-redundant-access-specifiers findingsPiotr Zegar1-1/+0
Fix issues found by clang-tidy in clang-tidy source directory.
2023-02-15[clang-tidy][NFC] Remove ModernizeTidyModule::getModuleOptionsCarlos Galvez1-1/+1
Most of the options stated there are duplicated already in the implementation of each check as a default value for each option. The only place where this is not the case is the nullptr check. Move the default option there instead. Only the HICPP guidelines alias this modernize check, and there is nothing in the documentation that suggests it should have a different default value than the main modernize check. Differential Revision: https://reviews.llvm.org/D143843
2023-01-14[clang-tidy][NFC] Use C++17 nested namespaces in the clang-tidy folderCarlos Galvez1-6/+2
Fix applied by running: run-clang-tidy.py -checks=-*,modernize-concat-nested-namespaces Differential Revision: https://reviews.llvm.org/D141770
2022-11-25[clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls ↵Jens Massberg1-1/+3
in modernize-use-nullptr The check has produced false positives when checking the default implementation of the spaceship operator. The default implementation should be skipped by the check. Modified the existing test so that the check runs into the bug without this fix and add another test case. Fixes #53961. Patch by Jens Massberg. Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D138701
2021-02-09[clang-tidy] fix modernize-use-nullptr false positive with spaceship ↵poelmanc1-4/+25
operator comparisons `clang-tidy -std=c++20` with `modernize-use-nullptr` mistakenly inserts `nullptr` in place of the comparison operator if the comparison internally expands in the AST to a rewritten spaceship operator. This can be reproduced by running the new `modernize-use-nullptr-cxx20.cpp` test without applying the supplied patch to `UseNullptrCheck.cpp`; the current clang-tidy will mistakenly replace: ```result = (a1 < a2);``` with ```result = (a1 nullptr a2);``` Reviewed By: njames93 Differential Revision: https://reviews.llvm.org/D95714
2021-01-29[clang-tidy] Applied clang-tidy fixes. NFCAlexander Kornienko1-2/+2
Applied fixes enabled by the LLVM's .clang-tidy configs. Reverted files where fixes introduced compile errors: clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp $ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -fix clang-tools-extra/clang-tidy/ Enabled checks: llvm-else-after-return llvm-header-guard llvm-include-order llvm-namespace-comment llvm-prefer-isa-or-dyn-cast-in-conditionals llvm-prefer-register-over-unsigned llvm-qualified-auto llvm-twine-local misc-definitions-in-headers misc-misplaced-const misc-new-delete-overloads misc-no-recursion misc-non-copyable-objects misc-redundant-expression misc-static-assert misc-throw-by-value-catch-by-reference misc-unconventional-assign-operator misc-uniqueptr-reset-release misc-unused-alias-decls misc-unused-using-decls readability-identifier-naming Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D95614
2020-12-11Remove references to the ast_type_traits namespaceAlexander Kornienko1-9/+7
Follow up to cd62511496938e33c061c90796dd23a5288ff843 / https://reviews.llvm.org/D74499 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D92994
2020-05-21Set traversal explicitly where needed in clang-tidyStephen Kelly1-4/+6
Reviewers: aaron.ballman Subscribers: nemanjai, kbarton, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72530
2020-04-05[clang-tools-extra] NFC: Fix trivial typo in documents and commentsKazuaki Ishizaki1-1/+1
Differential Revision: https://reviews.llvm.org/D77458
2020-03-03[clang-tidy] Change checks to use new isLanguageVersionSupported restrictionNathan James1-5/+1
Summary: Modifies all checks that are language version dependent to use `isLanguageVersionSupported` Reviewers: jdoerfert, lebedev.ri, aaron.ballman, gribozavr2, Eugene.Zelenko Reviewed By: gribozavr2 Subscribers: wuzish, nemanjai, xazax.hun, hiraditya, kbarton, steven_wu, dexonsmith, arphaman, lebedev.ri, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75340
2020-01-04NFC: Fix trivial typos in commentsKazuaki Ishizaki1-1/+1
2019-08-22Remove \brief commands from doxygen comments.Dmitri Gribenko1-9/+9
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
2019-07-13Simplify with llvm::is_contained. NFCFangrui Song1-5/+2
llvm-svn: 365993
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-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
2018-08-09Port getLocEnd -> getEndLocStephen Kelly1-1/+1
Subscribers: nemanjai, ioeric, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D50355 llvm-svn: 339401
2018-08-09Port getLocStart -> getBeginLocStephen Kelly1-5/+5
Reviewers: javed.absar Subscribers: nemanjai, kbarton, ilya-biryukov, ioeric, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50354 llvm-svn: 339400
2018-04-30Fix up after clang r331155.Richard Smith1-2/+2
llvm-svn: 331156
2018-02-02[clang-tidy] Kill marco. No functionality change.Benjamin Kramer1-3/+3
llvm-svn: 324084
2017-06-29[clang-tidy] Fix modernize-use-nullptr only warns the first NULL argument.Haojian Wu1-1/+1
Reviewers: alexfh Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34526 llvm-svn: 306651
2017-06-23[clang-tidy] Fix a false positive in modernize-use-nullptr.Haojian Wu1-5/+7
Summary: The FP happens when a casting nullptr expression is used within a NULL-default-arguemnt cxx constructor. Before the fix, the check will give a warning on nullptr when running with the test case, which should not happen: ``` G(g(static_cast<char*>(nullptr))); ^~~~~~~~~~~ nullptr ``` Reviewers: alexfh Reviewed By: alexfh Subscribers: cfe-commits, xazax.hun Differential Revision: https://reviews.llvm.org/D34524 llvm-svn: 306091
2017-03-06[clang-tidy] Ignore substituted template types in modernize-use-nullptr check.Haojian Wu1-0/+1
Reviewers: alexfh Reviewed By: alexfh Subscribers: xazax.hun, malcolm.parsons, JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D30639 llvm-svn: 297009
2017-02-28[clang-tidy] Fix a false positive on modernize-use-nullptr check.Haojian Wu1-1/+3
Summary: The false positive happens on two neighbour CXXDefaultArgExpr AST nodes. like below: ``` CXXFunctionalCastExpr 0x85c9670 <col:7, col:23> 'struct ZZ' functional cast to struct ZZ <ConstructorConversion> `-CXXConstructExpr 0x85c9518 <col:7, col:23> 'struct ZZ' 'void (uint64, const uint64 *)' |-CallExpr 0x85a0a90 <col:10, col:22> 'uint64':'unsigned long long' | |-ImplicitCastExpr 0x85a0a78 <col:10> 'uint64 (*)(uint64)' <FunctionToPointerDecay> | | `-DeclRefExpr 0x85a09f0 <col:10> 'uint64 (uint64)' lvalue Function 0x85a06a0 'Hash' 'uint64 (uint64)' | `-CXXDefaultArgExpr 0x85a0ac8 <<invalid sloc>> 'uint64':'unsigned long long' `-CXXDefaultArgExpr 0x85c94f8 <<invalid sloc>> 'const uint64 *' ``` For each particular CXXDefaultArgExpr node, we need to reset FirstSubExpr, otherwise FirstSubExpr will refer to an incorrect expr. Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D30412 llvm-svn: 296479
2016-12-14modernize-use-auto NFC fixesPiotr Padlewski1-2/+2
llvm-svn: 289656
2016-11-08[clang-tools-extra] Format sources with clang-format. NFC.Mandeep Singh Grang1-2/+1
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
2016-11-07[clang-tidy] Fix a regression issue introduced by r285239.Haojian Wu1-0/+8
Summary: r285239 changes the behavior of AST CXXDefaultArgExpr node. Update `modernize-use-nullptr` to handle CXXDefaultArgExpr correctly. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26301 llvm-svn: 286156
2016-05-17[clang-tidy] Lift common matchers to utils namespaceEtienne Bergeron1-15/+2
Summary: This patch is lifting matchers used by more than one checkers to the common namespace. Reviewers: aaron.ballman, alexfh Subscribers: aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D19841 llvm-svn: 269804
2016-03-11[clang-tidy] Make 'modernize-use-nullptr' check ignores NULL marcos used in ↵Haojian Wu1-0/+6
other macros. Reviewers: bkramer, alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17958 llvm-svn: 263221
2016-03-04[clang-tidy] Make 'modernize-use-nullptr' check work on multiple nested ↵Haojian Wu1-1/+1
implicit cast expressions. Summary: For some test cases like: ``` int func(int, void*, void*); (double)func(0, 0, 0); ``` The AST contains several `ImplicitCastExpr`s, so we should not only check on the first sub expression. ``` `-CStyleCastExpr 0x7fe43a088938 <line:6:3, col:24> 'double' <NoOp> `-ImplicitCastExpr 0x7fe43a088920 <col:11, col:24> 'double' <IntegralToFloating> `-CallExpr 0x7fe43a0888a0 <col:11, col:24> 'int' |-ImplicitCastExpr 0x7fe43a088888 <col:11> 'int (*)(int, void *, void *)' <FunctionToPointerDecay> | `-DeclRefExpr 0x7fe43a0887d8 <col:11> 'int (int, void *, void *)' lvalue Function 0x7fe43a0886f0 'func1' 'int (int, void *, void *)' |-IntegerLiteral 0x7fe43a088800 <col:17> 'int' 0 |-ImplicitCastExpr 0x7fe43a0888e0 <col:20> 'void *' <NullToPointer> | `-IntegerLiteral 0x7fe43a088820 <col:20> 'int' 0 `-ImplicitCastExpr 0x7fe43a0888f8 <col:23> 'void *' <NullToPointer> `-IntegerLiteral 0x7fe43a088840 <col:23> 'int' 0 ``` Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17849 llvm-svn: 262698
2016-02-26[clang-tidy] Fix an assertion failure in `modernize-use-nullptr` check.Haojian Wu1-1/+1
Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17640 llvm-svn: 262024
2015-11-02Remove unreachable that was reached in modernize-use-nullptr.Angel Garcia Gomez1-5/+7
Summary: When traversing the parent map, the check assumed that all the nodes would be either Stmt or Decl. After r251101, this is no longer true: there can be TypeLoc and NestedNameSpecifierLoc nodes. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D14229 llvm-svn: 251803
2015-10-05Fix bug in modernize-use-nullptr.Angel Garcia Gomez1-7/+24
Summary: https://llvm.org/bugs/show_bug.cgi?id=24960 modernize-use-nullptr would hit an assertion in some cases involving macros and initializer lists, due to finding a node with more than one parent (the two forms of the initializer list). However, this doesn't mean that the replacement is incorrect, so instead of just rejecting this case I tried to find a way to make it work. Looking at the semantic form of the InitListExpr made sense to me (looking at both forms results in false negatives) but I am not sure of the things that we can miss by skipping the syntactic form. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D13246 llvm-svn: 249291
2015-08-28Reapplying r246209, which exposed language options to the checkers. This ↵Aaron Ballman1-1/+5
time disable UseNullptrCheck when not compiling in C++ mode, but still allow in C++11 mode since it's likely the user wishes to modernize their code. llvm-svn: 246298
2015-08-27Reverting r246209 while I investigate a build bot failure: ↵Aaron Ballman1-3/+1
http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/30516 llvm-svn: 246224
2015-08-27Expose language options to the checkers; disable UseNullptrCheck when not ↵Aaron Ballman1-1/+3
compiling in C++11 mode. llvm-svn: 246209
2015-08-21Test commit!Angel Garcia Gomez1-0/+1
llvm-svn: 245701
2015-08-20[clang-tidy] Fold the meat of the UseNullPtrCheck into an anonymous namespace.Benjamin Kramer1-0/+2
While convenient, RecursiveASTVisitor generates a ridiculous amount of dead template code. Making it not visible from the outside lets the compiler eliminate some of it, shrinking clang-tidy by ~140k. llvm-svn: 245548
2015-08-20[clang-tidy] Add back a test with a custom NULL macro. Remove redundant default.Alexander Kornienko1-1/+1
llvm-svn: 245533
2015-08-19[clang-tidy] Fix use-after-free in UseNullptrCheck.Alexander Kornienko1-6/+4
llvm-svn: 245524
2015-08-19[clang-tidy] Work around failure in Darwin.Alexander Kornienko1-1/+1
llvm-svn: 245517
2015-08-19[clang-tidy] Add modernize-use-nullptr check, attempt 2.Alexander Kornienko1-0/+471
This patch re-applies r245434 and r245471 reverted in r245493, and changes the way custom null macros are configured. The test for custom null macros is temporarily excluded and will be committed separately to reduce chances of breakages. Initial patches by Angel Garcia. llvm-svn: 245511
2015-08-19Revert "[clang-tidy] Add use-nullptr check to clang-tidy."Justin Bogner1-472/+0
The new test is failing on darwin: http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/10339/ This reverts r245434 and its follow up r245471. llvm-svn: 245493