summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/check.cxx10
-rw-r--r--compilerplugins/clang/check.hxx2
-rw-r--r--compilerplugins/clang/nullptr.cxx9
-rw-r--r--compilerplugins/clang/test/nullptr.cxx6
4 files changed, 26 insertions, 1 deletions
diff --git a/compilerplugins/clang/check.cxx b/compilerplugins/clang/check.cxx
index 4ff081b6923e..60e476cc37b7 100644
--- a/compilerplugins/clang/check.cxx
+++ b/compilerplugins/clang/check.cxx
@@ -133,6 +133,16 @@ TypeCheck TypeCheck::Pointer() const {
return TypeCheck();
}
+TypeCheck TypeCheck::MemberPointerOf() const {
+ if (!type_.isNull()) {
+ auto const t = type_->getAs<clang::MemberPointerType>();
+ if (t != nullptr) {
+ return TypeCheck(t->getClass());
+ }
+ }
+ return TypeCheck();
+}
+
TerminalCheck TypeCheck::Enum() const {
if (!type_.isNull()) {
auto const t = type_->getAs<clang::EnumType>();
diff --git a/compilerplugins/clang/check.hxx b/compilerplugins/clang/check.hxx
index af6cd355a416..65ee16d77f2c 100644
--- a/compilerplugins/clang/check.hxx
+++ b/compilerplugins/clang/check.hxx
@@ -62,6 +62,8 @@ public:
TypeCheck Pointer() const;
+ TypeCheck MemberPointerOf() const;
+
TerminalCheck Enum() const;
TypeCheck LvalueReference() const;
diff --git a/compilerplugins/clang/nullptr.cxx b/compilerplugins/clang/nullptr.cxx
index 0213b6b05c88..04fb5bf0f9fd 100644
--- a/compilerplugins/clang/nullptr.cxx
+++ b/compilerplugins/clang/nullptr.cxx
@@ -131,11 +131,18 @@ bool Nullptr::VisitImplicitCastExpr(CastExpr const * expr) {
case Expr::NPCK_CXX11_nullptr:
break;
default:
- if (loplugin::TypeCheck(expr->getType()).Typedef("locale_t")
+ auto const tc = loplugin::TypeCheck(expr->getType());
+ if (tc.Typedef("locale_t")
.GlobalNamespace())
{
break; // POSIX locale_t is left unspecified
}
+ // Hack to handle libc++ and stdlibc++ `std::strong_ordering x; x < 0` etc.:
+ if (tc.MemberPointerOf().ClassOrStruct("_CmpUnspecifiedParam").StdNamespace()
+ || tc.Pointer().ClassOrStruct("__unspec").Namespace("__cmp_cat").StdNamespace())
+ {
+ break;
+ }
handleNull(expr->getSubExpr(), expr->getCastKindName(), k);
break;
}
diff --git a/compilerplugins/clang/test/nullptr.cxx b/compilerplugins/clang/test/nullptr.cxx
index bf7376cb6562..392a930bf9b8 100644
--- a/compilerplugins/clang/test/nullptr.cxx
+++ b/compilerplugins/clang/test/nullptr.cxx
@@ -7,6 +7,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include "sal/config.h"
+
+#include <compare>
+
struct S
{
void* p;
@@ -18,6 +22,8 @@ int main()
0 // expected-error {{NullToPointer ValueDependentIsNotNull ZeroLiteral -> nullptr [loplugin:nullptr]}}
};
(void)s;
+
+ (void)(std::strong_order(0, 1) < 0);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */