From e5745d7d4a9f779ca9bd1ba703086544c071c260 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 12 Apr 2015 14:51:57 +0200 Subject: [PATCH] Restore build with libc++ and revert PR#228 and PR#562. --- lib/checkio.cpp | 2 +- lib/checkstl.cpp | 2 +- lib/library.h | 2 +- lib/mathlib.cpp | 2 ++ test/testsuite.cpp | 14 +++----------- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 115b95d3b..448d32378 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -533,7 +533,7 @@ void CheckIO::checkWrongPrintfScanfArguments() if (Token::Match(tok->next(), "( %any%") && _settings->library.formatstr_function(tok->str())) { const std::map& argumentChecks = _settings->library.argumentChecks.at(tok->str()); - for (std::map::const_iterator i = argumentChecks.begin(); i != argumentChecks.end(); ++i) { + for (std::map::const_iterator i = argumentChecks.cbegin(); i != argumentChecks.cend(); ++i) { if (i->second.formatstr) { formatStringArgNo = i->first - 1; break; diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 4e13810cf..53a87cd82 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1260,7 +1260,7 @@ void CheckStl::checkAutoPointer() } if (Token::Match(tok3, "( %var%")) { std::map::const_iterator it = mallocVarId.find(tok3->next()->varId()); - if (it != mallocVarId.end()) { + if (it != mallocVarId.cend()) { // pointer on the memory allocated by malloc used in the auto pointer constructor -> error autoPointerMallocError(tok2->next(), it->second); } diff --git a/lib/library.h b/lib/library.h index 20e153670..83ce7d9e0 100644 --- a/lib/library.h +++ b/lib/library.h @@ -107,7 +107,7 @@ public: } bool formatstr_function(const std::string& funcname) const { - return _formatstr.find(funcname) != _formatstr.end(); + return _formatstr.find(funcname) != _formatstr.cend(); } bool formatstr_scan(const std::string& funcname) const { diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 8d7c5c4ac..b753387ad 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -143,6 +143,8 @@ double MathLib::toDoubleNumber(const std::string &str) // nullcheck else if (isNullValue(str)) return 0.0; + else if (isFloat(str)) // Workaround libc++ bug at http://llvm.org/bugs/show_bug.cgi?id=17782 + return std::strtod(str.c_str(), 0); // otherwise, convert to double std::istringstream istr(str); double ret; diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 1ecba779b..aecdaa236 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -170,20 +170,12 @@ void TestFixture::assertEquals(const char *filename, unsigned int linenr, const void TestFixture::assertEquals(const char *filename, unsigned int linenr, long long expected, long long actual, const std::string &msg) const { - std::ostringstream ostr1; - ostr1 << expected; - std::ostringstream ostr2; - ostr2 << actual; - assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg); + assertEquals(filename, linenr, MathLib::toString(expected), MathLib::toString(actual), msg); } void TestFixture::assertEqualsDouble(const char *filename, unsigned int linenr, double expected, double actual, const std::string &msg) const { - std::ostringstream ostr1; - ostr1 << expected; - std::ostringstream ostr2; - ostr2 << actual; - assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg); + assertEquals(filename, linenr, MathLib::toString(expected), MathLib::toString(actual), msg); } void TestFixture::todoAssertEquals(const char *filename, unsigned int linenr, @@ -301,7 +293,7 @@ std::size_t TestFixture::runTests(const options& args) if (!missingLibs.empty()) { std::cerr << "Missing libraries: "; - for (std::set::const_iterator i = missingLibs.begin(); i != missingLibs.end(); ++i) + for (std::set::const_iterator i = missingLibs.cbegin(); i != missingLibs.cend(); ++i) std::cerr << *i << " "; std::cerr << std::endl << std::endl; }