You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const std::string message = "Behaviour of 'sizeof(void)' is not covered by the ISO C standard.";
307
+
const std::string verbose = message + " A value for 'sizeof(void)' is defined only as part of a GNU C extension, which defines 'sizeof(void)' to be 1.";
const std::string message = "'*" + varname + "' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard.";
314
+
const std::string verbose = message + " A value for 'sizeof(void)' is defined only as part of a GNU C extension, which defines 'sizeof(void)' to be 1.";
Copy file name to clipboardExpand all lines: test/testsizeof.cpp
+46Lines changed: 46 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,7 @@ class TestSizeof : public TestFixture {
39
39
TEST_CASE(sizeofForArrayParameter);
40
40
TEST_CASE(sizeofForNumericParameter);
41
41
TEST_CASE(suspiciousSizeofCalculation);
42
+
TEST_CASE(sizeofVoid);
42
43
}
43
44
44
45
voidcheck(constchar code[]) {
@@ -47,6 +48,7 @@ class TestSizeof : public TestFixture {
47
48
48
49
Settings settings;
49
50
settings.addEnabled("warning");
51
+
settings.addEnabled("portability");
50
52
settings.inconclusive = true;
51
53
52
54
// Tokenize..
@@ -488,6 +490,50 @@ class TestSizeof : public TestFixture {
488
490
"}");
489
491
ASSERT_EQUALS("", errout.str());
490
492
}
493
+
494
+
voidsizeofVoid() {
495
+
check("void f() {\n"
496
+
" int size = sizeof(void);\n"
497
+
"}");
498
+
ASSERT_EQUALS("[test.cpp:2]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard.\n", errout.str());
499
+
500
+
check("void f() {\n"
501
+
" void* p;\n"
502
+
" int size = sizeof(*p);\n"
503
+
"}");
504
+
ASSERT_EQUALS("[test.cpp:3]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard.\n", errout.str());
505
+
506
+
check("void f() {\n"
507
+
" void* p = malloc(10);\n"
508
+
" int* p2 = p + 4;\n"
509
+
" int* p3 = p - 1;\n"
510
+
"}");
511
+
ASSERT_EQUALS("[test.cpp:3]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
512
+
"[test.cpp:4]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
513
+
514
+
check("void f() {\n"
515
+
" void* p1 = malloc(10);\n"
516
+
" void* p2 = malloc(5);\n"
517
+
" p1--;\n"
518
+
" p2++;\n"
519
+
"}");
520
+
ASSERT_EQUALS("[test.cpp:4]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
521
+
"[test.cpp:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
0 commit comments