aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
diff options
context:
space:
mode:
authorJens Massberg <massberg@google.com>2022-11-25 17:18:03 +0100
committerJens Massberg <massberg@google.com>2022-11-29 11:56:10 +0100
commit849b650cf3b60e60f5e3a6457fe52e9c63e76e4c (patch)
tree3fdc69708be90503ebab38a746fd88803ff3533e /clang/lib/Sema/Sema.cpp
parente9393789a9fa95ea1d7df71aa8f164f043d7da33 (diff)
downloadllvm-849b650cf3b60e60f5e3a6457fe52e9c63e76e4c.zip
llvm-849b650cf3b60e60f5e3a6457fe52e9c63e76e4c.tar.gz
llvm-849b650cf3b60e60f5e3a6457fe52e9c63e76e4c.tar.bz2
[clang] Skip defaulted functions in zero-as-null-pointer-constant.
The zero-as-null-pointer-constant check should not fire if it is inside a defaulted function, e.g. defaulted spaceship operators. Add C++20 tests with spaceship operators. Fixes #50221 Differential Revision: https://reviews.llvm.org/D138727
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r--clang/lib/Sema/Sema.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index c229a77..ad53e87 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -597,6 +597,12 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) {
CodeSynthesisContext::RewritingOperatorAsSpaceship)
return;
+ // Ignore null pointers in defaulted comparison operators.
+ FunctionDecl *FD = getCurFunctionDecl();
+ if (FD && FD->isDefaulted()) {
+ return;
+ }
+
// If it is a macro from system header, and if the macro name is not "NULL",
// do not warn.
SourceLocation MaybeMacroLoc = E->getBeginLoc();