From 118ad67645c19fe77ed8259097bb523e9fe4e1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 12 Jun 2021 16:43:48 +0200 Subject: [PATCH] testrunner: return value in non-void functions --- test/testfunctions.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 4ee234c4b..9f1a075eb 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -141,11 +141,12 @@ private: void prohibitedFunctions_index() { check("namespace n1 {\n" - " int index(){};\n" + " int index(){ return 1; };\n" "}\n" "int main()\n" "{\n" " n1::index();\n" + " return 0;\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -303,11 +304,12 @@ private: "{\n" " char s [ 10 ] ;\n" " gets ( s ) ;\n" + " return 0;\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str()); check("int getcontext(ucontext_t *ucp);\n" - "int f (ucontext_t *ucp)\n" + "void f (ucontext_t *ucp)\n" "{\n" " getcontext ( ucp ) ;\n" "}"); @@ -320,6 +322,7 @@ private: "{\n" " char s [ 10 ] ;\n" " gets ( s ) ;\n" + " return 0;\n" "}"); ASSERT_EQUALS("", errout.str()); } @@ -351,7 +354,7 @@ private: } void prohibitedFunctions_namespaceHandling() { - check("int f()\n" + check("void f()\n" "{\n" " time_t t = 0;" " std::localtime(&t);\n" @@ -359,14 +362,14 @@ private: ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str()); // Passed as function argument - check("int f()\n" + check("void f()\n" "{\n" " printf(\"Magic guess: %d\", getpwent());\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str()); // Pass return value - check("int f()\n" + check("void f()\n" "{\n" " time_t t = 0;" " struct tm *foo = localtime(&t);\n" @@ -374,7 +377,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str()); // Access via global namespace - check("int f()\n" + check("void f()\n" "{\n" " ::getpwent();\n" "}"); @@ -389,14 +392,14 @@ private: ASSERT_EQUALS("", errout.str()); // Be quiet on other namespaces - check("int f()\n" + check("void f()\n" "{\n" " foobar::getpwent();\n" "}"); ASSERT_EQUALS("", errout.str()); // Be quiet on class member functions - check("int f()\n" + check("void f()\n" "{\n" " foobar.getpwent();\n" "}"); @@ -404,19 +407,19 @@ private: } void invalidFunctionUsage1() { - check("int f() { memset(a,b,sizeof(a)!=12); }"); + check("void f() { memset(a,b,sizeof(a)!=12); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str()); - check("int f() { memset(a,b,sizeof(a)!=0); }"); + check("void f() { memset(a,b,sizeof(a)!=0); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str()); - check("int f() { memset(a,b,!c); }"); + check("void f() { memset(a,b,!c); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str()); // Ticket #6990 - check("int f(bool c) { memset(a,b,c); }"); + check("void f(bool c) { memset(a,b,c); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str()); - check("int f() { memset(a,b,true); }"); + check("void f() { memset(a,b,true); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str()); // Ticket #6588 (c mode) @@ -443,10 +446,10 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'.\n", errout.str()); - check("int f() { strtol(a,b,1); }"); + check("void f() { strtol(a,b,1); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'.\n", errout.str()); - check("int f() { strtol(a,b,10); }"); + check("void f() { strtol(a,b,10); }"); ASSERT_EQUALS("", errout.str()); } @@ -1210,6 +1213,7 @@ private: " teststruct TestStruct1;\n" " TestStruct1.testfunc1();\n" " TestStruct1.testfunc2();\n" + " return 0;\n" "}", "test.cpp", &settings2); ASSERT_EQUALS("[test.cpp:4]: (warning) Return value of function testfunc1() is not used.\n" "[test.cpp:4]: (warning) Return value of function testfunc2() is not used.\n"