From 324e2675599d18bda072c7429b4f5e95b6ea28e6 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Wed, 11 Nov 2020 22:51:17 +0100 Subject: [PATCH] getSizeOf: Handle long double (#2888) --- lib/valueflow.cpp | 2 ++ test/testvalueflow.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 48deb053a..75fee38a9 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -948,6 +948,8 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings *settings) return settings->sizeof_float; if (vt.type == ValueType::Type::DOUBLE) return settings->sizeof_double; + if (vt.type == ValueType::Type::LONGDOUBLE) + return settings->sizeof_long_double; return 0; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 9b0a9797e..760af450a 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -872,15 +872,16 @@ private: ASSERT_EQUALS(1U, values.size()); ASSERT_EQUALS(4, values.back().intvalue); -#define CHECK(A, B) \ +#define CHECK3(A, B, C) \ do { \ code = "void f() {\n" \ " x = sizeof(" A ");\n" \ "}"; \ - values = tokenValues(code,"( " A " )"); \ + values = tokenValues(code,"( " C " )"); \ ASSERT_EQUALS(1U, values.size()); \ ASSERT_EQUALS(B, values.back().intvalue);\ } while(false) +#define CHECK(A, B) CHECK3(A, B, A) // standard types CHECK("void *", settings.sizeof_pointer); @@ -888,7 +889,11 @@ private: CHECK("short", settings.sizeof_short); CHECK("int", settings.sizeof_int); CHECK("long", settings.sizeof_long); + CHECK3("long long", settings.sizeof_long_long, "long"); CHECK("wchar_t", settings.sizeof_wchar_t); + CHECK("float", settings.sizeof_float); + CHECK("double", settings.sizeof_double); + CHECK3("long double", settings.sizeof_long_double, "double"); // string/char literals CHECK("\"asdf\"", 5); @@ -903,6 +908,7 @@ private: CHECK("u'a'", 2U); // char16_t CHECK("U'a'", 4U); // char32_t #undef CHECK +#undef CHECK3 // array size code = "void f() {\n"