From bac1dfce863f75979c2a59162f5daa0b26739799 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Mon, 22 Dec 2014 09:59:34 +0100 Subject: [PATCH] Add test cases when sizeof is used on struct members --- test/testsizeof.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 626d18bfb..edf48d0e5 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -509,6 +509,22 @@ private: " memset( ptr->bar, 0, sizeof ptr->bar );\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " struct foo {\n" + " char bar[10];\n" + " };\n" + " memset( ptr->bar, 0, sizeof ptr->bar );\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " struct foo {\n" + " char *bar;\n" + " };\n" + " memset( ptr->bar, 0, sizeof ptr->bar );\n" + "}"); + TODO_ASSERT_EQUALS("[test.cpp:5]: (warning) Size of pointer 'bar' used instead of size of its data.\n", "", errout.str()); } void sizeofDivisionMemset() {