From e0846b7abe78e55bc1e959143d980208077b13ca Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 23 Nov 2017 10:39:41 +0200 Subject: loplugin:simplifybool can't invert conditions involving float types so revert some of the changes from commit 7a1c21e53fc4733a4bb52282ce0098fcc085ab0e loplugin:simplifybool for negation of comparison operator Change-Id: I937d575b86c1e418805d399b0dc16ae91876b4fe Reviewed-on: https://gerrit.libreoffice.org/45130 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- compilerplugins/clang/simplifybool.cxx | 4 ++++ compilerplugins/clang/test/simplifybool.cxx | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/simplifybool.cxx b/compilerplugins/clang/simplifybool.cxx index 260946a5fd98..9167014f8c84 100644 --- a/compilerplugins/clang/simplifybool.cxx +++ b/compilerplugins/clang/simplifybool.cxx @@ -142,6 +142,10 @@ bool SimplifyBool::VisitUnaryLNot(UnaryOperator const * expr) { // RecordType would require more smarts - we'd need to verify that an inverted operator actually existed if (t->isTemplateTypeParmType() || t->isRecordType() || t->isDependentType()) return true; + // for floating point (with NaN) !(x=y + if (t->isFloatingType() || + binaryOp->getRHS()->IgnoreImpCasts()->getType()->getUnqualifiedDesugaredType()->isFloatingType()) + return true; if (!binaryOp->isComparisonOp()) return true; report( diff --git a/compilerplugins/clang/test/simplifybool.cxx b/compilerplugins/clang/test/simplifybool.cxx index e6b52c33f3b6..2cb2e810c110 100644 --- a/compilerplugins/clang/test/simplifybool.cxx +++ b/compilerplugins/clang/test/simplifybool.cxx @@ -15,7 +15,16 @@ void f1(int a, int b) } }; -// Consitently either warn about all or none of the below occurrences of "!!": +void f2(float a, float b) +{ + // no warning expected + if (!(a < b)) + { + a = b; + } +}; + +// Consistently either warn about all or none of the below occurrences of "!!": enum E1 { -- cgit