From d1419b7f0779e7e1830c774f13da6c3a3f62a86f Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 16 May 2025 22:40:55 +0200 Subject: [PATCH 1/3] TestFunctions: added errors IDs and columns to expected output --- test/testfunctions.cpp | 550 ++++++++++++++++++++--------------------- 1 file changed, 275 insertions(+), 275 deletions(-) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 097a34c7566..f78356395f7 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -36,7 +36,7 @@ class TestFunctions : public TestFixture { certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library("std.cfg").library("posix.cfg").build(); void run() override { - // TODO: mNewTemplate = true; + mNewTemplate = true; // Prohibited functions TEST_CASE(prohibitedFunctions_posix); TEST_CASE(prohibitedFunctions_index); @@ -138,7 +138,7 @@ class TestFunctions : public TestFixture { "{\n" " bsd_signal(SIGABRT, SIG_IGN);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\n", errout_str()); check("int f()\n" "{\n" @@ -154,7 +154,7 @@ class TestFunctions : public TestFixture { " exit(1);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\n", errout_str()); check("void f()\n" "{\n" @@ -164,13 +164,13 @@ class TestFunctions : public TestFixture { " exit(1);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\n", errout_str()); check("void f()\n" "{\n" " usleep( 1000 );\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\n", errout_str()); } void prohibitedFunctions_index() { @@ -210,7 +210,7 @@ class TestFunctions : public TestFixture { " const char i = index(var, 0);\n" " return i;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n", + ASSERT_EQUALS("[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\n", errout_str()); } @@ -219,8 +219,8 @@ class TestFunctions : public TestFixture { " emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n" - "[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n", // duplicate + "[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\n" + "[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\n", // duplicate errout_str()); } @@ -236,7 +236,7 @@ class TestFunctions : public TestFixture { " const char var[7] = \"rindex\";\n" " print(rindex(var, 0));\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\n", errout_str()); } @@ -254,13 +254,13 @@ class TestFunctions : public TestFixture { "{\n" " char *x = gets(a);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str()); check("void f()\n" "{\n" " foo(x, gets(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str()); } void prohibitedFunctions_alloca() { @@ -268,13 +268,13 @@ class TestFunctions : public TestFixture { "{\n" " char *x = alloca(10);\n" "}"); // #4382 - there are no VLAs in C++ - ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'alloca' called.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\n", errout_str()); check("void f()\n" "{\n" " char *x = alloca(10);\n" "}", dinit(CheckOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead.\n", errout_str()); + ASSERT_EQUALS("[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\n", errout_str()); const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build(); check("void f()\n" @@ -317,8 +317,8 @@ class TestFunctions : public TestFixture { " char *x = std::gets(str);\n" " char *y = gets(str);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n" - "[test.cpp:4]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n" + "[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str()); } // multiple use @@ -328,8 +328,8 @@ class TestFunctions : public TestFixture { " char *x = std::gets(str);\n" " usleep( 1000 );\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n" - "[test.cpp:4]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n" + "[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\n", errout_str()); } void prohibitedFunctions_c_declaration() { @@ -340,14 +340,14 @@ class TestFunctions : public TestFixture { " 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()); + ASSERT_EQUALS("[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str()); check("int getcontext(ucontext_t *ucp);\n" "void f (ucontext_t *ucp)\n" "{\n" " getcontext ( ucp ) ;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\n", errout_str()); } void prohibitedFunctions_functionWithBody() { @@ -367,8 +367,8 @@ class TestFunctions : public TestFixture { " char *cpwd;" " crypt(pwd, cpwd);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function crypt() is not used.\n" - "[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\n" + "[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\n", errout_str()); check("void f()\n" "{\n" @@ -376,8 +376,8 @@ class TestFunctions : public TestFixture { " char *cpwd;" " crypt(pwd, cpwd);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function crypt() is not used.\n" - "[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\n" + "[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\n", errout_str()); check("int f()\n" "{\n" @@ -393,14 +393,14 @@ class TestFunctions : public TestFixture { " time_t t = 0;" " auto lt = std::localtime(&t);\n" "}"); - 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()); + ASSERT_EQUALS("[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\n", errout_str()); // Passed as function argument 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()); + ASSERT_EQUALS("[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\n", errout_str()); // Pass return value check("void f()\n" @@ -408,15 +408,15 @@ class TestFunctions : public TestFixture { " time_t t = 0;" " struct tm *foo = localtime(&t);\n" "}"); - 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()); + ASSERT_EQUALS("[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\n", errout_str()); // Access via global namespace check("void f()\n" "{\n" " ::getpwent();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function ::getpwent() is not used.\n" - "[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()); + ASSERT_EQUALS("[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\n" + "[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\n", errout_str()); // Be quiet on function definitions check("int getpwent()\n" @@ -442,46 +442,46 @@ class TestFunctions : public TestFixture { void invalidFunctionUsage1() { 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()); + ASSERT_EQUALS("[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); 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()); + ASSERT_EQUALS("[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); 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()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); // Ticket #6990 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()); + ASSERT_EQUALS("[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); 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()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); // Ticket #6588 (c mode) check("void record(char* buf, int n) {\n" " memset(buf, 0, n < 255);\n" /* KO */ " memset(buf, 0, n < 255 ? n : 255);\n" /* OK */ "}", dinit(CheckOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:2]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout_str()); + ASSERT_EQUALS("[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); // Ticket #6588 (c++ mode) check("void record(char* buf, int n) {\n" " memset(buf, 0, n < 255);\n" /* KO */ " memset(buf, 0, n < 255 ? n : 255);\n" /* OK */ "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); check("int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\n" " return div(a, param > 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\n", errout_str()); check("void boolArgZeroIsValidButOneIsInvalid(int param) {\n" " strtol(a, b, param > 0);\n" "}"); - 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()); + ASSERT_EQUALS("[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\n", errout_str()); 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()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\n", errout_str()); check("void f() { strtol(a,b,10); }"); ASSERT_EQUALS("", errout_str()); @@ -492,21 +492,21 @@ class TestFunctions : public TestFixture { " N = h(N);\n" " v.resize(N);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); check("void f(std::vector& v, int N) {\n" " if (N < -1)\n" " return;\n" " v.resize(N);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'.\n", + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); check("void f(std::vector& v, int N) {\n" " if (N == -1) {}\n" " v.resize(N);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'.\n", + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); check("void f(std::vector& v, int N, bool b) {\n" @@ -514,26 +514,26 @@ class TestFunctions : public TestFixture { " N = -1;\n" " v.resize(N);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'.\n", + ASSERT_EQUALS("[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); check("void f(std::vector& v) {\n" " int N = -1;\n" " v.resize(N);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'.\n", + ASSERT_EQUALS("[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); } void invalidFunctionUsageStrings() { check("size_t f() { char x = 'x'; return strlen(&x); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("size_t f() { return strlen(&x); }"); ASSERT_EQUALS("", errout_str()); check("size_t f(char x) { return strlen(&x); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("size_t f() { char x = '\\0'; return strlen(&x); }"); ASSERT_EQUALS("", errout_str()); @@ -546,22 +546,22 @@ class TestFunctions : public TestFixture { " x = 'a';\n" " return strlen(&x);\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("int f() { char x = '\\0'; return strcmp(\"Hello world\", &x); }"); ASSERT_EQUALS("", errout_str()); check("int f() { char x = 'x'; return strcmp(\"Hello world\", &x); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("size_t f(char x) { char * y = &x; return strlen(y); }"); - TODO_ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", "", errout_str()); check("size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }"); - TODO_ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", "", errout_str()); check("size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }"); - TODO_ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", "", errout_str()); check("size_t f() { char x = '\\0'; char * y = &x; char *z = y; return strlen(z); }"); ASSERT_EQUALS("", errout_str()); @@ -573,8 +573,8 @@ class TestFunctions : public TestFixture { ASSERT_EQUALS("", errout_str()); check("int f(char x, char y) { return strcmp(&x, &y); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required.\n" - "[test.cpp:1]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n" + "[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("size_t f() { char x[] = \"Hello world\"; return strlen(&x[0]); }"); ASSERT_EQUALS("", errout_str()); @@ -593,11 +593,11 @@ class TestFunctions : public TestFixture { " size_t l2 = strlen(&s2.x);\n" " return l1 + l2;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n" - "[test.cpp:9]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n" + "[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("const char x = 'x'; size_t f() { return strlen(&x); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("struct someStruct {\n" " union {\n" @@ -624,7 +624,7 @@ class TestFunctions : public TestFixture { ASSERT_EQUALS("", errout_str()); check("const char x = 'x'; size_t f() { char y = x; return strlen(&y); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("const char x = '\\0'; size_t f() { return strlen(&x); }"); ASSERT_EQUALS("", errout_str()); @@ -654,19 +654,19 @@ class TestFunctions : public TestFixture { " puts(str);\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[1] = { \'x\' };\n" " return fopen(fileName, \"r\"); \n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[2] = { \'x\', \'y\' };\n" " return fopen(fileName, \"r\"); \n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[3] = { \'x\', \'y\' ,\'\\0\' };\n" @@ -696,13 +696,13 @@ class TestFunctions : public TestFixture { " const char fileName[] = { \'0\' + 42 };\n" // no size is explicitly defined, no implicit '\0' is added " return fopen(fileName, \"r\"); \n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[] = { \'0\' + 42, \'x\' };\n" // no size is explicitly defined, no implicit '\0' is added " return fopen(fileName, \"r\"); \n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[2] = { \'0\' + 42 };\n" // implicitly '\0' added at the end because size is set to 2 @@ -731,13 +731,13 @@ class TestFunctions : public TestFixture { " const char c[3] = \"abc\";\n" " return strlen(c);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("int f() {\n" " const wchar_t c[3] = L\"abc\";\n" " return wcslen(c);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("void f(char* dest) {\n" " char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \"%\";\n" @@ -760,10 +760,10 @@ class TestFunctions : public TestFixture { ASSERT_EQUALS("", errout_str()); check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("void f() { char a[10] = \"1234567890\"; puts(a); }", dinit(CheckOptions, $.cpp = false)); // #1770 - ASSERT_EQUALS("[test.c:1]: (error) Invalid puts() argument nr 1. A nul-terminated string is required.\n", errout_str()); + ASSERT_EQUALS("[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); } void invalidFunctionArg1() { @@ -789,9 +789,9 @@ class TestFunctions : public TestFixture { " std::cout << sqrtf(-1) << std::endl;\n" " std::cout << sqrtl(-1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'.\n" - "[test.cpp:4]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'.\n" - "[test.cpp:5]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\n" + "[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\n" + "[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\n", errout_str()); // implementation-defined behaviour for "finite values of x<0" only: check("void foo()\n" @@ -828,27 +828,27 @@ class TestFunctions : public TestFixture { " std::cout << log1pf(-3) << std::endl;\n" " std::cout << log1pl(-3) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:4]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:5]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:6]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:7]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:8]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:9]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:10]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:11]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:3]: (warning) Passing value -2 to log() leads to implementation-defined result.\n" - "[test.cpp:4]: (warning) Passing value -2 to logf() leads to implementation-defined result.\n" - "[test.cpp:5]: (warning) Passing value -2 to logl() leads to implementation-defined result.\n" - "[test.cpp:6]: (warning) Passing value -2 to log10() leads to implementation-defined result.\n" - "[test.cpp:7]: (warning) Passing value -2 to log10f() leads to implementation-defined result.\n" - "[test.cpp:8]: (warning) Passing value -2 to log10l() leads to implementation-defined result.\n" - "[test.cpp:9]: (warning) Passing value -2 to log2() leads to implementation-defined result.\n" - "[test.cpp:10]: (warning) Passing value -2 to log2f() leads to implementation-defined result.\n" - "[test.cpp:11]: (warning) Passing value -2 to log2l() leads to implementation-defined result.\n" - "[test.cpp:12]: (warning) Passing value -3 to log1p() leads to implementation-defined result.\n" - "[test.cpp:13]: (warning) Passing value -3 to log1pf() leads to implementation-defined result.\n" - "[test.cpp:14]: (warning) Passing value -3 to log1pl() leads to implementation-defined result.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); check("void foo()\n" "{\n" @@ -865,27 +865,27 @@ class TestFunctions : public TestFixture { " std::cout << log1pf(-2) << std::endl;\n" " std::cout << log1pl(-2) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:4]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:5]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:6]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:7]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:8]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:9]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:10]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:11]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:3]: (warning) Passing value -1 to log() leads to implementation-defined result.\n" - "[test.cpp:4]: (warning) Passing value -1 to logf() leads to implementation-defined result.\n" - "[test.cpp:5]: (warning) Passing value -1 to logl() leads to implementation-defined result.\n" - "[test.cpp:6]: (warning) Passing value -1 to log10() leads to implementation-defined result.\n" - "[test.cpp:7]: (warning) Passing value -1 to log10f() leads to implementation-defined result.\n" - "[test.cpp:8]: (warning) Passing value -1 to log10l() leads to implementation-defined result.\n" - "[test.cpp:9]: (warning) Passing value -1 to log2() leads to implementation-defined result.\n" - "[test.cpp:10]: (warning) Passing value -1 to log2f() leads to implementation-defined result.\n" - "[test.cpp:11]: (warning) Passing value -1 to log2l() leads to implementation-defined result.\n" - "[test.cpp:12]: (warning) Passing value -2 to log1p() leads to implementation-defined result.\n" - "[test.cpp:13]: (warning) Passing value -2 to log1pf() leads to implementation-defined result.\n" - "[test.cpp:14]: (warning) Passing value -2 to log1pl() leads to implementation-defined result.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); check("void foo()\n" "{\n" @@ -902,27 +902,27 @@ class TestFunctions : public TestFixture { " std::cout << log1pf(-2.0) << std::endl;\n" " std::cout << log1pl(-2.0) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:4]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:5]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:6]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:7]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:8]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:9]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:10]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:11]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:3]: (warning) Passing value -1.0 to log() leads to implementation-defined result.\n" - "[test.cpp:4]: (warning) Passing value -1.0 to logf() leads to implementation-defined result.\n" - "[test.cpp:5]: (warning) Passing value -1.0 to logl() leads to implementation-defined result.\n" - "[test.cpp:6]: (warning) Passing value -1.0 to log10() leads to implementation-defined result.\n" - "[test.cpp:7]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result.\n" - "[test.cpp:8]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result.\n" - "[test.cpp:9]: (warning) Passing value -1.0 to log2() leads to implementation-defined result.\n" - "[test.cpp:10]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result.\n" - "[test.cpp:11]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result.\n" - "[test.cpp:12]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result.\n" - "[test.cpp:13]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result.\n" - "[test.cpp:14]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); check("void foo()\n" "{\n" @@ -939,27 +939,27 @@ class TestFunctions : public TestFixture { " std::cout << log1pf(-1.1) << std::endl;\n" " std::cout << log1pl(-1.1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:4]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:5]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:6]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:7]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:8]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:9]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:10]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:11]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:3]: (warning) Passing value -0.1 to log() leads to implementation-defined result.\n" - "[test.cpp:4]: (warning) Passing value -0.1 to logf() leads to implementation-defined result.\n" - "[test.cpp:5]: (warning) Passing value -0.1 to logl() leads to implementation-defined result.\n" - "[test.cpp:6]: (warning) Passing value -0.1 to log10() leads to implementation-defined result.\n" - "[test.cpp:7]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result.\n" - "[test.cpp:8]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result.\n" - "[test.cpp:9]: (warning) Passing value -0.1 to log2() leads to implementation-defined result.\n" - "[test.cpp:10]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result.\n" - "[test.cpp:11]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result.\n" - "[test.cpp:12]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result.\n" - "[test.cpp:13]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result.\n" - "[test.cpp:14]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); check("void foo()\n" "{\n" @@ -976,27 +976,27 @@ class TestFunctions : public TestFixture { " std::cout << log1pf(-1.0) << std::endl;\n" " std::cout << log1pl(-1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:4]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:5]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:6]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:7]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:8]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:9]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:10]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'.\n" - "[test.cpp:11]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'.\n" - "[test.cpp:3]: (warning) Passing value 0 to log() leads to implementation-defined result.\n" - "[test.cpp:4]: (warning) Passing value 0. to logf() leads to implementation-defined result.\n" - "[test.cpp:5]: (warning) Passing value 0.0 to logl() leads to implementation-defined result.\n" - "[test.cpp:6]: (warning) Passing value 0.0 to log10() leads to implementation-defined result.\n" - "[test.cpp:7]: (warning) Passing value 0 to log10f() leads to implementation-defined result.\n" - "[test.cpp:8]: (warning) Passing value 0. to log10l() leads to implementation-defined result.\n" - "[test.cpp:9]: (warning) Passing value 0. to log2() leads to implementation-defined result.\n" - "[test.cpp:10]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result.\n" - "[test.cpp:11]: (warning) Passing value 0 to log2l() leads to implementation-defined result.\n" - "[test.cpp:12]: (warning) Passing value -1. to log1p() leads to implementation-defined result.\n" - "[test.cpp:13]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result.\n" - "[test.cpp:14]: (warning) Passing value -1 to log1pl() leads to implementation-defined result.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" + "[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" + "[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); check("void foo()\n" "{\n" @@ -1109,9 +1109,9 @@ class TestFunctions : public TestFixture { " std::cout << acosf(1.1) << std::endl;\n" " std::cout << acosl(1.1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'.\n" - "[test.cpp:4]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'.\n" - "[test.cpp:5]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", errout_str()); check("void foo()\n" "{\n" @@ -1119,9 +1119,9 @@ class TestFunctions : public TestFixture { " std::cout << acosf(-1.1) << std::endl;\n" " std::cout << acosl(-1.1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'.\n" - "[test.cpp:4]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'.\n" - "[test.cpp:5]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", errout_str()); } void mathfunctionCall_asin() { @@ -1170,9 +1170,9 @@ class TestFunctions : public TestFixture { " std::cout << asinf(1.1) << std::endl;\n" " std::cout << asinl(1.1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'.\n" - "[test.cpp:4]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'.\n" - "[test.cpp:5]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", errout_str()); check("void foo()\n" "{\n" @@ -1180,9 +1180,9 @@ class TestFunctions : public TestFixture { " std::cout << asinf(-1.1) << std::endl;\n" " std::cout << asinl(-1.1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'.\n" - "[test.cpp:4]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'.\n" - "[test.cpp:5]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", errout_str()); } void mathfunctionCall_pow() { @@ -1193,9 +1193,9 @@ class TestFunctions : public TestFixture { " std::cout << powf(0,-10) << std::endl;\n" " std::cout << powl(0,-10) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result.\n" - "[test.cpp:4]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result.\n" - "[test.cpp:5]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); check("void foo()\n" "{\n" @@ -1252,9 +1252,9 @@ class TestFunctions : public TestFixture { " std::cout << atan2f(0,0) << std::endl;\n" " std::cout << atan2l(0,0) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result.\n" - "[test.cpp:4]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result.\n" - "[test.cpp:5]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); } void mathfunctionCall_fmod() { @@ -1265,12 +1265,12 @@ class TestFunctions : public TestFixture { " std::cout << fmodf(1.0,0) << std::endl;\n" " std::cout << fmodl(1.0,0) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'.\n" - "[test.cpp:4]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'.\n" - "[test.cpp:5]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'.\n" - "[test.cpp:3]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result.\n" - "[test.cpp:4]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result.\n" - "[test.cpp:5]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\n" + "[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\n" + "[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\n" + "[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\n" + "[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); check("void foo()\n" "{\n" @@ -1287,27 +1287,27 @@ class TestFunctions : public TestFixture { " print(log(1 + x));\n" " print(1 - erf(x));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision.\n" - "[test.cpp:3]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision.\n" - "[test.cpp:4]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\n" + "[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\n" + "[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\n", errout_str()); check("void foo() {\n" " print(exp(x) - 1.0);\n" " print(log(1.0 + x));\n" " print(1.0 - erf(x));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision.\n" - "[test.cpp:3]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision.\n" - "[test.cpp:4]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\n" + "[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\n" + "[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\n", errout_str()); check("void foo() {\n" " print(exp(3 + x*f(a)) - 1);\n" " print(log(x*4 + 1));\n" " print(1 - erf(34*x + f(x) - c));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision.\n" - "[test.cpp:3]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision.\n" - "[test.cpp:4]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\n" + "[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\n" + "[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\n", errout_str()); check("void foo() {\n" " print(2*exp(x) - 1);\n" @@ -1330,24 +1330,24 @@ class TestFunctions : public TestFixture { check("void foo() {\n" " mystrcmp(a, b);\n" "}", dinit(CheckOptions, $.s = &settings2)); - ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function mystrcmp() is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("void foo() {\n" " foo::mystrcmp(a, b);\n" "}", dinit(CheckOptions, $.s = &settings2)); - ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function foo::mystrcmp() is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("void f() {\n" " foo x;\n" " x.mystrcmp(a, b);\n" "}", dinit(CheckOptions, $.s = &settings2)); - ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function x.mystrcmp() is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("bool mystrcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library. "void foo() {\n" " mystrcmp(a, b);\n" "}", dinit(CheckOptions, $.s = &settings2)); - ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function mystrcmp() is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("void mystrcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition which returns void! "void foo() {\n" @@ -1435,10 +1435,10 @@ class TestFunctions : public TestFixture { " TestStruct1.testfunc2();\n" " return 0;\n" "}", dinit(CheckOptions, $.s = &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" - "[test.cpp:8]: (warning) Return value of function TestStruct1.testfunc1() is not used.\n" - "[test.cpp:9]: (warning) Return value of function TestStruct1.testfunc2() is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\n" + "[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\n" + "[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\n" + "[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\n", errout_str()); // #9006 check("template uint8_t b(std::tuple d) {\n" @@ -1459,7 +1459,7 @@ class TestFunctions : public TestFixture { check("void foo() {\n" " !mystrcmp(a, b);\n" "}", dinit(CheckOptions, $.s = &settings2)); - ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function mystrcmp() is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("void f(std::vector v) {\n" " delete *v.begin();\n" @@ -1472,8 +1472,8 @@ class TestFunctions : public TestFixture { " p_foo(0);\n" " c_foo(0);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Return value of function p_foo() is not used.\n" - "[test.cpp:5]: (warning) Return value of function c_foo() is not used.\n", + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\n" + "[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\n", errout_str()); } @@ -1491,19 +1491,19 @@ class TestFunctions : public TestFixture { check("void foo() {\n" " mystrcmp(a, b);\n" "}", dinit(CheckOptions, $.s = &settings2)); - ASSERT_EQUALS("[test.cpp:2]: (style) Error code from the return value of function mystrcmp() is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\n", errout_str()); } void memsetZeroBytes() { check("void f() {\n" " memset(p, 10, 0x0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\n", errout_str()); check("void f() {\n" " memset(p, sizeof(p), 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\n", errout_str()); check("void f() {\n" " memset(p, sizeof(p), i);\n" @@ -1523,7 +1523,7 @@ class TestFunctions : public TestFixture { check("void f() {\n" " memset(&tm, sizeof(tm), 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\n", errout_str()); } @@ -1534,15 +1534,15 @@ class TestFunctions : public TestFixture { " int* is2 = new int[10];\n" " memset(is2, 0.1f, 40);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined.\n" - "[test.cpp:5]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\n" + "[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\n", errout_str()); check("void f() {\n" " int* is = new int[10];\n" " float g = computeG();\n" " memset(is, g, 40);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\n", errout_str()); check("void f() {\n" " int* is = new int[10];\n" @@ -1562,8 +1562,8 @@ class TestFunctions : public TestFixture { " short ss2[2];\n" " memset(ss2, -129, 4);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'.\n" - "[test.cpp:5]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\n" + "[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\n", errout_str()); check("void f() {\n" " int is[10];\n" @@ -1584,12 +1584,12 @@ class TestFunctions : public TestFixture { " const int i = g();\n" " memset(is, 1.0f + i, 40);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\n", errout_str()); } void checkMissingReturn1() { check("int f() {}"); - ASSERT_EQUALS("[test.cpp:1]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); { const char code[] = "int main(void) {}"; @@ -1597,7 +1597,7 @@ class TestFunctions : public TestFixture { const Settings s = settingsBuilder().c(Standards::C89).build(); check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89) - ASSERT_EQUALS("[test.c:1]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); } { @@ -1643,7 +1643,7 @@ class TestFunctions : public TestFixture { " return 1;\n" "out:\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); // switch check("int f() {\n" @@ -1652,7 +1652,7 @@ class TestFunctions : public TestFixture { " case 2: return 1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("int f() {\n" " switch (x) {\n" @@ -1682,7 +1682,7 @@ class TestFunctions : public TestFixture { " return 1;\n" " }\n" // <- error (missing else) "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("int f(int x) {\n" " if (x) {\n" @@ -1691,7 +1691,7 @@ class TestFunctions : public TestFixture { " return 1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("int f() {\n" " if (!0) {\n" @@ -1703,7 +1703,7 @@ class TestFunctions : public TestFixture { check("int f() {\n" " if (!0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); // loop check("int f(int x) {\n" @@ -1747,8 +1747,8 @@ class TestFunctions : public TestFixture { " S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\n" " int k;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2]: (error) Found an exit path from function with non-void return type that has missing return statement\n" - "[test.cpp:10]: (error) Found an exit path from function with non-void return type that has missing return statement\n", + ASSERT_EQUALS("[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n" + "[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); // #11171 @@ -1757,12 +1757,12 @@ class TestFunctions : public TestFixture { check("std::enable_if_t f() {}"); ASSERT_EQUALS( - "[test.cpp:1]: (error) Found an exit path from function with non-void return type that has missing return statement\n", + "[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("template std::enable_if_t{}, int> f(T) {}"); ASSERT_EQUALS( - "[test.cpp:1]: (error) Found an exit path from function with non-void return type that has missing return statement\n", + "[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("template std::enable_if_t{}> f(T) {}"); @@ -1773,12 +1773,12 @@ class TestFunctions : public TestFixture { check("typename std::enable_if::type f() {}"); ASSERT_EQUALS( - "[test.cpp:1]: (error) Found an exit path from function with non-void return type that has missing return statement\n", + "[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("template typename std::enable_if{}, int>::type f(T) {}"); ASSERT_EQUALS( - "[test.cpp:1]: (error) Found an exit path from function with non-void return type that has missing return statement\n", + "[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("template typename std::enable_if{}>::type f(T) {}"); @@ -1845,7 +1845,7 @@ class TestFunctions : public TestFixture { " return 2;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); } void checkMissingReturn5() { @@ -1877,35 +1877,35 @@ class TestFunctions : public TestFixture { "{\n" " i = readData();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Found an exit path from function with non-void return type that has missing return statement\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); } // NRVO check void returnLocalStdMove1() { check("struct A{}; A f() { A var; return std::move(var); }"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." - " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." + " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\n", errout_str()); } // RVO, C++03 ctor style void returnLocalStdMove2() { check("struct A{}; A f() { return std::move( A() ); }"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." - " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." + " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\n", errout_str()); } // RVO, new ctor style void returnLocalStdMove3() { check("struct A{}; A f() { return std::move(A{}); }"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." - " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." + " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\n", errout_str()); } // Function argument void returnLocalStdMove4() { check("struct A{}; A f(A a) { return std::move(A{}); }"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." - " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." + " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\n", errout_str()); } void returnLocalStdMove5() { @@ -1938,15 +1938,15 @@ class TestFunctions : public TestFixture { " a = malloc( -10 );\n" " free(a);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); check("void f() {\n" " int *a;\n" " a = alloca( -10 );\n" " free(a);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'alloca' called.\n" - "[test.cpp:3]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\n" + "[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); } void checkLibraryMatchFunctions() { @@ -1956,12 +1956,12 @@ class TestFunctions : public TestFixture { check("void f() {\n" " lib_func();" "}", dinit(CheckOptions, $.s = &s)); - ASSERT_EQUALS("[test.cpp:2]: (information) --check-library: There is no matching configuration for function lib_func()\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\n", errout_str()); check("void f(void* v) {\n" " lib_func(v);" "}", dinit(CheckOptions, $.s = &s)); - ASSERT_EQUALS("[test.cpp:2]: (information) --check-library: There is no matching configuration for function lib_func()\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\n", errout_str()); // #10105 check("class TestFixture {\n" @@ -1987,7 +1987,7 @@ class TestFunctions : public TestFixture { "void f() {\n" " cb(std::string(\"\"));\n" "}", dinit(CheckOptions, $.s = &s)); - TODO_ASSERT_EQUALS("", "[test.cpp:6]: (information) --check-library: There is no matching configuration for function cb()\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\n", errout_str()); // #7375 check("void f() {\n" @@ -2026,7 +2026,7 @@ class TestFunctions : public TestFixture { " for (const auto& s : v)\n" " s.find(\"\");\n" "}\n", dinit(CheckOptions, $.s = &s)); - ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function s.find() is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\n", errout_str()); check("void f() {\n" " auto* p = new std::vector(5);\n" @@ -2067,10 +2067,10 @@ class TestFunctions : public TestFixture { " q->push_back(1);\n" "}\n", dinit(CheckOptions, $.s = &s)); TODO_ASSERT_EQUALS("", - "[test.cpp:2]: (debug) auto token with no type.\n" - "[test.cpp:4]: (debug) auto token with no type.\n" - "[test.cpp:3]: (information) --check-library: There is no matching configuration for function auto::push_back()\n" - "[test.cpp:5]: (information) --check-library: There is no matching configuration for function auto::push_back()\n", + "[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\n" + "[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\n" + "[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\n" + "[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\n", errout_str()); check("struct F { void g(int); };\n" @@ -2085,7 +2085,7 @@ class TestFunctions : public TestFixture { " return std::runtime_error(\"abc\");\n" "}\n", dinit(CheckOptions, $.s = &s)); TODO_ASSERT_EQUALS("", - "[test.cpp:1]: (debug) auto token with no type.\n", + "[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\n", errout_str()); check("struct S {\n" // #11543 @@ -2137,7 +2137,7 @@ class TestFunctions : public TestFixture { " p->h(i);\n" " p.reset(nullptr);\n" "}\n", dinit(CheckOptions, $.s = &s)); - ASSERT_EQUALS("[test.cpp:5]: (information) --check-library: There is no matching configuration for function T::h()\n", + ASSERT_EQUALS("[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\n", errout_str()); check("struct S : std::vector {\n" @@ -2175,7 +2175,7 @@ class TestFunctions : public TestFixture { " const bool b = it != m->end();\n" " return b;\n" "}\n", dinit(CheckOptions, $.s = &s)); - TODO_ASSERT_EQUALS("", "[test.cpp:6]: (debug) auto token with no type.\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\n", errout_str()); } void checkUseStandardLibrary1() { @@ -2184,7 +2184,7 @@ class TestFunctions : public TestFixture { " for (i = 0; count > i; ++i)\n" " (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::memcpy instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary2() { @@ -2192,7 +2192,7 @@ class TestFunctions : public TestFixture { " for (size_t i = 0; i < count; i++) {\n" " (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\n" "}}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memcpy instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary3() { @@ -2201,7 +2201,7 @@ class TestFunctions : public TestFixture { " for (i = 0; count > i; i++)\n" " ((char*)dst)[i] = ((const char*)src)[i];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::memcpy instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary4() { @@ -2209,7 +2209,7 @@ class TestFunctions : public TestFixture { " for (size_t i = 0; i < size; i += 1) {\n" " ((int8_t*)dst)[i] = ((int8_t*)src)[i];\n" "}}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memcpy instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\n", errout_str()); } // different indexes @@ -2247,7 +2247,7 @@ class TestFunctions : public TestFixture { " for (i = 0; i < count; ++i)\n" " (reinterpret_cast(dest))[i] = static_cast(0);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::memset instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary9() { @@ -2255,7 +2255,7 @@ class TestFunctions : public TestFixture { " for (size_t i = 0; i < count; i++) {\n" " (reinterpret_cast(dest))[i] = (static_cast(0));\n" "}}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memset instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary10() { @@ -2264,7 +2264,7 @@ class TestFunctions : public TestFixture { " for (i = 0; i < size; i++)\n" " ((char*)dst)[i] = (const char)0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::memset instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary11() { @@ -2272,7 +2272,7 @@ class TestFunctions : public TestFixture { " for (size_t i = 0; i < size; i += 1) {\n" " ((int8_t*)dst)[i] = ((int8_t)0);\n" "}}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memset instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary12() { @@ -2280,7 +2280,7 @@ class TestFunctions : public TestFixture { " for (size_t i = 0; i < size; i += 1) {\n" " ((int8_t*)dst)[i] = 42;\n" "}}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memset instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary13() { @@ -2288,7 +2288,7 @@ class TestFunctions : public TestFixture { " for (size_t i = 0; i < count; i++) {\n" " reinterpret_cast(dest)[i] = '0';\n" "}}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memset instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\n", errout_str()); } void checkUseStandardLibrary14() { @@ -2296,7 +2296,7 @@ class TestFunctions : public TestFixture { " for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\n" " reinterpret_cast(dest)[i] = '0';\n" "}}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memset instead of loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\n", errout_str()); } }; From 4e1b768103c2ce2c324f2ee0458b2f22c8a9f908 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 16 May 2025 23:01:40 +0200 Subject: [PATCH 2/3] TestUninitVar: added errors IDs and columns to expected output --- test/testuninitvar.cpp | 676 ++++++++++++++++++++--------------------- 1 file changed, 338 insertions(+), 338 deletions(-) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 26e847c887f..b7438c13692 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -34,7 +34,7 @@ class TestUninitVar : public TestFixture { const Settings settings = settingsBuilder().library("std.cfg").build(); void run() override { - // TODO: mNewTemplate = true; + mNewTemplate = true; TEST_CASE(uninitvar1); TEST_CASE(uninitvar_warn_once); // only write 1 warning at a time TEST_CASE(uninitvar_decl); // handling various types in C and C++ files @@ -135,13 +135,13 @@ class TestUninitVar : public TestFixture { " int a;\n" " b = c - a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo() {\n" " int a;\n" " b = a - c;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); // Ticket #6455 - some compilers allow const variables to be uninitialized // extracttests.disable @@ -149,14 +149,14 @@ class TestUninitVar : public TestFixture { " const int a;\n" " b = c - a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); // extracttests.enable checkUninitVar("void foo() {\n" " int *p;\n" " realloc(p,10);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo() {\n" // #5240 " char *p = malloc(100);\n" @@ -178,7 +178,7 @@ class TestUninitVar : public TestFixture { " Foo *p;\n" " p->abcd();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); // extracttests.start: template struct Foo { void abcd(); }; checkUninitVar("static void foo()\n" @@ -186,7 +186,7 @@ class TestUninitVar : public TestFixture { " Foo *p;\n" " p->abcd();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); // extracttests.start: struct Foo { void* a; }; checkUninitVar("void f(Foo *p)\n" @@ -194,49 +194,49 @@ class TestUninitVar : public TestFixture { " int a;\n" " p->a = malloc(4 * a);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:23]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int *p;\n" " delete p;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int *p;\n" " delete [] p;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:15]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int *p;\n" " *p = 135;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int *p;\n" " p[0] = 135;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int *x;\n" " int y = *x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int *x;\n" " int &y(*x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo()\n" "{\n" @@ -263,14 +263,14 @@ class TestUninitVar : public TestFixture { " int a;\n" " a = 5 + a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void f()\n" "{\n" " int a;\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void f()\n" "{\n" @@ -285,28 +285,28 @@ class TestUninitVar : public TestFixture { " int a;\n" " bar(4 * a);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int i;\n" " if (i);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int i;\n" " for (int x = 0; i < 10; x++);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:21]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" " int i;\n" " for (int x = 0; x < 10; i++);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:29]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo(int x)\n" "{\n" @@ -315,7 +315,7 @@ class TestUninitVar : public TestFixture { " i = 0;\n" " i++;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" @@ -323,7 +323,7 @@ class TestUninitVar : public TestFixture { " int i;\n" " ar[i] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:8]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" @@ -345,13 +345,13 @@ class TestUninitVar : public TestFixture { " int b = 1;\n" " (b += a) = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("int f() {\n" " int a,b,c;\n" " a = b = c;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:0]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo()\n" "{\n" @@ -383,7 +383,7 @@ class TestUninitVar : public TestFixture { " return ret;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ret\n", errout_str()); + ASSERT_EQUALS("[test.c:4:12]: (error) Uninitialized variable: ret [legacyUninitvar]\n", errout_str()); } // extracttests.enable @@ -446,14 +446,14 @@ class TestUninitVar : public TestFixture { " int a;\n" " i >> a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("int a() {\n" " int ret;\n" " int a = value >> ret;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: ret\n", errout_str()); + ASSERT_EQUALS("[test.c:3:22]: (error) Uninitialized variable: ret [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo() {\n" // #3707 " Node node;\n" @@ -467,14 +467,14 @@ class TestUninitVar : public TestFixture { " arc << p;\n" // <- TODO initialization? " return *p;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("void a() {\n" " int ret;\n" " a = value << ret;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: ret\n", errout_str()); + ASSERT_EQUALS("[test.c:3:18]: (error) Uninitialized variable: ret [legacyUninitvar]\n", errout_str()); // #4320 says this is a FP. << is overloaded. checkUninitVar("int f() {\n" @@ -482,32 +482,32 @@ class TestUninitVar : public TestFixture { " a << 1;\n" // <- TODO initialization? " return a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); // #4673 checkUninitVar("void f() {\n" " int a;\n" " std::cout << a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void f(std::ostringstream& os) {\n" " int a;\n" " os << a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int a;\n" " std::cout << 1 << a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void f(std::ostringstream& os) {\n" " int a;\n" " os << 1 << a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); { // #9422 @@ -527,7 +527,7 @@ class TestUninitVar : public TestFixture { " char *p = new char[10];\n" " std::cout << p << 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Memory is allocated but not initialized: p [uninitdata]\n", errout_str()); checkUninitVar("void f() {\n" // #9696 " int *p = new int[10];\n" @@ -543,21 +543,21 @@ class TestUninitVar : public TestFixture { " wchar_t w[10];\n" " std::cout << w;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: c\n" - "[test.cpp:7]: (error) Uninitialized variable: w\n", + ASSERT_EQUALS("[test.cpp:5:16]: (error) Uninitialized variable: c [legacyUninitvar]\n" + "[test.cpp:7:16]: (error) Uninitialized variable: w [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " char p[10];\n" " std::cout << p << 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " char p[10];\n" " std::cout << *p << 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); } } @@ -572,7 +572,7 @@ class TestUninitVar : public TestFixture { " int x;\n" " a & x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int a,b,c;\n" @@ -599,7 +599,7 @@ class TestUninitVar : public TestFixture { " struct S *s;\n" " s->x = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Uninitialized variable: s [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo()\n" "{\n" @@ -642,7 +642,7 @@ class TestUninitVar : public TestFixture { " *p = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); // += checkUninitVar("void f()\n" @@ -650,14 +650,14 @@ class TestUninitVar : public TestFixture { " int c;\n" " c += 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("void f()\n" "{\n" " int a[10];\n" " a[0] = 10 - a[1];\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a[1]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (error) Uninitialized variable: a[1] [legacyUninitvar]\n", errout_str()); // goto/setjmp/longjmp.. checkUninitVar("void foo(int x)\n" @@ -767,14 +767,14 @@ class TestUninitVar : public TestFixture { " int x;\n" " int z = (x) & ~__round_mask(1, 1);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f(void)\n" "{\n" " int x;\n" " int z = (x) | ~__round_mask(1, 1);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("int __round_mask(int, int);\n" "void f(void)\n" @@ -793,7 +793,7 @@ class TestUninitVar : public TestFixture { " a = x;\n" " b = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); } // Handling of unknown types. Assume they are POD in C. @@ -809,7 +809,7 @@ class TestUninitVar : public TestFixture { // Assume dfs is a POD type if file is C checkUninitVar(code, dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.c:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); const char code2[] = "struct AB { int a,b; };\n" "void f() {\n" @@ -817,10 +817,10 @@ class TestUninitVar : public TestFixture { " return ab;\n" "}"; checkUninitVar(code2); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n" - "[test.cpp:4]: (error) Uninitialized struct member: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n" + "[test.cpp:4:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\n", errout_str()); checkUninitVar(code2, dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab\n", errout_str()); + ASSERT_EQUALS("[test.c:4:12]: (error) Uninitialized variable: ab [legacyUninitvar]\n", errout_str()); // Ticket #3890 - False positive for std::map checkUninitVar("void f() {\n" @@ -883,13 +883,13 @@ class TestUninitVar : public TestFixture { " int b;\n" " c = a | b;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: b [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo() {\n" " int b;\n" " c = b | a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: b [legacyUninitvar]\n", errout_str()); } // if.. @@ -902,7 +902,7 @@ class TestUninitVar : public TestFixture { " p = new Foo;\n" " p->abcd();\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("static void foo(int x)\n" "{\n" @@ -911,7 +911,7 @@ class TestUninitVar : public TestFixture { " if (x==2);\n" " x = a;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:9]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("int foo() {\n" " int i;\n" @@ -1074,7 +1074,7 @@ class TestUninitVar : public TestFixture { " XYZ ret = 2;\n" // XYZ may be an unexpanded macro so bailout the checking of "ret". " return ret;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: ret\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:12]: (error) Uninitialized variable: ret [legacyUninitvar]\n", errout_str()); checkUninitVar("int f(int a, int b)\n" "{\n" @@ -1130,7 +1130,7 @@ class TestUninitVar : public TestFixture { " int x;\n" " x = v <= 0 ? -1 : x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo()\n" "{\n" @@ -1149,7 +1149,7 @@ class TestUninitVar : public TestFixture { " int x; x = (a a;\n" " return a[0];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("std::string f() {\n" " std::array a;\n" @@ -1886,7 +1886,7 @@ class TestUninitVar : public TestFixture { " vertices[i][1][3] = 5.0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: vertices\n", + ASSERT_EQUALS("[test.cpp:4:5]: (error) Uninitialized variable: vertices [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" @@ -1911,33 +1911,33 @@ class TestUninitVar : public TestFixture { " char *s = (char *)malloc(100);\n" " strcat(s, \"abc\");\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: s\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Memory is allocated but not initialized: s [uninitdata]\n", errout_str()); checkUninitVar("void f()\n" "{\n" " char *s1 = new char[10];\n" " char *s2 = new char[strlen(s1)];\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: s1\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:32]: (error) Memory is allocated but not initialized: s1 [uninitdata]\n", errout_str()); checkUninitVar("void f()\n" "{\n" " char *p = (char*)malloc(64);\n" " int x = p[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Memory is allocated but not initialized: p [uninitdata]\n", errout_str()); checkUninitVar("void f() {\n" " char *p = (char*)malloc(64);\n" " if (p[0]) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p[0]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Memory is allocated but not initialized: p[0] [uninitdata]\n", errout_str()); checkUninitVar("char f() {\n" " char *p = (char*)malloc(64);\n" " return p[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Memory is allocated but not initialized: p [uninitdata]\n", errout_str()); checkUninitVar("void f()\n" "{\n" @@ -1979,7 +1979,7 @@ class TestUninitVar : public TestFixture { " char *a;\n" " if (a);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo()\n" "{\n" @@ -2097,7 +2097,7 @@ class TestUninitVar : public TestFixture { " *((int*)*p) = 42;\n" " delete p;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Memory is allocated but not initialized: p [uninitdata]\n", errout_str()); checkUninitVar("int f() {\n" // #10596 " int* a = new int;\n" @@ -2106,7 +2106,7 @@ class TestUninitVar : public TestFixture { " delete a;\n" " return i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Memory is allocated but not initialized: a [uninitdata]\n", errout_str()); checkUninitVar("void* f(size_t n, int i) {\n" // #11766 " char* p = (char*)malloc(n);\n" @@ -2187,7 +2187,7 @@ class TestUninitVar : public TestFixture { " AB ab;\n" " if (ab);\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: ab\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (error) Uninitialized variable: ab [legacyUninitvar]\n", errout_str()); } // references.. @@ -2232,13 +2232,13 @@ class TestUninitVar : public TestFixture { " int ret;\n" " return ret;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: ret\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Uninitialized variable: ret [legacyUninitvar]\n", errout_str()); checkUninitVar("static int foo() {\n" " int ret;\n" " return ret+5;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: ret\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Uninitialized variable: ret [legacyUninitvar]\n", errout_str()); checkUninitVar("static int foo() {\n" " int ret;\n" @@ -2258,13 +2258,13 @@ class TestUninitVar : public TestFixture { " int ret;\n" " return cin >> ret;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: ret\n", errout_str()); + ASSERT_EQUALS("[test.c:3:19]: (error) Uninitialized variable: ret [legacyUninitvar]\n", errout_str()); } // Ticket #6341- False negative { checkUninitVar("wchar_t f() { int i; return btowc(i); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:35]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("wchar_t f(int i) { return btowc(i); }"); ASSERT_EQUALS("", errout_str()); @@ -2292,7 +2292,7 @@ class TestUninitVar : public TestFixture { " }\n" " printf (\"%f\",f);\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: f\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:18]: (error) Uninitialized variable: f [legacyUninitvar]\n", errout_str()); // Check for potential FP checkUninitVar("void f(bool b) {\n" @@ -2311,7 +2311,7 @@ class TestUninitVar : public TestFixture { " int y;\n" " return x ? 1 : y;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: y\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Uninitialized variable: y [legacyUninitvar]\n", errout_str()); // Ticket #3106 - False positive { @@ -2325,7 +2325,7 @@ class TestUninitVar : public TestFixture { " int i;\n" " return x() ? i : 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); } } @@ -2441,14 +2441,14 @@ class TestUninitVar : public TestFixture { " int x;\n" " a(x);\n" "}").c_str()); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar((funca + "void b() {\n" " int *p;\n" " a(*p);\n" "}").c_str()); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); } @@ -2470,7 +2470,7 @@ class TestUninitVar : public TestFixture { " int *p;\n" " a(p);\n" "}").c_str()); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); } void uninitvar_typeof() { @@ -2490,7 +2490,7 @@ class TestUninitVar : public TestFixture { " struct SData * s;\n" " TYPEOF(s->status);\n" "}"); - TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Uninitialized variable: s\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:3:12]: (error) Uninitialized variable: s [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int *n = ({ typeof(*n) z; (typeof(*n)*)z; })\n" @@ -2509,7 +2509,7 @@ class TestUninitVar : public TestFixture { " int i;\n" " return (int&)i + 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("void foo() {\n" " int i;\n" @@ -2521,7 +2521,7 @@ class TestUninitVar : public TestFixture { " int i;\n" " return *&i;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); } void uninitvar2() { @@ -2530,51 +2530,51 @@ class TestUninitVar : public TestFixture { " int x;\n" " x++;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); // extracttests.start: char str[10]; checkUninitVar("void f() {\n" " int x;\n" " str[x] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" // #7736 " int buf[12];\n" " printf (\"%d\", buf[0] );\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: buf\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Uninitialized variable: buf [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int x;\n" " int y = x & 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int x;\n" " int y = 3 & x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int x;\n" " x = 3 + x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int x;\n" " x = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); // extracttests.start: struct ABC {int a;}; checkUninitVar("void f() {\n" " struct ABC *abc;\n" " abc->a = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: abc\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: abc [legacyUninitvar]\n", errout_str()); checkUninitVar("int f() {\n" " static int x;\n" @@ -2617,13 +2617,13 @@ class TestUninitVar : public TestFixture { " int x;\n" " if (x) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int x;\n" " if (1 == (3 & x)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); // ?: checkUninitVar("int f(int *ptr) {\n" @@ -2644,7 +2644,7 @@ class TestUninitVar : public TestFixture { " int x = ({ 1 + 2; });\n" " int y = 1 + (x ? y : y);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: y\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (error) Uninitialized variable: y [legacyUninitvar]\n", errout_str()); // >> => initialization / usage { @@ -2656,7 +2656,7 @@ class TestUninitVar : public TestFixture { ASSERT_EQUALS("", errout_str()); checkUninitVar(code, dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.c:3:14]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); } checkUninitVar("void f() {\n" @@ -2689,7 +2689,7 @@ class TestUninitVar : public TestFixture { " else { if (y == 2) { x = 1; } }\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int x;\n" @@ -2698,7 +2698,7 @@ class TestUninitVar : public TestFixture { " if (y == 3) { }\n" // <- ignore condition " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); // initialization in condition checkUninitVar("void f() {\n" @@ -2722,7 +2722,7 @@ class TestUninitVar : public TestFixture { " if (y == 1) { return; }\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("int f(int x) {\n" " int ret;\n" @@ -2754,7 +2754,7 @@ class TestUninitVar : public TestFixture { " if (foo) break;\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("int f() {\n" " int x;\n" @@ -2762,7 +2762,7 @@ class TestUninitVar : public TestFixture { " if (bar) break;\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); // try/catch : don't warn about exception variable checkUninitVar("void f() {\n" @@ -2844,7 +2844,7 @@ class TestUninitVar : public TestFixture { " int a;\n" " if (x == 0 && (a == 1)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int a;\n" @@ -2937,7 +2937,7 @@ class TestUninitVar : public TestFixture { " if (x == 1)\n" " v = value;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: value\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:9]: (error) Uninitialized variable: value [legacyUninitvar]\n", errout_str()); checkUninitVar("void f(int x) {\n" " int value;\n" @@ -2946,7 +2946,7 @@ class TestUninitVar : public TestFixture { " if (x == 32) {}\n" " else v = value;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: value\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12]: (error) Uninitialized variable: value [legacyUninitvar]\n", errout_str()); checkUninitVar("static int x;" // #4773 "int f() {\n" @@ -3003,7 +3003,7 @@ class TestUninitVar : public TestFixture { " struct ABC *abc;\n" " int i = ARRAY_SIZE(abc.a);" "}"); - TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Uninitialized variable: abc\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:3:24]: (error) Uninitialized variable: abc [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int *abc;\n" @@ -3079,7 +3079,7 @@ class TestUninitVar : public TestFixture { " char c;\n" " char a = c << 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); } // #13227 @@ -3119,8 +3119,8 @@ class TestUninitVar : public TestFixture { "class Ns::C* p;\n" "void f2() { char *p; *p = 0; }"; checkUninitVar(code); - ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: p\n" - "[test.cpp:4]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (error) Uninitialized variable: p [legacyUninitvar]\n" + "[test.cpp:4:23]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); } void uninitvar10() { // 9467 @@ -3200,7 +3200,7 @@ class TestUninitVar : public TestFixture { " return i;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:16]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("int f() {\n" " int i;\n" @@ -3208,7 +3208,7 @@ class TestUninitVar : public TestFixture { " return i;\n" " } catch(...) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:16]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("void f(bool x) {\n" " bool b;\n" @@ -3237,7 +3237,7 @@ class TestUninitVar : public TestFixture { " }\n" " if (b) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:9]: (error) Uninitialized variable: b [legacyUninitvar]\n", errout_str()); } void uninitvar_funcptr() { @@ -3255,13 +3255,13 @@ class TestUninitVar : public TestFixture { " int (*f)(int, int) = x;\n" " dostuff((*f)(a,b));\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void getLibraryContainer() {\n" " Reference< XStorageBasedLibraryContainer >(*Factory)(const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&);\n" " rxContainer.set((*Factory)(m_aContext, xDocument));\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: Factory\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (error) Uninitialized variable: Factory [legacyUninitvar]\n", errout_str()); // extracttests.enable } @@ -3281,7 +3281,7 @@ class TestUninitVar : public TestFixture { " int n;\n" " foo >> s2.v >> n;\n" // Initialized by operator>> "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized struct member: s.v\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:16]: (error) Uninitialized struct member: s.v [uninitStructMember]\n", errout_str()); checkUninitVar("struct Fred { int a; };\n" "void foo() {\n" @@ -3301,7 +3301,7 @@ class TestUninitVar : public TestFixture { " bar(a,b);\n" // << " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:8]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); // non-pointer variable checkUninitVar("void a(char);\n" // value => error @@ -3309,21 +3309,21 @@ class TestUninitVar : public TestFixture { " char c;\n" " a(c);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("void a(char c);\n" // value => error "void b() {\n" " char c;\n" " a(c);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("void a(const char c);\n" // const value => error "void b() {\n" " char c;\n" " a(c);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("void a(char *c);\n" // address => no error "void b() {\n" @@ -3353,7 +3353,7 @@ class TestUninitVar : public TestFixture { " char *c;\n" " a(*c);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("void a(char *c);\n" // address => error @@ -3361,7 +3361,7 @@ class TestUninitVar : public TestFixture { " char *c;\n" " a(c);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("typedef struct { int a; int b; } AB;\n" "void a(AB *ab);\n" @@ -3369,21 +3369,21 @@ class TestUninitVar : public TestFixture { " AB *ab;\n" " a(ab);\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: ab\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7]: (error) Uninitialized variable: ab [legacyUninitvar]\n", errout_str()); checkUninitVar("void a(const char *c);\n" // const address => error "void b() {\n" " char *c;\n" " a(c);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("void a(const char c[]);\n" // const address => error "void b() {\n" " char *c;\n" " a(c);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\n", errout_str()); checkUninitVar("void a(char **c);\n" // address of pointer => no error "void b() {\n" @@ -3412,7 +3412,7 @@ class TestUninitVar : public TestFixture { " int x[10];\n" " calc(x,10);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", + TODO_ASSERT_EQUALS("[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\n", "", errout_str()); checkUninitVar("void f() {\n" @@ -3441,13 +3441,13 @@ class TestUninitVar : public TestFixture { " time_t* now0;\n" " time(now0);\n" "}", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: now0\n", errout_str()); + ASSERT_EQUALS("[test.c:3:10]: (error) Uninitialized variable: now0 [legacyUninitvar]\n", errout_str()); checkUninitVar("void write_packet() {\n" " char now0;\n" " strcmp(&now0, sth);\n" "}", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: now0\n", errout_str()); + ASSERT_EQUALS("[test.c:3:13]: (error) Uninitialized variable: now0 [legacyUninitvar]\n", errout_str()); // #2775 - uninitialized struct pointer in subfunction // extracttests.start: struct Fred {int x;}; @@ -3459,7 +3459,7 @@ class TestUninitVar : public TestFixture { " struct Fred *p;\n" " a(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:7]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); // #2946 - FP array is initialized in subfunction checkUninitVar("void a(char *buf) {\n" @@ -3523,7 +3523,7 @@ class TestUninitVar : public TestFixture { " else i = 0;\n" " if (x || i>0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:14]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("void f(int x) {\n" " int i;\n" @@ -3556,7 +3556,7 @@ class TestUninitVar : public TestFixture { " a = y;\n" " return y ? 2*a : 3*a;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:14]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); ASSERT_THROW_INTERNAL(checkUninitVar("void f() {\n" // Don't crash " int a;\n" @@ -3630,7 +3630,7 @@ class TestUninitVar : public TestFixture { " if (!x) i = 0;\n" " if (!x || i>0) {}\n" // <- error "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:4:15]: (warning) Uninitialized variable: i [uninitvar]\n", errout_str()); valueFlowUninit("void f(int x) {\n" " int i;\n" @@ -3645,7 +3645,7 @@ class TestUninitVar : public TestFixture { " else i = 0;\n" " if (x || i>0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:14]: (warning) Uninitialized variable: i [uninitvar]\n", errout_str()); valueFlowUninit("void f(int x) {\n" " int i;\n" @@ -3678,7 +3678,7 @@ class TestUninitVar : public TestFixture { " a = y;\n" " return y ? 2*a : 3*a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:18]: (warning) Uninitialized variable: a [uninitvar]\n", errout_str()); ASSERT_THROW_INTERNAL(valueFlowUninit("void f() {\n" // Don't crash " int a;\n" @@ -3716,7 +3716,7 @@ class TestUninitVar : public TestFixture { " int *p;\n" " int a[ 2 ] = { [ 0 ] = *p++, [ 1 ] = 1 };\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26]: (error) Uninitialized variable: p [uninitvar]\n", errout_str()); valueFlowUninit("void f(int height) {\n" " int a[11];\n" @@ -3761,7 +3761,7 @@ class TestUninitVar : public TestFixture { " }\n" " if (!flag && x==3) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:8]: (warning) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:8:18]: (warning) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("int do_something();\n" // #11983 "int set_st(int *x);\n" @@ -3808,51 +3808,51 @@ class TestUninitVar : public TestFixture { " int x;\n" " x++;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); // extracttests.start: char str[10]; valueFlowUninit("void f() {\n" " int x;\n" " str[x] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" // #7736 " int buf[12];\n" " printf (\"%d\", buf[0] );\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: buf\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Uninitialized variable: buf [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " int x;\n" " int y = x & 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " int x;\n" " int y = 3 & x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " int x;\n" " x = 3 + x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " int x;\n" " x = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); // extracttests.start: struct ABC {int a;}; valueFlowUninit("void f() {\n" " struct ABC *abc;\n" " abc->a = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: abc\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: abc [uninitvar]\n", errout_str()); valueFlowUninit("int f() {\n" " static int x;\n" @@ -3897,13 +3897,13 @@ class TestUninitVar : public TestFixture { " int x;\n" " if (x) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " int x;\n" " if (1 == (3 & x)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); // ?: valueFlowUninit("int f(int *ptr) {\n" @@ -3924,7 +3924,7 @@ class TestUninitVar : public TestFixture { " int x = ({ 1 + 2; });\n" " int y = 1 + (x ? y : y);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: y\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:3:14]: (error) Uninitialized variable: y [legacyUninitvar]\n", "", errout_str()); // >> => initialization / usage { @@ -3936,7 +3936,7 @@ class TestUninitVar : public TestFixture { ASSERT_EQUALS("", errout_str()); valueFlowUninit(code, false); - ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.c:3:14]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); } valueFlowUninit("void f() {\n" @@ -3969,7 +3969,7 @@ class TestUninitVar : public TestFixture { " else { if (y == 2) { x = 1; } }\n" " return x;\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\n", "", errout_str()); valueFlowUninit("void f() {\n" " int x;\n" @@ -3978,7 +3978,7 @@ class TestUninitVar : public TestFixture { " if (y == 3) { }\n" // <- ignore condition " return x;\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: x\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:6:24]: (error) Uninitialized variable: x [legacyUninitvar]\n", "", errout_str()); // initialization in condition valueFlowUninit("void f() {\n" @@ -4002,7 +4002,7 @@ class TestUninitVar : public TestFixture { " if (y == 1) { return; }\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("int f(int x) {\n" " int ret;\n" @@ -4035,7 +4035,7 @@ class TestUninitVar : public TestFixture { " if (foo) break;\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("int f() {\n" " int x;\n" @@ -4043,7 +4043,7 @@ class TestUninitVar : public TestFixture { " if (bar) break;\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); // try/catch : don't warn about exception variable valueFlowUninit("void f() {\n" @@ -4127,7 +4127,7 @@ class TestUninitVar : public TestFixture { " if (x == 0 && (a == 1)) { }\n" "}", true); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " int a;\n" @@ -4172,7 +4172,7 @@ class TestUninitVar : public TestFixture { " else {}\n" " return y;\n" "}"); - TODO_ASSERT_EQUALS("", "[test.cpp:5] -> [test.cpp:7]: (warning) Uninitialized variable: y\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:5:9] -> [test.cpp:7:12]: (warning) Uninitialized variable: y [uninitvar]\n", errout_str()); valueFlowUninit("int f(int a) {\n" // #6583 " int x;\n" @@ -4191,7 +4191,7 @@ class TestUninitVar : public TestFixture { " else y = 123;\n" // <- y is always initialized " return y;\n" "}"); - TODO_ASSERT_EQUALS("", "[test.cpp:5] -> [test.cpp:7]: (warning) Uninitialized variable: y\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:5:9] -> [test.cpp:7:12]: (warning) Uninitialized variable: y [uninitvar]\n", errout_str()); valueFlowUninit("void f(int x) {\n" // #3948 " int value;\n" @@ -4221,7 +4221,7 @@ class TestUninitVar : public TestFixture { " if (x == 1)\n" " v = value;\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: value\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:6:9]: (error) Uninitialized variable: value [legacyUninitvar]\n", "", errout_str()); valueFlowUninit("void f(int x) {\n" " int value;\n" @@ -4230,7 +4230,7 @@ class TestUninitVar : public TestFixture { " if (x == 32) {}\n" " else v = value;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Uninitialized variable: value\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:6:12]: (warning) Uninitialized variable: value [uninitvar]\n", errout_str()); valueFlowUninit("static int x;" // #4773 "int f() {\n" @@ -4325,7 +4325,7 @@ class TestUninitVar : public TestFixture { " int done;\n" " dostuff(1, (AuPointer) &done);\n" // <- It is not conclusive if the "&" is a binary or unary operator. Bailout. "}"); - TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Uninitialized variable: done\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:3:29]: (error) Uninitialized variable: done [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" // #4778 - cast address of uninitialized variable " long a;\n" @@ -4358,7 +4358,7 @@ class TestUninitVar : public TestFixture { " bar(&item);\n" " a = item.a;\n" // <- item.a is not initialized "}", false); - ASSERT_EQUALS("[test.c:6]: (error) Uninitialized variable: item.a\n", errout_str()); + ASSERT_EQUALS("[test.c:6:12]: (error) Uninitialized variable: item.a [uninitvar]\n", errout_str()); valueFlowUninit("struct myst { int a; };\n" "void bar(struct myst* p) { p->a = 0; }\n" @@ -4385,7 +4385,7 @@ class TestUninitVar : public TestFixture { " int i;\n" " return f(i, 1, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:4]: (warning) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:4:12]: (warning) Uninitialized variable: i [uninitvar]\n", errout_str()); valueFlowUninit("int f(int& i, int k) {\n" " if (k)\n" @@ -4396,7 +4396,7 @@ class TestUninitVar : public TestFixture { " int i;\n" " return f(i, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:4]: (warning) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:4:12]: (warning) Uninitialized variable: i [uninitvar]\n", errout_str()); } void uninitStructMember() { // struct members @@ -4405,21 +4405,21 @@ class TestUninitVar : public TestFixture { " struct AB ab;\n" " int a = ab.a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void f(void) {\n" " AB ab;\n" " int a = ab.a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void f(void) {\n" " struct AB ab;\n" " ab.a = ab.a + 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void do_something(const struct AB ab);\n" @@ -4428,7 +4428,7 @@ class TestUninitVar : public TestFixture { " ab.a = 0;\n" " do_something(ab);\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:6]: (error) Uninitialized struct member: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.c:6:18]: (error) Uninitialized struct member: ab.b [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" // #4760 "void do_something(int a);\n" @@ -4436,7 +4436,7 @@ class TestUninitVar : public TestFixture { " struct AB ab;\n" " do_something(ab.a);\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.c:5:18]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void do_something(const struct AB &ab) { a = ab.a; }\n" @@ -4452,21 +4452,21 @@ class TestUninitVar : public TestFixture { " struct AB ab;\n" " int a = ab.a;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.c:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void f(void) {\n" " AB ab1;\n" " AB ab2 = { ab1.a, 0 };\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab1.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:20]: (error) Uninitialized struct member: ab1.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void f(void) {\n" " struct AB ab;\n" " buf[ab.a] = 0;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.c:4:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void f(void) {\n" @@ -4474,7 +4474,7 @@ class TestUninitVar : public TestFixture { " ab.a = 1;\n" " x = ab;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.c:5:9]: (error) Uninitialized struct member: ab.b [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void f(void) {\n" @@ -4482,7 +4482,7 @@ class TestUninitVar : public TestFixture { " ab.a = 1;\n" " x = *(&ab);\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.c:5:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\n", errout_str()); checkUninitVar("void f(void) {\n" " struct AB ab;\n" @@ -4498,7 +4498,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; element->f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\n", errout_str()); checkUninitVar("struct Element {\n" " static void f() { }\n" @@ -4506,7 +4506,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; (*element).f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\n", errout_str()); checkUninitVar("struct Element {\n" " static int v;\n" @@ -4514,7 +4514,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; element->v;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\n", errout_str()); checkUninitVar("struct Element {\n" " static int v;\n" @@ -4522,7 +4522,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; (*element).v;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\n", errout_str()); checkUninitVar("struct Element {\n" " void f() { }\n" @@ -4530,7 +4530,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; element->f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\n", errout_str()); checkUninitVar("struct Element {\n" " void f() { }\n" @@ -4538,7 +4538,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; (*element).f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\n", errout_str()); checkUninitVar("struct Element {\n" " int v;\n" @@ -4546,7 +4546,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; element->v;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\n", errout_str()); checkUninitVar("struct Element {\n" " int v;\n" @@ -4554,7 +4554,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; (*element).v;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" // pass struct member by address "void f(void) {\n" @@ -4590,7 +4590,7 @@ class TestUninitVar : public TestFixture { " uninitvar_funcArgInTest(&ab);\n" " x = ab;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false, $.s = &s)); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.c:5:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; };\n" "void f(void) {\n" @@ -4631,7 +4631,7 @@ class TestUninitVar : public TestFixture { " struct AB ab;\n" " strcpy(x, ab.a);\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - TODO_ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab.a\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\n", "", errout_str()); checkUninitVar("struct AB { int a; };\n" "void f(void) {\n" @@ -4666,7 +4666,7 @@ class TestUninitVar : public TestFixture { " ab.get();\n" " x = ab;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; void dostuff() {} };\n" "void f(void) {\n" @@ -4754,7 +4754,7 @@ class TestUninitVar : public TestFixture { TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: abc.a\n" "[test.cpp:5]: (error) Uninitialized struct member: abc.b\n" "[test.cpp:5]: (error) Uninitialized struct member: abc.c\n", - "[test.cpp:6]: (error) Uninitialized struct member: abc.b\n", + "[test.cpp:6:10]: (error) Uninitialized struct member: abc.b [uninitStructMember]\n", errout_str()); checkUninitVar("struct ABC { int a; int b; int c; };\n" @@ -4777,7 +4777,7 @@ class TestUninitVar : public TestFixture { " ab.a = 0;\n" " return ab.b;\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.c:5:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void f(void) {\n" @@ -4793,14 +4793,14 @@ class TestUninitVar : public TestFixture { " s.a = 0;\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: s.b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized struct member: s.b [uninitStructMember]\n", errout_str()); checkUninitVar("struct S { int a; int b; };\n" // #9810 "void f(void) {\n" " struct S s;\n" " return s.a ? 1 : 2;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: s.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Uninitialized struct member: s.a [uninitStructMember]\n", errout_str()); // checkIfForWhileHead checkUninitVar("struct FRED {\n" @@ -4825,14 +4825,14 @@ class TestUninitVar : public TestFixture { " fred.a = do_something();\n" " if (fred.b == 0) { }\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:9]: (error) Uninitialized struct member: fred.b\n", errout_str()); + ASSERT_EQUALS("[test.c:9:8]: (error) Uninitialized struct member: fred.b [uninitStructMember]\n", errout_str()); checkUninitVar("struct Fred { int a; };\n" "void f() {\n" " struct Fred fred;\n" " if (fred.a==1) {}\n" "}", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: fred.a\n", errout_str()); + ASSERT_EQUALS("[test.c:4:9]: (error) Uninitialized struct member: fred.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct S { int n; int m; };\n" "void f(void) {\n" @@ -4860,7 +4860,7 @@ class TestUninitVar : public TestFixture { " struct AB ab;\n" " while (x) { ab.a = ab.a + 1; }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:24]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; };\n" "void f() {\n" @@ -4894,7 +4894,7 @@ class TestUninitVar : public TestFixture { " int a = ab.a;\n" " int b = ab.b;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (error) Uninitialized struct member: ab.b [uninitStructMember]\n", errout_str()); // STL class member checkUninitVar("struct A {\n" @@ -4927,7 +4927,7 @@ class TestUninitVar : public TestFixture { " A a;\n" " x = a.m;\n" "}", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:7]: (error) Uninitialized struct member: a.m\n", errout_str()); + ASSERT_EQUALS("[test.c:7:9]: (error) Uninitialized struct member: a.m [uninitStructMember]\n", errout_str()); // Type with constructor checkUninitVar("class C { C(); }\n" @@ -4999,7 +4999,7 @@ class TestUninitVar : public TestFixture { " x = x + 1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int x;\n" @@ -5007,18 +5007,18 @@ class TestUninitVar : public TestFixture { " x = x + 1;\n" " } while (a);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " for (int x = x; x < 10; x++) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); // extracttests.start: struct Element{Element*Next();}; checkUninitVar("void f() {\n" " for (Element *ptr3 = ptr3->Next(); ptr3; ptr3 = ptr3->Next()) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: ptr3\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26]: (error) Uninitialized variable: ptr3 [legacyUninitvar]\n", errout_str()); // extracttests.start: int a; checkUninitVar("void f() {\n" @@ -5051,7 +5051,7 @@ class TestUninitVar : public TestFixture { " int x;\n" " for (int i = 0; i < 10; i += x) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:34]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("int f() {\n" " int i;\n" @@ -5099,7 +5099,7 @@ class TestUninitVar : public TestFixture { " do_something(a);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:16]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); checkUninitVar("struct AB {int a; int b;};\n" "void f(void) {\n" @@ -5109,7 +5109,7 @@ class TestUninitVar : public TestFixture { " do_something(a);\n" " }\n" "}\n", dinit(CheckUninitVarOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.c:5:18]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("void f(int i) {\n" // #4569 fp " float *buffer;\n" @@ -5168,7 +5168,7 @@ class TestUninitVar : public TestFixture { " while(*p && *p == '_')\n" " p++;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: *p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Memory is allocated but not initialized: *p [uninitdata]\n", errout_str()); // #6646 - init in for loop checkUninitVar("void f() {\n" // No FP @@ -5182,7 +5182,7 @@ class TestUninitVar : public TestFixture { " for (int i;;i++)\n" " a=i;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (error) Uninitialized variable: i [legacyUninitvar]\n", errout_str()); checkUninitVar("namespace N {\n" // #7377 " template\n" @@ -5195,7 +5195,7 @@ class TestUninitVar : public TestFixture { " r += x;\n" " return r;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:17]: (error) Uninitialized variable: x [legacyUninitvar]\n", errout_str()); } void uninitvar2_4494() { @@ -5220,11 +5220,11 @@ class TestUninitVar : public TestFixture { " void fg(void) { char *p; Foo::f1(p); }\n" " void fh(void) { char *p; Foo::f2(p); }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: p\n" - "[test.cpp:8]: (error) Uninitialized variable: p\n" - "[test.cpp:13]: (error) Uninitialized variable: p\n" - "[test.cpp:15]: (error) Uninitialized variable: p\n" - "[test.cpp:17]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:39]: (error) Uninitialized variable: p [legacyUninitvar]\n" + "[test.cpp:8:45]: (error) Uninitialized variable: p [legacyUninitvar]\n" + "[test.cpp:13:33]: (error) Uninitialized variable: p [legacyUninitvar]\n" + "[test.cpp:15:43]: (error) Uninitialized variable: p [legacyUninitvar]\n" + "[test.cpp:17:45]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("class Fred {\n" "public:\n" @@ -5235,7 +5235,7 @@ class TestUninitVar : public TestFixture { " char *p;\n" " fred.f1(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:13]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); checkUninitVar("class Fred {\n" "public:\n" @@ -5258,7 +5258,7 @@ class TestUninitVar : public TestFixture { " char *p;\n" " fred.wilma.barney.betty.f1(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:20]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:20:32]: (error) Uninitialized variable: p [legacyUninitvar]\n", errout_str()); } void uninitvar2_malloc() { @@ -5266,21 +5266,21 @@ class TestUninitVar : public TestFixture { " int *p = (int*)malloc(40);\n" " return *p;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Memory is allocated but not initialized: p [uninitdata]\n", errout_str()); checkUninitVar("void f() {\n" " int *p = (int*)malloc(40);\n" " int var = *p;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Memory is allocated but not initialized: p [uninitdata]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "int f() {\n" " struct AB *ab = (AB*)malloc(sizeof(struct AB));\n" " return ab->a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: ab\n" - "[test.cpp:4]: (error) Uninitialized struct member: ab.a\n", + ASSERT_EQUALS("[test.cpp:4:12]: (error) Memory is allocated but not initialized: ab [uninitdata]\n" + "[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct t_udf_file { int dir_left; };\n" @@ -5322,7 +5322,7 @@ class TestUninitVar : public TestFixture { " p = (int*)malloc(256);\n" " return *p;\n" // error "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Memory is allocated but not initialized: p [uninitdata]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "int f(struct AB *ab) {\n" @@ -5330,7 +5330,7 @@ class TestUninitVar : public TestFixture { " ab = (AB*)malloc(sizeof(struct AB));\n" " return ab->a;\n" // error "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\n", errout_str()); checkUninitVar("struct AB { int a; int b; };\n" "void do_something(struct AB *ab);\n" // unknown function @@ -5457,7 +5457,7 @@ class TestUninitVar : public TestFixture { " init(dp);\n" "}", dinit(CheckUninitVarOptions, $.cpp = false)); // Unknown type - TODO_ASSERT_EQUALS("", "[test.c:4]: (error) Uninitialized variable: d\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.c:4:14]: (error) Uninitialized variable: d [legacyUninitvar]\n", errout_str()); } void valueFlowUninit_(const char* file, int line, const char code[], bool cpp = true) @@ -5495,20 +5495,20 @@ class TestUninitVar : public TestFixture { " s.x = 42;\n" " bar(&s);\n" "}"); - ASSERT_EQUALS("[test.cpp:18] -> [test.cpp:12] -> [test.cpp:8]: (warning) Uninitialized variable: s->flag\n", errout_str()); + ASSERT_EQUALS("[test.cpp:18:9] -> [test.cpp:12:13] -> [test.cpp:8:15]: (warning) Uninitialized variable: s->flag [uninitvar]\n", errout_str()); // Ticket #2207 - False negative valueFlowUninit("void foo() {\n" " int a;\n" " b = c - a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); valueFlowUninit("void foo() {\n" " int a;\n" " b = a - c;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); // Ticket #6455 - some compilers allow const variables to be uninitialized // extracttests.disable @@ -5516,14 +5516,14 @@ class TestUninitVar : public TestFixture { " const int a;\n" " b = c - a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); // extracttests.enable valueFlowUninit("void foo() {\n" " int *p;\n" " realloc(p,10);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Uninitialized variable: p [uninitvar]\n", errout_str()); valueFlowUninit("void foo() {\n" // #5240 " char *p = malloc(100);\n" @@ -5542,7 +5542,7 @@ class TestUninitVar : public TestFixture { " int x;\n" " switch (x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("int f() {\n" " int x;\n" @@ -5561,7 +5561,7 @@ class TestUninitVar : public TestFixture { " int a;\n" " int x[] = {a,2};\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); valueFlowUninit("void foo()\n" "{\n" @@ -5640,7 +5640,7 @@ class TestUninitVar : public TestFixture { " p->Write();\n" "}"); TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:10]: (warning) Uninitialized variable: p\n", - "[test.cpp:8] -> [test.cpp:10]: (warning) Uninitialized variable: p.rIo\n", + "[test.cpp:8:9] -> [test.cpp:10:5]: (warning) Uninitialized variable: p.rIo [uninitvar]\n", errout_str()); // Unknown types @@ -5713,7 +5713,7 @@ class TestUninitVar : public TestFixture { " arc << p;\n" // <- TODO initialization? " return *p;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Uninitialized variable: p [uninitvar]\n", errout_str()); // #4320 valueFlowUninit("void f() {\n" @@ -5721,7 +5721,7 @@ class TestUninitVar : public TestFixture { " a << 1;\n" " return a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); // #9750 valueFlowUninit("struct S {\n" @@ -5961,7 +5961,7 @@ class TestUninitVar : public TestFixture { " }\n" " printf(\"\", value);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:9]: (warning) Uninitialized variable: value\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:13] -> [test.cpp:9:16]: (warning) Uninitialized variable: value [uninitvar]\n", errout_str()); valueFlowUninit("void f(int x)\n" "{\n" @@ -6035,14 +6035,14 @@ class TestUninitVar : public TestFixture { " int me;\n" " dowork(me);\n" // <- me is uninitialized "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: me\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:13]: (error) Uninitialized variable: me [uninitvar]\n", errout_str()); valueFlowUninit("int foo() {\n" " int x;\n" " int a = x;\n" // <- x is uninitialized " return a;\n" // <- a has been initialized "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); // #10468 valueFlowUninit("uint32_t foo(uint32_t in) {\n" @@ -6063,7 +6063,7 @@ class TestUninitVar : public TestFixture { " else\n" " return -1;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:6:16]: (warning) Uninitialized variable: a [uninitvar]\n", errout_str()); // #9772 valueFlowUninit("int func(void) {\n" @@ -6124,7 +6124,7 @@ class TestUninitVar : public TestFixture { " char src, dest;\n" " std::memcpy(&dest, &src, 1);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: &src\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (error) Uninitialized variable: &src [uninitvar]\n", errout_str()); // #10988 valueFlowUninit("void f(const void* ptr, bool* result) {\n" @@ -6151,7 +6151,7 @@ class TestUninitVar : public TestFixture { " A a;\n" " g(a.x);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: a.x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9]: (error) Uninitialized variable: a.x [uninitvar]\n", errout_str()); valueFlowUninit("struct A {\n" " int x;\n" @@ -6162,13 +6162,13 @@ class TestUninitVar : public TestFixture { " A* p = &a;\n" " g(p->x);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: p->x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:10]: (error) Uninitialized variable: p->x [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " int a;\n" " a++;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); // #11006 valueFlowUninit("int g(int);\n" @@ -6187,7 +6187,7 @@ class TestUninitVar : public TestFixture { " increment(n);\n" " return n;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (warning) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:15] -> [test.cpp:1:28]: (warning) Uninitialized variable: i [uninitvar]\n", errout_str()); // #11412 valueFlowUninit("void f(int n) {\n" @@ -6243,7 +6243,7 @@ class TestUninitVar : public TestFixture { " }\n" " printf(\"nok = %d\\n\", nok);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: nok\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:26]: (error) Uninitialized variable: nok [uninitvar]\n", errout_str()); // #7475 valueFlowUninit("struct S {\n" @@ -6253,7 +6253,7 @@ class TestUninitVar : public TestFixture { " s_t s;\n" " printf(\"%d\", s.a);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: s.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:20]: (error) Uninitialized variable: s.a [uninitvar]\n", errout_str()); valueFlowUninit("void f(char* src) {\n" // #11608 " char envar[64], *cp, c;\n" @@ -6374,13 +6374,13 @@ class TestUninitVar : public TestFixture { " int* p = &x;\n" " return i >> *p;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: *p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (error) Uninitialized variable: *p [uninitvar]\n", errout_str()); valueFlowUninit("void f(int& x) {\n" " int i;\n" " x = i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Uninitialized variable: i [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" // #11890 " int x;\n" @@ -6399,7 +6399,7 @@ class TestUninitVar : public TestFixture { " int &q = s;\n" " foo(q);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: q\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:9]: (error) Uninitialized variable: q [uninitvar]\n", errout_str()); valueFlowUninit("int g();\n" // #12082 "void f() {\n" @@ -6415,7 +6415,7 @@ class TestUninitVar : public TestFixture { " f(a, b);\n" " printf(\"%s\", a);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); valueFlowUninit("void usage(const char *);\n" // #10330 "int main(int argc, char* argv[]) {\n" @@ -6435,7 +6435,7 @@ class TestUninitVar : public TestFixture { " pwd = getpwnam(user);\n" " if (pwd == NULL) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:15] -> [test.cpp:17]: (warning) Uninitialized variable: pwd\n", errout_str()); + ASSERT_EQUALS("[test.cpp:15:9] -> [test.cpp:17:9]: (warning) Uninitialized variable: pwd [uninitvar]\n", errout_str()); valueFlowUninit("size_t Read(unsigned char* buffer, size_t len);\n" // #11540 "void f() {\n" @@ -6458,7 +6458,7 @@ class TestUninitVar : public TestFixture { " char buf[10];\n" " g(buf);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: buf\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: buf [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" // #12288 " char buf[100];\n" @@ -6497,7 +6497,7 @@ class TestUninitVar : public TestFixture { " struct S s;\n" " s.p[0] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s.p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Uninitialized variable: s.p [uninitvar]\n", errout_str()); // #12460 valueFlowUninit("typedef struct {\n" @@ -6518,7 +6518,7 @@ class TestUninitVar : public TestFixture { " int i;\n" " f(i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (warning) Uninitialized variable: r\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:1:22]: (warning) Uninitialized variable: r [uninitvar]\n", errout_str()); // #12197 valueFlowUninit("void f() {\n" @@ -6565,9 +6565,9 @@ class TestUninitVar : public TestFixture { " std::array a;\n" " return a[1];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:12]: (error) Uninitialized variable: a\n" - "[test.cpp:12]: (error) Uninitialized variable: b\n" - "[test.cpp:16]: (error) Uninitialized variable: a\n", + ASSERT_EQUALS("[test.cpp:12:12]: (error) Uninitialized variable: a [uninitvar]\n" + "[test.cpp:12:22]: (error) Uninitialized variable: b [uninitvar]\n" + "[test.cpp:16:12]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" // # 12932 @@ -6579,7 +6579,7 @@ class TestUninitVar : public TestFixture { " std::array c;\n" " return c.front();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:12]: (error) Uninitialized variable: c [uninitvar]\n", errout_str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value @@ -6592,7 +6592,7 @@ class TestUninitVar : public TestFixture { " memcpy(wcsin, x, sizeof(wcsstruct));\n" // <- warning " x->wcsprm = NULL;\n" // <- no warning "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:19]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("struct wcsstruct {\n" " int *wcsprm;\n" @@ -6603,7 +6603,7 @@ class TestUninitVar : public TestFixture { " sizeof(x);\n" " x->wcsprm = NULL;\n" // <- Warn "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); valueFlowUninit("struct wcsstruct {\n" " int *wcsprm;\n" @@ -6616,7 +6616,7 @@ class TestUninitVar : public TestFixture { " x->wcsprm = NULL;\n" // <- warn here " init_wcs(x);\n" // <- no warning "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); } void uninitvar_ipa() { @@ -6631,7 +6631,7 @@ class TestUninitVar : public TestFixture { " someType_t gVar;\n" " bar(&gVar);\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: &gVar\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:9]: (error) Uninitialized variable: &gVar [uninitvar]\n", errout_str()); valueFlowUninit("typedef struct\n" "{\n" @@ -6662,7 +6662,7 @@ class TestUninitVar : public TestFixture { " struct pc_data *pcdata;\n" " if ( *pcdata->wampiryzm.strefa == '\\0' ) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: pcdata\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:11]: (error) Uninitialized variable: pcdata [uninitvar]\n", errout_str()); // # 9293 valueFlowUninit("struct S {\n" @@ -6675,7 +6675,7 @@ class TestUninitVar : public TestFixture { " int * x = &s1.x;\n" " struct S s2 = {*x, 0};\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: *x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:20]: (error) Uninitialized variable: *x [uninitvar]\n", errout_str()); valueFlowUninit("struct S {\n" " int x;\n" @@ -6688,7 +6688,7 @@ class TestUninitVar : public TestFixture { " int * x = &s1.x;\n" " s2.x = *x;\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Uninitialized variable: *x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:12]: (error) Uninitialized variable: *x [uninitvar]\n", errout_str()); valueFlowUninit("void f(bool * x) {\n" " *x = false;\n" @@ -6758,7 +6758,7 @@ class TestUninitVar : public TestFixture { " c->x = 42;\n" " return c->x;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: c\n", + ASSERT_EQUALS("[test.cpp:6:5]: (error) Uninitialized variable: c [uninitvar]\n", errout_str()); valueFlowUninit("struct A {\n" @@ -6833,7 +6833,7 @@ class TestUninitVar : public TestFixture { " bool copied_all = true;\n" " g(&copied_all, 5, 6, &bytesCopied);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (warning) Uninitialized variable: *buflen\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:24] -> [test.cpp:2:18]: (warning) Uninitialized variable: *buflen [uninitvar]\n", errout_str()); // # 9953 valueFlowUninit("uint32_t f(uint8_t *mem) {\n" @@ -6853,7 +6853,7 @@ class TestUninitVar : public TestFixture { " ab.a = 1;\n" " if (ab.b == 2) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: ab.b [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; int b; };\n" "void do_something(const struct AB &ab) { a = ab.a; }\n" @@ -6871,7 +6871,7 @@ class TestUninitVar : public TestFixture { " ab.a = 0;\n" " do_something(ab);\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (warning) Uninitialized variable: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:18] -> [test.cpp:2:49]: (warning) Uninitialized variable: ab.b [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; int b; };\n" "void f(void) {\n" @@ -6879,14 +6879,14 @@ class TestUninitVar : public TestFixture { " int a = ab.a;\n" "}\n", false); - ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; int b; };\n" "void f(void) {\n" " AB ab1;\n" " AB ab2 = { ab1.a, 0 };\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ab1.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:20]: (error) Uninitialized variable: ab1.a [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; int b; };\n" "void f(void) {\n" @@ -6894,7 +6894,7 @@ class TestUninitVar : public TestFixture { " buf[ab.a] = 0;\n" "}\n", false); - ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.c:4:12]: (error) Uninitialized variable: ab.a [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; int b; };\n" "void f(void) {\n" @@ -6903,7 +6903,7 @@ class TestUninitVar : public TestFixture { " x = ab;\n" "}\n", false); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized variable: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.c:5:9]: (error) Uninitialized variable: ab.b [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; int b; };\n" "void f(void) {\n" @@ -6912,7 +6912,7 @@ class TestUninitVar : public TestFixture { " x = *(&ab);\n" "}\n", false); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized variable: *(&ab).b\n", errout_str()); + ASSERT_EQUALS("[test.c:5:9]: (error) Uninitialized variable: *(&ab).b [uninitvar]\n", errout_str()); valueFlowUninit("void f(void) {\n" " struct AB ab;\n" @@ -6929,7 +6929,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; element->f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\n", errout_str()); valueFlowUninit("struct Element {\n" " static void f() { }\n" @@ -6937,7 +6937,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; (*element).f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\n", errout_str()); valueFlowUninit("struct Element {\n" " static int v;\n" @@ -6945,7 +6945,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; element->v;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\n", errout_str()); valueFlowUninit("struct Element {\n" " static int v;\n" @@ -6953,7 +6953,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; (*element).v;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\n", errout_str()); valueFlowUninit("struct Element {\n" " void f() { }\n" @@ -6961,7 +6961,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; element->f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\n", errout_str()); valueFlowUninit("struct Element {\n" " void f() { }\n" @@ -6969,7 +6969,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; (*element).f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\n", errout_str()); valueFlowUninit("struct Element {\n" " int v;\n" @@ -6977,7 +6977,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; element->v;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\n", errout_str()); valueFlowUninit("struct Element {\n" " int v;\n" @@ -6985,7 +6985,7 @@ class TestUninitVar : public TestFixture { "void test() {\n" " Element *element; (*element).v;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; int b; };\n" // pass struct member by address "void f(void) {\n" @@ -7039,7 +7039,7 @@ class TestUninitVar : public TestFixture { " strcpy(x, ab.a);\n" "}\n", false); - TODO_ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab.a\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\n", "", errout_str()); valueFlowUninit("struct AB { int a; };\n" "void f(void) {\n" @@ -7076,7 +7076,7 @@ class TestUninitVar : public TestFixture { " ab.get();\n" " x = ab;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ab\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Uninitialized variable: ab [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; void dostuff() {} };\n" "void f(void) {\n" @@ -7163,7 +7163,7 @@ class TestUninitVar : public TestFixture { " foo(123, &abc);\n" " return abc.b;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: &abc\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: &abc [uninitvar]\n", errout_str()); valueFlowUninit("struct ABC { int a; int b; int c; };\n" "void foo() {\n" @@ -7186,7 +7186,7 @@ class TestUninitVar : public TestFixture { " return ab.b;\n" "}\n", false); - ASSERT_EQUALS("[test.c:5]: (error) Uninitialized variable: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.c:5:15]: (error) Uninitialized variable: ab.b [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; int b; };\n" "void f(void) {\n" @@ -7203,14 +7203,14 @@ class TestUninitVar : public TestFixture { " s.a = 0;\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s.b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Uninitialized variable: s.b [uninitvar]\n", errout_str()); valueFlowUninit("struct S { int a; int b; };\n" // #9810 "void f(void) {\n" " struct S s;\n" " return s.a ? 1 : 2;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Uninitialized variable: s.a [uninitvar]\n", errout_str()); // checkIfForWhileHead valueFlowUninit("struct FRED {\n" @@ -7237,7 +7237,7 @@ class TestUninitVar : public TestFixture { " if (fred.b == 0) { }\n" "}\n", false); - ASSERT_EQUALS("[test.c:9]: (error) Uninitialized variable: fred.b\n", errout_str()); + ASSERT_EQUALS("[test.c:9:13]: (error) Uninitialized variable: fred.b [uninitvar]\n", errout_str()); valueFlowUninit("struct Fred { int a; };\n" "void f() {\n" @@ -7245,7 +7245,7 @@ class TestUninitVar : public TestFixture { " if (fred.a==1) {}\n" "}", false); - ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: fred.a\n", errout_str()); + ASSERT_EQUALS("[test.c:4:14]: (error) Uninitialized variable: fred.a [uninitvar]\n", errout_str()); valueFlowUninit("struct S { int n; int m; };\n" "void f(void) {\n" @@ -7274,7 +7274,7 @@ class TestUninitVar : public TestFixture { " struct AB ab;\n" " while (x) { ab.a = ab.a + 1; }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ab.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:27]: (error) Uninitialized variable: ab.a [uninitvar]\n", errout_str()); valueFlowUninit("struct AB { int a; };\n" "void f() {\n" @@ -7308,7 +7308,7 @@ class TestUninitVar : public TestFixture { " int a = ab.a;\n" " int b = ab.b;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: ab.b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:16]: (error) Uninitialized variable: ab.b [uninitvar]\n", errout_str()); // STL class member valueFlowUninit("struct A {\n" @@ -7343,7 +7343,7 @@ class TestUninitVar : public TestFixture { " x = a.m;\n" "}", false); - ASSERT_EQUALS("[test.c:7]: (error) Uninitialized variable: a.m\n", errout_str()); + ASSERT_EQUALS("[test.c:7:11]: (error) Uninitialized variable: a.m [uninitvar]\n", errout_str()); // Type with constructor valueFlowUninit("class C { C(); }\n" @@ -7412,7 +7412,7 @@ class TestUninitVar : public TestFixture { " abc.a = 1;\n" " setabc(123, &abc);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (warning) Uninitialized variable: abc->b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:17] -> [test.cpp:3:25]: (warning) Uninitialized variable: abc->b [uninitvar]\n", errout_str()); valueFlowUninit("struct S { int* p; };\n" // #10463 "void f(S* in) {\n" @@ -7420,7 +7420,7 @@ class TestUninitVar : public TestFixture { " memcpy(in, s, sizeof(S));\n" " s->p = NULL;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:16]: (error) Uninitialized variable: s [uninitvar]\n", errout_str()); valueFlowUninit("struct S {\n" // #11321 " int a = 0;\n" @@ -7518,12 +7518,12 @@ class TestUninitVar : public TestFixture { " S s;\n" " if (s.t.j-- < 3) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: s.i\n" - "[test.cpp:11]: (error) Uninitialized variable: s.i\n" - "[test.cpp:15]: (error) Uninitialized variable: s.i\n" - "[test.cpp:19]: (error) Uninitialized variable: s.i\n" - "[test.cpp:23]: (error) Uninitialized variable: s.t.j\n" - "[test.cpp:27]: (error) Uninitialized variable: s.t.j\n", + ASSERT_EQUALS("[test.cpp:7:9]: (error) Uninitialized variable: s.i [uninitvar]\n" + "[test.cpp:11:7]: (error) Uninitialized variable: s.i [uninitvar]\n" + "[test.cpp:15:7]: (error) Uninitialized variable: s.i [uninitvar]\n" + "[test.cpp:19:13]: (error) Uninitialized variable: s.i [uninitvar]\n" + "[test.cpp:23:11]: (error) Uninitialized variable: s.t.j [uninitvar]\n" + "[test.cpp:27:13]: (error) Uninitialized variable: s.t.j [uninitvar]\n", errout_str()); valueFlowUninit("struct S { int x; };\n" // #6933 @@ -7539,9 +7539,9 @@ class TestUninitVar : public TestFixture { " int i;\n" " std::vector v(i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n" - "[test.cpp:8]: (error) Uninitialized variable: i\n" - "[test.cpp:12]: (error) Uninitialized variable: i\n", + ASSERT_EQUALS("[test.cpp:4:9]: (error) Uninitialized variable: i [uninitvar]\n" + "[test.cpp:8:10]: (error) Uninitialized variable: i [uninitvar]\n" + "[test.cpp:12:24]: (error) Uninitialized variable: i [uninitvar]\n", errout_str()); valueFlowUninit("struct S {\n" @@ -7564,7 +7564,7 @@ class TestUninitVar : public TestFixture { " p = new S();\n" " p->f();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Uninitialized variable: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:9:5]: (warning) Uninitialized variable: p [uninitvar]\n", errout_str()); // #12461 valueFlowUninit("struct stry_type {\n" @@ -7589,7 +7589,7 @@ class TestUninitVar : public TestFixture { " st_arr[0].out = &arr;\n" " int len = strlen(arr);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: arr\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:20]: (error) Uninitialized variable: arr [uninitvar]\n", errout_str()); valueFlowUninit("struct S {\n" " void *out;\n" @@ -7622,7 +7622,7 @@ class TestUninitVar : public TestFixture { " double d;\n" " S s(d);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: d\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9]: (error) Uninitialized variable: d [uninitvar]\n", errout_str()); valueFlowUninit("struct S {\n" " explicit S(double v) : m(v) {}\n" @@ -7632,7 +7632,7 @@ class TestUninitVar : public TestFixture { " double d;\n" " S s{ d };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: d\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10]: (error) Uninitialized variable: d [uninitvar]\n", errout_str()); valueFlowUninit("struct S { int x; int y; };\n" "int f() {\n" @@ -7648,7 +7648,7 @@ class TestUninitVar : public TestFixture { " s.x = 0;\n" " return (&s)->y;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s.y\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:16]: (error) Uninitialized variable: s.y [uninitvar]\n", errout_str()); } void valueFlowUninitForLoop() @@ -7658,7 +7658,7 @@ class TestUninitVar : public TestFixture { " std::cout << ++b << std::endl;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:24]: (error) Uninitialized variable: b [uninitvar]\n", errout_str()); } void uninitvar_memberfunction() { @@ -7670,7 +7670,7 @@ class TestUninitVar : public TestFixture { " C *c;\n" " if (c->x() == 4) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:9]: (error) Uninitialized variable: c [uninitvar]\n", errout_str()); valueFlowUninit("struct A { \n" " int i; \n" @@ -7692,7 +7692,7 @@ class TestUninitVar : public TestFixture { " Foo* foo;\n" " foo->bar = 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: foo\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:3]: (error) Uninitialized variable: foo [uninitvar]\n", errout_str()); } void uninitvarDesignatedInitializers() { @@ -7719,20 +7719,20 @@ class TestUninitVar : public TestFixture { " char a[10];\n" " char c = *a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); // extracttests.start: extern const int SIZE; checkUninitVar("void f() {\n" " char a[SIZE+10];\n" " char c = *a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " char a[10];\n" " *a += 10;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Uninitialized variable: a [legacyUninitvar]\n", errout_str()); checkUninitVar("void f() {\n" " int a[10][10];\n" @@ -7754,20 +7754,20 @@ class TestUninitVar : public TestFixture { " char a[10];\n" " char c = *a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: *a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Uninitialized variable: *a [uninitvar]\n", errout_str()); // extracttests.start: extern const int SIZE; valueFlowUninit("void f() {\n" " char a[SIZE+10];\n" " char c = *a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: *a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Uninitialized variable: *a [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " char a[10];\n" " *a += 10;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: *a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: *a [uninitvar]\n", errout_str()); valueFlowUninit("void f() {\n" " int a[10][10];\n" @@ -7850,7 +7850,7 @@ class TestUninitVar : public TestFixture { " A::B b;\n" " x.push_back(b);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:17]: (error) Uninitialized variable: b [uninitvar]\n", errout_str()); valueFlowUninit("struct A {\n" " struct B {\n" @@ -7874,7 +7874,7 @@ class TestUninitVar : public TestFixture { " A a;\n" " x.push_back(a);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:17]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); valueFlowUninit("struct S { struct T { int* p; } t[2]; };\n" // #11018 "void f() {\n" @@ -7893,7 +7893,7 @@ class TestUninitVar : public TestFixture { " int x = -3;\n" " int y = x < (1, s.i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s.i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (error) Uninitialized variable: s.i [uninitvar]\n", errout_str()); valueFlowUninit("struct S { int x; };\n" // #11353 "struct S f() {\n" @@ -7932,7 +7932,7 @@ class TestUninitVar : public TestFixture { " int x;\n" " f(&x);\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Using argument p that points at uninitialized variable x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:4] -> [test.cpp:2:10]: (error) Using argument p that points at uninitialized variable x [ctuuninitvar]\n", errout_str()); ctu("void use(int *p) { a = *p + 3; }\n" "void call(int x, int *p) { x++; use(p); }\n" @@ -7940,7 +7940,7 @@ class TestUninitVar : public TestFixture { " int x;\n" " call(4,&x);\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2] -> [test.cpp:1]: (error) Using argument p that points at uninitialized variable x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7] -> [test.cpp:2:33] -> [test.cpp:1:25]: (error) Using argument p that points at uninitialized variable x [ctuuninitvar]\n", errout_str()); ctu("void dostuff(int *x, int *y) {\n" " if (!var)\n" @@ -7990,7 +7990,7 @@ class TestUninitVar : public TestFixture { " increment(n);\n" " return n;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Using argument i that points at uninitialized variable n\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14] -> [test.cpp:1:28]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\n", errout_str()); ctu("void increment(int* i) { ++(*i); }\n" "int f() {\n" @@ -7998,7 +7998,7 @@ class TestUninitVar : public TestFixture { " increment(&n);\n" " return n;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Using argument i that points at uninitialized variable n\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14] -> [test.cpp:1:30]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\n", errout_str()); ctu("typedef struct { int type; int id; } Stem;\n" "void lookupStem(recodeCtx h, Stem *stem) {\n" @@ -8017,7 +8017,7 @@ class TestUninitVar : public TestFixture { " increment(n);\n" " return n;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Using argument i that points at uninitialized variable n\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14] -> [test.cpp:1:28]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\n", errout_str()); } }; From 5874d3e0c59f5d6b7802aa3fb7fe5aed8a3f1be1 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 16 May 2025 23:17:51 +0200 Subject: [PATCH 3/3] TestCondition: added errors IDs and columns to expected output --- test/testcondition.cpp | 842 ++++++++++++++++++++--------------------- 1 file changed, 421 insertions(+), 421 deletions(-) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index f2c680a5981..4e19837f37c 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -43,7 +43,7 @@ class TestCondition : public TestFixture { ""; settings1 = settingsBuilder(settings1).libraryxml(cfg).build(); - // TODO: mNewTemplate = true; + mNewTemplate = true; TEST_CASE(assignAndCompare); // assignment and comparison don't match TEST_CASE(mismatchingBitAnd); // overlapping bitmasks TEST_CASE(comparison); // CheckCondition::comparison test cases @@ -170,21 +170,21 @@ class TestCondition : public TestFixture { " int y = x & 4;\n" " if (y == 3);\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\n", errout_str()); check("void foo(int x)\n" "{\n" " int y = x & 4;\n" " if (y != 3);\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\n", errout_str()); // | check("void foo(int x) {\n" " int y = x | 0x14;\n" " if (y == 0x710);\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\n", errout_str()); check("void foo(int x) {\n" " int y = x | 0x14;\n" @@ -197,26 +197,26 @@ class TestCondition : public TestFixture { " int y = (x+1) | 1;\n" " if (y == 2);\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\n", errout_str()); check("void foo() {\n" " int y = 1 | x();\n" " if (y == 2);\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\n", errout_str()); // multiple conditions check("void foo(int x) {\n" " int y = x & 4;\n" " if ((y == 3) && (z == 1));\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\n", errout_str()); check("void foo(int x) {\n" " int y = x & 4;\n" " if ((x==123) || ((y == 3) && (z == 1)));\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\n", errout_str()); check("void f(int x) {\n" " int y = x & 7;\n" @@ -230,14 +230,14 @@ class TestCondition : public TestFixture { " if (z) y=0;\n" " else { if (y==8); }\n" // always false "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\n", errout_str()); // while check("void f(int x) {\n" " int y = x & 7;\n" " while (y==8);\n" // local variable => always false "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\n", errout_str()); check("void f(int x) {\n" " extern int y; y = x & 7;\n" @@ -263,7 +263,7 @@ class TestCondition : public TestFixture { " }\n" "}"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:6]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true.\n", + "[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\n", errout_str()); check("void g(int &x);\n" @@ -282,7 +282,7 @@ class TestCondition : public TestFixture { " do_something();\n" " if (y==8);\n" // local variable => always false "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\n", errout_str()); check("void f(int x) {\n" " int y = x & 7;\n" @@ -297,7 +297,7 @@ class TestCondition : public TestFixture { " do_something(y);\n" " if (y==8);\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\n", errout_str()); check("void f(int x) {\n" " extern int y; y = x & 7;\n" @@ -349,8 +349,8 @@ class TestCondition : public TestFixture { " if (&rHitObject) {}\n" " else if (rHitObject.IsClosedObj() && !&rHitObject) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Condition '&rHitObject' is always true\n" - "[test.cpp:3]: (style) Condition '!&rHitObject' is always false\n", + ASSERT_EQUALS("[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\n" + "[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\n", errout_str()); // #5695: increment @@ -370,7 +370,7 @@ class TestCondition : public TestFixture { " if (x != 5) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\n", errout_str()); check("void f(int a) {\n" // #6662 " int x = a & 1;\n" @@ -395,7 +395,7 @@ class TestCondition : public TestFixture { " g(x);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'x' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\n", errout_str()); check("void g(int & x);\n" "void f() {\n" @@ -413,13 +413,13 @@ class TestCondition : public TestFixture { " int b = a & 0xf0;\n" " b &= 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\n", errout_str()); check("void f(int a) {\n" " int b = a & 0xf0;\n" " int c = b & 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\n", errout_str()); check("void f(int a) {\n" " int b = a;" @@ -435,56 +435,56 @@ class TestCondition : public TestFixture { // CheckCondition::comparison test cases // '==' check("void f(int a) {\n assert( (a & 0x07) == 8U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X & 0x7) == 0x8' is always false.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\n",errout_str()); check("void f(int a) {\n assert( (a & b & 4 & c ) == 3 );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X & 0x4) == 0x3' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\n", errout_str()); check("void f(int a) {\n assert( (a | 0x07) == 8U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X | 0x7) == 0x8' is always false.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\n",errout_str()); check("void f(int a) {\n assert( (a & 0x07) == 7U );\n}"); ASSERT_EQUALS("", errout_str()); check("void f(int a) {\n assert( (a | 0x01) == -15 );\n}"); ASSERT_EQUALS("", errout_str()); // '!=' check("void f(int a) {\n assert( (a & 0x07) != 8U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X & 0x7) != 0x8' is always true.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\n",errout_str()); check("void f(int a) {\n assert( (a | 0x07) != 8U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X | 0x7) != 0x8' is always true.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\n",errout_str()); check("void f(int a) {\n assert( (a & 0x07) != 7U );\n}"); ASSERT_EQUALS("", errout_str()); check("void f(int a) {\n assert( (a | 0x07) != 7U );\n}"); ASSERT_EQUALS("", errout_str()); // '>=' check("void f(int a) {\n assert( (a & 0x07) >= 8U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X & 0x7) >= 0x8' is always false.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\n",errout_str()); check("void f(unsigned int a) {\n assert( (a | 0x7) >= 7U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X | 0x7) >= 0x7' is always true.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\n",errout_str()); check("void f(int a) {\n assert( (a & 0x07) >= 7U );\n}"); ASSERT_EQUALS("",errout_str()); check("void f(int a) {\n assert( (a | 0x07) >= 8U );\n}"); ASSERT_EQUALS("",errout_str()); //correct for negative 'a' // '>' check("void f(int a) {\n assert( (a & 0x07) > 7U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X & 0x7) > 0x7' is always false.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\n",errout_str()); check("void f(unsigned int a) {\n assert( (a | 0x7) > 6U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X | 0x7) > 0x6' is always true.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\n",errout_str()); check("void f(int a) {\n assert( (a & 0x07) > 6U );\n}"); ASSERT_EQUALS("",errout_str()); check("void f(int a) {\n assert( (a | 0x07) > 7U );\n}"); ASSERT_EQUALS("",errout_str()); //correct for negative 'a' // '<=' check("void f(int a) {\n assert( (a & 0x07) <= 7U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X & 0x7) <= 0x7' is always true.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\n",errout_str()); check("void f(unsigned int a) {\n assert( (a | 0x08) <= 7U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X | 0x8) <= 0x7' is always false.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\n",errout_str()); check("void f(int a) {\n assert( (a & 0x07) <= 6U );\n}"); ASSERT_EQUALS("",errout_str()); check("void f(int a) {\n assert( (a | 0x08) <= 7U );\n}"); ASSERT_EQUALS("",errout_str()); //correct for negative 'a' // '<' check("void f(int a) {\n assert( (a & 0x07) < 8U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X & 0x7) < 0x8' is always true.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\n",errout_str()); check("void f(unsigned int a) {\n assert( (a | 0x07) < 7U );\n}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Expression '(X | 0x7) < 0x7' is always false.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\n",errout_str()); check("void f(int a) {\n assert( (a & 0x07) < 3U );\n}"); ASSERT_EQUALS("",errout_str()); check("void f(int a) {\n assert( (a | 0x07) < 7U );\n}"); @@ -494,9 +494,9 @@ class TestCondition : public TestFixture { " if ((i & 0x100) == 0x200) {}\n" " if (0x200 == (i & 0x100)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The if condition is the same as the previous if condition\n" - "[test.cpp:2]: (style) Expression '(X & 0x100) == 0x200' is always false.\n" - "[test.cpp:3]: (style) Expression '(X & 0x100) == 0x200' is always false.\n", + ASSERT_EQUALS("[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n" + "[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\n" + "[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\n", errout_str()); checkP("#define MACRO1 (0x0010)\n" // #13222 @@ -512,8 +512,8 @@ class TestCondition : public TestFixture { " if ((i & 0xff00) == X) {}\n" " if (X == (j & 0xff00)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0xff00) == 0x10' is always false.\n" - "[test.cpp:4]: (style) Expression '(X & 0xff00) == 0x10' is always false.\n", + ASSERT_EQUALS("[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\n" + "[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\n", errout_str()); } @@ -524,14 +524,14 @@ class TestCondition : public TestFixture { " if (x & 7);\n" " else { if (x == 1); }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\n", errout_str()); check("void foo(int x)\n" "{\n" " if (x & 7);\n" " else { if (x & 1); }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\n", errout_str()); check("extern int bar() __attribute__((pure));\n" "void foo(int x)\n" @@ -539,7 +539,7 @@ class TestCondition : public TestFixture { " if ( bar() >1 && b) {}\n" " else if (bar() >1 && b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Expression is always false because 'else if' condition matches previous condition at line 4.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\n", errout_str()); checkPureFunction("extern int bar();\n" "void foo(int x)\n" @@ -547,14 +547,14 @@ class TestCondition : public TestFixture { " if ( bar() >1 && b) {}\n" " else if (bar() >1 && b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Expression is always false because 'else if' condition matches previous condition at line 4.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\n", errout_str()); // 7284 check("void foo() {\n" " if (a) {}\n" " else if (!!a) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); // #11059 check("int f();\n" @@ -590,27 +590,27 @@ class TestCondition : public TestFixture { " if (a) { b = 1; }\n" " else { if (a) { b = 2; } }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a) { b = 1; }\n" " else { if (a) { b = 2; } }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a == 1) { b = 1; }\n" " else { if (a == 2) { b = 2; }\n" " else { if (a == 1) { b = 3; } } }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a == 1) { b = 1; }\n" " else { if (a == 2) { b = 2; }\n" " else { if (a == 2) { b = 3; } } }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a++) { b = 1; }\n" @@ -636,7 +636,7 @@ class TestCondition : public TestFixture { " if (c.dostuff() == 3) {}\n" " else { if (c.dostuff() == 3) {} }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); } check("void f(int a, int &b) {\n" @@ -701,7 +701,7 @@ class TestCondition : public TestFixture { " if (x & 15) {}\n" " else if (x == 40) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(int x) {\n" " if (x == sizeof(double)) {}\n" @@ -719,37 +719,37 @@ class TestCondition : public TestFixture { " if (x & 0xF8) {}\n" " else if (x & 0x08) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && !!a){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && a){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( b && !!a){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( b && !(!a)){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && !(!a)){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" @@ -809,13 +809,13 @@ class TestCondition : public TestFixture { " bool b = x | 0x02;\n" " return b;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("bool f(int x) {\n" " bool b = 0x02 | x;\n" " return b;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("int f(int x) {\n" " int b = x | 0x02;\n" @@ -833,7 +833,7 @@ class TestCondition : public TestFixture { " if(x | 0x02)\n" " return b;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("bool f(int x) {\n" " int y = 0x1;\n" @@ -846,12 +846,12 @@ class TestCondition : public TestFixture { check("bool f(int x) {\n" " foo(a && (x | 0x02));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("int f(int x) {\n" " return (x | 0x02) ? 0 : 5;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("int f(int x) {\n" " return x ? (x | 0x02) : 5;\n" @@ -861,7 +861,7 @@ class TestCondition : public TestFixture { check("bool f(int x) {\n" " return x | 0x02;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("bool f(int x) {\n" " if (x) {\n" @@ -869,19 +869,19 @@ class TestCondition : public TestFixture { " }\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("const bool f(int x) {\n" " return x | 0x02;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("struct F {\n" " static const bool f(int x) {\n" " return x | 0x02;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("struct F {\n" " typedef bool b_t;\n" @@ -889,7 +889,7 @@ class TestCondition : public TestFixture { "F::b_t f(int x) {\n" " return x | 0x02;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("int f(int x) {\n" " return x | 0x02;\n" @@ -916,7 +916,7 @@ class TestCondition : public TestFixture { " int j = 0;\n" " if (i | j) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Operator '|' with one operand equal to zero is redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\n", errout_str()); check("#define EIGHTTOIS(x) (((x) << 8) | (x))\n" "int f() {\n" @@ -957,28 +957,28 @@ class TestCondition : public TestFixture { " if ((x != 1) || (x != 3))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (1 != x || 3 != x)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x<0 && !x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 0 && !x.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x==0 && x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x == 0 && x.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" // ast.. " if (y == 1 && x == 1 && x == 7) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\n", errout_str()); check("void f(int x, int y) {\n" " if (x != 1 || y != 1)\n" @@ -997,7 +997,7 @@ class TestCondition : public TestFixture { " a++;\n" "}" ); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition 'x!=3' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if ((x != 1) && (x != 3))\n" @@ -1034,7 +1034,7 @@ class TestCondition : public TestFixture { " if ((x != 5) || (x != 6))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\n", errout_str()); check("void f(unsigned int a, unsigned int b, unsigned int c) {\n" " if((a != b) || (c != b) || (c != a))\n" @@ -1043,7 +1043,7 @@ class TestCondition : public TestFixture { " }\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition 'c!=a' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\n", errout_str()); } void incorrectLogicOperator2() { @@ -1057,13 +1057,13 @@ class TestCondition : public TestFixture { " if ((x == 1) && (x == 0x00000001))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition 'x==0x00000001' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if (x == 1 && x == 3)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x == 1.0 && x == 3.0)\n" @@ -1086,19 +1086,19 @@ class TestCondition : public TestFixture { " if (x < 1 && x > 1)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x < 1.0 && x > 1.0)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x < 1 && x > 1.0)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x >= 1.0 && x <= 1.001)\n" @@ -1110,19 +1110,19 @@ class TestCondition : public TestFixture { " if (x < 1 && x > 3)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(float x) {\n" " if (x < 1.0 && x > 3.0)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (1 > x && 3 < x)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x < 3 && x > 1)\n" @@ -1134,25 +1134,25 @@ class TestCondition : public TestFixture { " if (x > 3 || x < 10)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x >= 3 || x <= 10)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x >= 3 || x < 10)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 || x <= 10)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 || x < 3)\n" @@ -1165,64 +1165,64 @@ class TestCondition : public TestFixture { " a++;\n" "}" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x >= 3 || x < 3)\n" " a++;\n" "}" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 || x <= 3)\n" " a++;\n" "}" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if((x==3) && (x!=4))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\n", errout_str()); check("void f(const std::string &s) {\n" // #8860 " const std::size_t p = s.find(\"42\");\n" " const std::size_t * const ptr = &p;\n" " if(p != std::string::npos && p == 0 && *ptr != 1){;}\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:4]: (style) Condition '*ptr!=1' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if ((x!=4) && (x==3))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if ((x==3) || (x!=4))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if ((x!=4) || (x==3))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if ((x==3) && (x!=3))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if ((x==6) || (x!=6))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 10 || x < 3)\n" @@ -1234,13 +1234,13 @@ class TestCondition : public TestFixture { " if (x > 5 && x == 1)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 5 && x == 6)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\n", errout_str()); // #3419 check("void f() {\n" @@ -1278,10 +1278,10 @@ class TestCondition : public TestFixture { " d = x >= 5 && x == 1;\n" " e = x <= 1 && x == 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1.\n" - "[test.cpp:3]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3.\n" - "[test.cpp:4]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1.\n" - "[test.cpp:5]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\n" + "[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\n" + "[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\n" + "[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\n", errout_str()); } void incorrectLogicOperator4() { @@ -1304,7 +1304,7 @@ class TestCondition : public TestFixture { check("void f(int x) {\n" " if (x+3 > 2 || x+3 < 10) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\n", errout_str()); } void incorrectLogicOperator6() { // char literals @@ -1316,7 +1316,7 @@ class TestCondition : public TestFixture { check("void f(char x) {\n" " if (x == '1' && x == '2') {}\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\n", errout_str()); check("int f(char c) {\n" " return (c >= 'a' && c <= 'z');\n" @@ -1326,24 +1326,24 @@ class TestCondition : public TestFixture { check("int f(char c) {\n" " return (c <= 'a' && c >= 'z');\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\n", errout_str()); check("int f(char c) {\n" " return (c <= 'a' && c >= 'z');\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Return value 'c>='z'' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\n", errout_str()); } void incorrectLogicOperator7() { // opposite expressions check("void f(int i) {\n" " if (i || !i) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: i || !(i).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\n", errout_str()); check("void f(int a, int b) {\n" " if (a>b || a<=b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: a > b || a <= b.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\n", errout_str()); check("void f(int a, int b) {\n" " if (a>b || a n && i == n ) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Logical conjunction always evaluates to false: i > n && i == n.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\n", errout_str()); check("void foo(int i, const int n) { if ( i == n && i > n ) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Logical conjunction always evaluates to false: i == n && i > n.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\n", errout_str()); check("void foo(int i, const int n) { if ( i == n && i < n ) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Logical conjunction always evaluates to false: i == n && i < n.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\n", errout_str()); } void incorrectLogicOperator12() { // #8696 @@ -1419,7 +1419,7 @@ class TestCondition : public TestFixture { " return;\n" "}"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:6] -> [test.cpp:8]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", + "[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\n", errout_str()); check("struct A {\n" @@ -1451,7 +1451,7 @@ class TestCondition : public TestFixture { " return;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3] -> [test.cpp:5]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", + "[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\n", errout_str()); check("struct A {\n" @@ -1464,8 +1464,8 @@ class TestCondition : public TestFixture { " if (a > x && a < y)\n" " return;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (style) Condition 'a>x' is always false\n" - "[test.cpp:8]: (style) Condition 'ax' is always false [knownConditionTrueFalse]\n" + "[test.cpp:8:18]: (style) Condition 'a x && a < y)\n" " return;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (style) Condition 'a>x' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo(A a) {\n" " A x = a;\n" @@ -1487,7 +1487,7 @@ class TestCondition : public TestFixture { " if (a > x && a < y)\n" " return;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'a>x' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo(A a) {\n" " const A x = a;\n" @@ -1496,8 +1496,8 @@ class TestCondition : public TestFixture { " if (a > x && a < y)\n" " return;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'a>x' is always false\n" - "[test.cpp:5]: (style) Condition 'ax' is always false [knownConditionTrueFalse]\n" + "[test.cpp:5:18]: (style) Condition 'a [test.cpp:3]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17] -> [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\n", errout_str()); check("void f2(const int *v) {\n" " const int *x=v;\n" " if ((*v == 1) && (*x == 2)) {;}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\n", errout_str()); } void incorrectLogicOperator14() { @@ -1720,7 +1720,7 @@ class TestCondition : public TestFixture { " ;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:200] -> [test.cpp:200]: (style) Condition 'g' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\n", errout_str()); } void incorrectLogicOperator15() { @@ -1776,13 +1776,13 @@ class TestCondition : public TestFixture { " const char c[1] = { \'x\' }; \n" " if(c[0] == \'x\'){;}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'c[0]=='x'' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if (x > 5 && x != 1)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if (x > 5 && x != 6)\n" @@ -1794,7 +1794,7 @@ class TestCondition : public TestFixture { " if ((x > 5) && (x != 1))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if ((x > 5) && (x != 6))\n" @@ -1808,10 +1808,10 @@ class TestCondition : public TestFixture { " d = x >= 3 || x == 4;\n" " e = x <= 5 || x == 4;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient.\n" - "[test.cpp:3]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient.\n" - "[test.cpp:4]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient.\n" - "[test.cpp:5]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient.\n", + ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\n" + "[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\n" + "[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\n" + "[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x, bool& b) {\n" @@ -1820,10 +1820,10 @@ class TestCondition : public TestFixture { " d = x >= 5 || x != 1;\n" " e = x <= 1 || x != 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient.\n" - "[test.cpp:3]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient.\n" - "[test.cpp:4]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient.\n" - "[test.cpp:5]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient.\n", + ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\n" + "[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\n" + "[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\n" + "[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x, bool& b) {\n" @@ -1832,10 +1832,10 @@ class TestCondition : public TestFixture { " d = x < 6 && x < 5;\n" " e = x < 5 || x < 6;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient.\n" - "[test.cpp:3]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient.\n" - "[test.cpp:4]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient.\n" - "[test.cpp:5]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient.\n", + ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\n" + "[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\n" + "[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\n" + "[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\n", errout_str()); check("void f(double x, bool& b) {\n" @@ -1844,16 +1844,16 @@ class TestCondition : public TestFixture { " d = x < 6.5 && x < 5.5;\n" " e = x < 5.5 || x < 6.5;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient.\n" - "[test.cpp:3]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient.\n" - "[test.cpp:4]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient.\n" - "[test.cpp:5]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient.\n", + ASSERT_EQUALS("[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\n" + "[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\n" + "[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\n" + "[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\n", errout_str()); check("void f(const char *p) {\n" // #10320 " if (!p || !*p || *p != 'x') {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient.\n", + ASSERT_EQUALS("[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\n", errout_str()); } @@ -1862,49 +1862,49 @@ class TestCondition : public TestFixture { " if (x < 1 && x > 3)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (1 > x && x > 3)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x < 1 && 3 < x)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (1 > x && 3 < x)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 && x < 1)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (3 < x && x < 1)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 && 1 > x)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (3 < x && 1 > x)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\n", errout_str()); } void modulo() { @@ -1925,12 +1925,12 @@ class TestCondition : public TestFixture { " return a % 5 > 5;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n" - "[test.cpp:3]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n" - "[test.cpp:4]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n" - "[test.cpp:5]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n" - "[test.cpp:6]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n" - "[test.cpp:7]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n", + "[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" + "[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" + "[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" + "[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" + "[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" + "[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n", errout_str()); check("void f(bool& b1, bool& b2) {\n" @@ -1939,9 +1939,9 @@ class TestCondition : public TestFixture { " b2 = x.a % 5 == 5;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n" - "[test.cpp:3]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n" - "[test.cpp:4]: (warning) Comparison of modulo result is predetermined, because it is always less than 5.\n", + "[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" + "[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" + "[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n", errout_str()); check("void f() {\n" @@ -1957,21 +1957,21 @@ class TestCondition : public TestFixture { " if(a!=b)\n" " cout << a;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("bool foo(int a, int b) {\n" " if(a==b)\n" " return a!=b;\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'return' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(int a, int b) {\n" " if(a==b)\n" " if(b!=a)\n" " cout << a;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(int a) {\n" " if(a >= 50) {\n" @@ -1981,7 +1981,7 @@ class TestCondition : public TestFixture { " cout << 100;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); // #4186 check("void foo(int a) {\n" @@ -2055,7 +2055,7 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(const int &i);\n" "void bar(int i) {\n" @@ -2065,7 +2065,7 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(int i);\n" "void bar() {\n" @@ -2076,7 +2076,7 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("class C { void f(int &i) const; };\n" // #7028 - variable is changed by const method "void foo(C c, int i) {\n" @@ -2099,7 +2099,7 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); // #5874 - array @@ -2127,7 +2127,7 @@ class TestCondition : public TestFixture { " if(!b) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(unsigned u) {\n" " if (u != 0) {\n" @@ -2145,7 +2145,7 @@ class TestCondition : public TestFixture { " if (i==5) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); // #8938 check("void Delete(SS_CELLCOORD upperleft) {\n" @@ -2176,7 +2176,7 @@ class TestCondition : public TestFixture { " b = g();\n" " return b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Return value '!b' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\n", errout_str()); } void oppositeInnerConditionPointers() { @@ -2223,7 +2223,7 @@ class TestCondition : public TestFixture { " if (!fred.isValid()) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("class Fred { public: bool isValid() const; void dostuff() const; };\n" "void f() {\n" @@ -2233,7 +2233,7 @@ class TestCondition : public TestFixture { " if (!fred.isValid()) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f() {\n" " Fred fred;\n" @@ -2331,7 +2331,7 @@ class TestCondition : public TestFixture { " if (hasFailed) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Condition '!hasFailed' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\n", errout_str()); } void oppositeInnerCondition2() { @@ -2342,7 +2342,7 @@ class TestCondition : public TestFixture { " if (x==5) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" "\n" @@ -2350,14 +2350,14 @@ class TestCondition : public TestFixture { " if (x!=5) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x!=5' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x<4) {\n" " if (x>5) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" "\n" @@ -2365,7 +2365,7 @@ class TestCondition : public TestFixture { " if (x>=5) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" "\n" @@ -2373,14 +2373,14 @@ class TestCondition : public TestFixture { " if (x<5) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x<5' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x<4) {\n" " if (x<=5) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x<=5' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" @@ -2402,14 +2402,14 @@ class TestCondition : public TestFixture { " if (x!=6) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x!=6' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x<5) {\n" " if (x>4) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x>4' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x<5) {\n" @@ -2430,7 +2430,7 @@ class TestCondition : public TestFixture { " if (x<=4) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x<=4' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\n", errout_str()); // first comparison: > check("void f(int x) {\n" @@ -2453,14 +2453,14 @@ class TestCondition : public TestFixture { " if (x>=5) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x>=5' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x>4) {\n" " if (x<5) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x<5' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x>4) {\n" @@ -2475,7 +2475,7 @@ class TestCondition : public TestFixture { " if (x==4) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" "\n" @@ -2483,21 +2483,21 @@ class TestCondition : public TestFixture { " if (x>4) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x>4' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x>5) {\n" " if (x>=4) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'x>=4' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x>5) {\n" " if (x<4) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" "\n" @@ -2505,7 +2505,7 @@ class TestCondition : public TestFixture { " if (x<=4) {}\n" // <- Warning " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" @@ -2513,42 +2513,42 @@ class TestCondition : public TestFixture { " if (10 < x) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); } void oppositeInnerCondition3() { check("void f3(char c) { if(c=='x') if(c=='y') {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f4(char *p) { if(*p=='x') if(*p=='y') {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f6(char * const p) { if(*p=='x') if(*p=='y') {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f7(const char * p) { if(*p=='x') if(*p=='y') {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f8(int i) { if(i==4) if(i==2) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f9(int *p) { if (*p==4) if(*p==2) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f10(int * const p) { if (*p==4) if(*p==2) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f11(const int *p) { if (*p==4) if(*p==2) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f12(const int * const p) { if (*p==4) if(*p==2) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("struct foo {\n" " int a;\n" @@ -2568,7 +2568,7 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("", errout_str()); check("void f(int x) { if (x == 1) if (x != 1) {} }"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); } void oppositeInnerConditionAnd() { @@ -2577,13 +2577,13 @@ class TestCondition : public TestFixture { " if (x < 10) {}\n" " }" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(bool x, const int a, const int b) {\n" " if(x && a < b)\n" " if( x && a > b){}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); } void oppositeInnerConditionOr() @@ -2593,7 +2593,7 @@ class TestCondition : public TestFixture { " if (x == 3) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" @@ -2622,31 +2622,31 @@ class TestCondition : public TestFixture { " if (x == 3) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", + ASSERT_EQUALS("[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); } void oppositeInnerConditionEmpty() { check("void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} "); // <- CheckOther reports: checking if unsigned expression is less than zero - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Condition 's.empty()' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}"); ASSERT_EQUALS("", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it. check("void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}"); ASSERT_EQUALS("", errout_str()); @@ -2750,10 +2750,10 @@ class TestCondition : public TestFixture { void identicalInnerCondition() { check("void f1(int a, int b) { if(a==b) if(a==b) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Identical inner 'if' condition is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); check("void f2(int a, int b) { if(a!=b) if(a!=b) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Identical inner 'if' condition is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); // #6645 false negative: condition is always false check("void f(bool a, bool b) {\n" @@ -2762,13 +2762,13 @@ class TestCondition : public TestFixture { " else {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical inner 'if' condition is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); check("bool f(int a, int b) {\n" " if(a == b) { return a == b; }\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (warning) Identical inner 'return' condition is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\n", errout_str()); check("bool f(bool a) {\n" " if(a) { return a; }\n" @@ -2825,39 +2825,39 @@ class TestCondition : public TestFixture { " if (x > 100) { return; }\n" " if (x > 100) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'x>100', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("bool f(int x) {\n" " if (x > 100) { return false; }\n" " return x > 100;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition and return expression 'x>100', return value is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" " if (x > 100) { return; }\n" " if (x > 100 || y > 100) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'x>100', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" " if (x > 100) { return; }\n" " if (x > 100 && y > 100) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'x>100', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" " if (x > 100) { return; }\n" " if (abc) {}\n" " if (x > 100) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" " if (x > 100) { return; }\n" " while (abc) { y = x; }\n" " if (x > 100) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); ASSERT_THROW_INTERNAL(check("void f(int x) {\n" // #8217 - crash for incomplete code " if (x > 100) { return; }\n" @@ -2871,7 +2871,7 @@ class TestCondition : public TestFixture { " if (!num1tok) { *num1 = *num2; }\n" " if (!i) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition '!i', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void C::f(Tree &coreTree) {\n" // daca " if(!coreTree.build())\n" @@ -2888,7 +2888,7 @@ class TestCondition : public TestFixture { " coreTree.dostuff();\n" " if(!coreTree.build()) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Identical condition '!coreTree.build()', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" // daca: labplot " switch(type) {\n" @@ -2937,7 +2937,7 @@ class TestCondition : public TestFixture { " }\n" " int FileIndex;\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'this->FileIndex<0' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\n", errout_str()); // #8858 - #if check("short Do() {\n" @@ -3011,7 +3011,7 @@ class TestCondition : public TestFixture { check("void f() {\n" " if (x = b() < 0) {}\n" // don't simplify and verify this code "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("void f(int i) {\n" " for (i = 0; i < 10; i++) {}\n" @@ -3032,25 +3032,25 @@ class TestCondition : public TestFixture { " int y = rand(), z = rand();\n" " if (y || (!y && z));\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\n", errout_str()); check("void f() {\n" " int y = rand(), z = rand();\n" " if (y || !y && z);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (!a || a && b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\n", errout_str()); check("void f(const Token *tok) {\n" " if (!tok->next()->function() ||\n" " (tok->next()->function() && tok->next()->function()->isConstructor()));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (!tok->next()->function() ||\n" @@ -3068,7 +3068,7 @@ class TestCondition : public TestFixture { " if (!tok->next(1)->function(1) ||\n" " (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (!tok->next()->function(1) ||\n" @@ -3080,7 +3080,7 @@ class TestCondition : public TestFixture { " int y = rand(), z = rand();\n" " if (y==0 || y!=0 && z);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (x>0 || (x<0 && y)) {}\n" @@ -3091,22 +3091,22 @@ class TestCondition : public TestFixture { check("void f() {\n" " if (!dead || (dead && (*it).ticks > 0)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (!x || (x && (2>(y-1)))) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if (a || (a && b)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if (a && (a || b)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\n", errout_str()); } // clarify conditions with bitwise operator and comparison @@ -3114,15 +3114,15 @@ class TestCondition : public TestFixture { check("void f() {\n" " if (x & 3 == 2) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses.\n" - "[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n" - "[test.cpp:2]: (style) Condition 'x&3==2' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\n" + "[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n" + "[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " if (a & fred1.x == fred2.y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses.\n" - "[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n" + ASSERT_EQUALS("[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\n" + "[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n" , errout_str()); } @@ -3131,7 +3131,7 @@ class TestCondition : public TestFixture { check("void f(int w) {\n" " if(!w & 0x8000) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("void f(int w) {\n" " if((!w) & 0x8000) {}\n" @@ -3141,12 +3141,12 @@ class TestCondition : public TestFixture { check("void f() {\n" " if (x == foo() & 2) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("void f() {\n" " if (2 & x == foo()) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("void f() {\n" " if (2 & (x == foo())) {}\n" @@ -3160,7 +3160,7 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("", errout_str()); check("void f() { a(x there are never templates - ASSERT_EQUALS("[test.c:1]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout_str()); + ASSERT_EQUALS("[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("class A;"); ASSERT_EQUALS("", errout_str()); @@ -3267,7 +3267,7 @@ class TestCondition : public TestFixture { " int x2 = s->x;\n" " if (x1 == 10 && x2 == 10) {}\n" // << "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:4]: (style) Condition 'x2==10' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f ()\n"// #8220 "{\n" @@ -3283,28 +3283,28 @@ class TestCondition : public TestFixture { " }\n" " ret = b;\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:8]: (style) Condition '8 [test.cpp:8:40]: (style) Condition '8 [test.cpp:2]: (style) Return value 'x==0' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8] -> [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" // #6898 (Token::expressionString) " int x = 0;\n" " A(x++ == 1);\n" " A(x++ == 2);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'x++==1' is always false\n" - "[test.cpp:4]: (style) Condition 'x++==2' is always false\n", + ASSERT_EQUALS("[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\n" + "[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\n", errout_str()); check("bool foo(int bar) {\n" @@ -3318,46 +3318,46 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("", errout_str()); check("void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Condition 's.size()==0' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int buf[42];\n" " if( buf != 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'buf!=0' is always true\n", errout_str()); // #8924 + ASSERT_EQUALS("[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\n", errout_str()); // #8924 check("void f() {\n" " int buf[42];\n" " if( !buf ) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition '!buf' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int buf[42];\n" " bool b = buf;\n" " if( b ) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'b' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int buf[42];\n" " bool b = buf;\n" " if( !b ) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition '!b' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int buf[42];\n" " int * p = nullptr;\n" " if( buf == p ) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'buf==p' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(bool x) {\n" " int buf[42];\n" " if( buf || x ) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'buf' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int * p) {\n" " int buf[42];\n" @@ -3462,7 +3462,7 @@ class TestCondition : public TestFixture { " if(i > 4)\n" " for( int x = 0; i < 3; ++x){}\n" // << "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'i<3' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\n", errout_str()); // Skip literals check("void f() { if(true) {} }"); @@ -3490,7 +3490,7 @@ class TestCondition : public TestFixture { " if (b)\n" " {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition '!b' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\n", errout_str()); check("bool f() { return nullptr; }"); ASSERT_EQUALS("", errout_str()); @@ -3519,7 +3519,7 @@ class TestCondition : public TestFixture { " const int b = 52;\n" " return a+b;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Return value 'a+b' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\n", errout_str()); check("int f() {\n" " int a = 50;\n" @@ -3616,28 +3616,28 @@ class TestCondition : public TestFixture { " if (handle) return 1;\n" " else return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Condition 'handle' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\n", errout_str()); check("int f(void *handle) {\n" " if (handle == 0) return 0;\n" " if (handle) return 1;\n" " else return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'handle' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\n", errout_str()); check("int f(void *handle) {\n" " if (handle != 0) return 0;\n" " if (handle) return 1;\n" " else return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'handle!=0', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("int f(void *handle) {\n" " if (handle != nullptr) return 0;\n" " if (handle) return 1;\n" " else return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'handle!=nullptr', second condition is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(void* x, void* y) {\n" " if (x == nullptr && y == nullptr)\n" @@ -3665,7 +3665,7 @@ class TestCondition : public TestFixture { " }\n" " if (a) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'a' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int * x, bool b) {\n" " if (!x && b) {}\n" @@ -3677,7 +3677,7 @@ class TestCondition : public TestFixture { " const std::string x=\"xyz\";\n" " if(!x.empty()){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition '!x.empty()' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\n", errout_str()); check("std::string g();\n" "void f() {\n" @@ -3693,7 +3693,7 @@ class TestCondition : public TestFixture { " if(array){}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'array' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int *array, int size ) {\n" " for(int i = 0; i < size; ++i) {\n" @@ -3702,7 +3702,7 @@ class TestCondition : public TestFixture { " else if(array){}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'array' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\n", errout_str()); // #9277 check("int f() {\n" @@ -3800,7 +3800,7 @@ class TestCondition : public TestFixture { " if(b) return b?0:-1;\n" " return 42;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (style) Condition 'b' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\n", errout_str()); // #9362 check("uint8_t g();\n" @@ -3902,7 +3902,7 @@ class TestCondition : public TestFixture { " if (v == nullptr && e) {}\n" " return d;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:11]: (style) Condition 'e' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\n", errout_str()); // #10037 check("struct a {\n" @@ -3934,7 +3934,7 @@ class TestCondition : public TestFixture { " }\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:11]: (style) Condition '!y' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\n", errout_str()); // #10134 check("bool foo(bool b);\n" @@ -3983,7 +3983,7 @@ class TestCondition : public TestFixture { " for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\n" " g(name);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'name.empty()' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\n", errout_str()); // #10278 check("void foo(unsigned int x) {\n" @@ -4030,7 +4030,7 @@ class TestCondition : public TestFixture { " else\n" " if(x == 1) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'x==1' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\n", errout_str()); // do not report both unsignedLessThanZero and knownConditionTrueFalse check("void foo(unsigned int max) {\n" @@ -4069,18 +4069,18 @@ class TestCondition : public TestFixture { check("void f(int i) {\n" " if(abs(i) == -1) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'abs(i)==-1' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\n", errout_str()); // #7844 check("void f(int i) {\n" " if(i > 0 && abs(i) == i) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'abs(i)==i' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " if(i < 0 && abs(i) == i) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition 'abs(i)==i' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " if(i > -3 && abs(i) == i) {}\n" @@ -4091,7 +4091,7 @@ class TestCondition : public TestFixture { check("bool f(bool a, bool b) {\n" " return a || ! b || ! a;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Return value '!a' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\n", errout_str()); // #10148 check("void f(int i) {\n" @@ -4174,21 +4174,21 @@ class TestCondition : public TestFixture { " if (init)\n" " init = false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\n", errout_str()); check("void f() {\n" " static bool init(true);\n" " if (init)\n" " init = false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\n", errout_str()); check("void f() {\n" " static bool init{ true };\n" " if (init)\n" " init = false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\n", errout_str()); // #10248 check("void f() {\n" @@ -4318,8 +4318,8 @@ class TestCondition : public TestFixture { " if (w) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'v<2' is always true\n" - "[test.cpp:5]: (style) Condition 'w' is always true\n", + ASSERT_EQUALS("[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\n" + "[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(double d) {\n" // #10792 @@ -4353,10 +4353,10 @@ class TestCondition : public TestFixture { " if(wcslen(L\"abc\") == 3) {;}\n" " if(wcslen(L\"abc\") == 1) {;}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'strlen(\"abc\")==3' is always true\n" - "[test.cpp:3]: (style) Condition 'strlen(\"abc\")==1' is always false\n" - "[test.cpp:4]: (style) Condition 'wcslen(L\"abc\")==3' is always true\n" - "[test.cpp:5]: (style) Condition 'wcslen(L\"abc\")==1' is always false\n", + ASSERT_EQUALS("[test.cpp:2:22]: (style) Condition 'strlen(\"abc\")==3' is always true [knownConditionTrueFalse]\n" + "[test.cpp:3:22]: (style) Condition 'strlen(\"abc\")==1' is always false [knownConditionTrueFalse]\n" + "[test.cpp:4:23]: (style) Condition 'wcslen(L\"abc\")==3' is always true [knownConditionTrueFalse]\n" + "[test.cpp:5:23]: (style) Condition 'wcslen(L\"abc\")==1' is always false [knownConditionTrueFalse]\n", errout_str()); check("int foo(bool a, bool b) {\n" @@ -4364,7 +4364,7 @@ class TestCondition : public TestFixture { " return 1;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition '!a==!b' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\n", errout_str()); // #10454 check("struct S {\n" @@ -4387,7 +4387,7 @@ class TestCondition : public TestFixture { "void S::f() {\n" " if ((p == NULL) || ((p) && (g() >= *p))) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Condition 'p' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\n", errout_str()); // #10749 check("struct Interface {\n" @@ -4415,22 +4415,22 @@ class TestCondition : public TestFixture { " else if (s.i < 0)\n" " s.s = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 's.i<0' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\n", errout_str()); // #6857 check("int bar(int i) { return i; }\n" "void foo() {\n" " if (bar(1) == 0 && bar(1) > 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'bar(1)==0' is always false\n" - "[test.cpp:3]: (style) Condition 'bar(1)>0' is always true\n", + ASSERT_EQUALS("[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\n" + "[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\n", errout_str()); check("struct S { int bar(int i) const; };\n" "void foo(const S& s) {\n" " if (s.bar(1) == 0 && s.bar(1) > 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0.\n", + ASSERT_EQUALS("[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\n", errout_str()); check("struct B {\n" // #10618 @@ -4454,7 +4454,7 @@ class TestCondition : public TestFixture { " B::Static();\n" " if (i == 1) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:20]: (style) Condition 'i==1' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\n", errout_str()); check("typedef struct { bool x; } s_t;\n" // #8446 "unsigned f(bool a, bool b) {\n" @@ -4484,8 +4484,8 @@ class TestCondition : public TestFixture { " if(f < 10) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'i>9.9' is always true\n" - "[test.cpp:5]: (style) Condition 'f<10' is always true\n", + "[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\n" + "[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\n", errout_str()); check("constexpr int f() {\n" // #11238 " return 1;\n" @@ -4499,8 +4499,8 @@ class TestCondition : public TestFixture { "void f() {\n" " if (g() == 1 && g() == -1) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'g()==1' is always false\n" - "[test.cpp:3]: (style) Condition 'g()==-1' is always true\n", + ASSERT_EQUALS("[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\n" + "[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\n", errout_str()); // #9817 @@ -4519,11 +4519,11 @@ class TestCondition : public TestFixture { " if ((bool)0) {}\n" " return s.empty();" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition '!s.empty()' is always false\n" - "[test.cpp:4]: (style) Condition 's.empty()' is always true\n" - "[test.cpp:5]: (style) Condition 's.empty()' is always true\n" - "[test.cpp:6]: (style) Condition '(bool)0' is always false\n" - "[test.cpp:7]: (style) Return value 's.empty()' is always true\n", + ASSERT_EQUALS("[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\n" + "[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\n" + "[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\n" + "[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\n" + "[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\n", errout_str()); check("int f(bool b) {\n" @@ -4534,16 +4534,16 @@ class TestCondition : public TestFixture { " if (b) return static_cast(1);\n" " return (int)0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Return value 'static_cast(1)' is always true\n" - "[test.cpp:7]: (style) Return value '(int)0' is always false\n", + ASSERT_EQUALS("[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\n" + "[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\n", errout_str()); check("int f() { return 3; }\n" "int g() { return f(); }\n" "int h() { if (f()) {} }\n" "int i() { return f() == 3; }\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f()' is always true\n" - "[test.cpp:4]: (style) Return value 'f()==3' is always true\n", + ASSERT_EQUALS("[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\n" + "[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\n", errout_str()); check("int f() {\n" @@ -4571,7 +4571,7 @@ class TestCondition : public TestFixture { " return;\n" " g(s ? s->get() : 0);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (style) Condition 's' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(const char* o) {\n" // #11558 " if (!o || !o[0])\n" @@ -4582,9 +4582,9 @@ class TestCondition : public TestFixture { " }\n" "}\n"); if (std::numeric_limits::is_signed) { - ASSERT_EQUALS("[test.cpp:6]: (style) Condition 'o[1]=='\\0'' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:18]: (style) Condition 'o[1]=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str()); } else { - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\0'' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str()); } check("void f(int x) {\n" // #11449 @@ -4609,7 +4609,7 @@ class TestCondition : public TestFixture { " if (a == \"x\") {}\n" " return a;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'a==\"x\"' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'a==\"x\"' is always true [knownConditionTrueFalse]\n", errout_str()); check("void g(bool);\n" "void f() {\n" @@ -4618,8 +4618,8 @@ class TestCondition : public TestFixture { " g(i == 7);\n" " g(p == nullptr);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'i==7' is always false\n" - "[test.cpp:6]: (style) Condition 'p==nullptr' is always false\n", + ASSERT_EQUALS("[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\n" + "[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\n", errout_str()); check("enum E { E0, E1 };\n" @@ -4659,26 +4659,26 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'S::s' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" // #10811 " int i = 0;\n" " if ((i = g(), 1) != 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition '(i=g(),1)!=0' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(unsigned i) {\n" " const int a[2] = {};\n" " const int* q = a + i;\n" " if (q) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'q' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" // #12786 " const int b[2] = {};\n" " if (b) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'b' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " int j = 0;\n" @@ -4770,7 +4770,7 @@ class TestCondition : public TestFixture { " const S* sp2 = s.get2();\n" " if (sp2) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:12]: (style) Condition 'sp2' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\n", errout_str()); check("struct S {\n" " void f(int i);\n" @@ -4795,7 +4795,7 @@ class TestCondition : public TestFixture { " y[0]=x;\n" " if(x > 0 || y[0] < 42){}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:4]: (style) Condition 'y[0]<42' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x, int y) {\n" " if(x < y && x < 42) {\n" @@ -4803,13 +4803,13 @@ class TestCondition : public TestFixture { " if(x == y) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'x==y' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(bool a, bool b) { if (a == b && a && !b){} }"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Condition '!b' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\n", errout_str()); check("bool f(bool a, bool b) { if(a && b && (!a)){} }"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Condition '!a' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int x, int y) {\n" " if (x < y) {\n" @@ -4817,7 +4817,7 @@ class TestCondition : public TestFixture { " if (z < 1) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'z<1' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\n", errout_str()); check("bool f(int &index, const int s, const double * const array, double & x) {\n" " if (index >= s)\n" @@ -4827,7 +4827,7 @@ class TestCondition : public TestFixture { " return (index++) >= s;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (style) Return value '(index++)>=s' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\n", errout_str()); check("struct a {\n" " a *b() const;\n" @@ -4930,7 +4930,7 @@ class TestCondition : public TestFixture { " return 1;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition 'b' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\n", errout_str()); // #11124 check("struct Basket {\n" @@ -5028,7 +5028,7 @@ class TestCondition : public TestFixture { " if (x == 1) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'x==1' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if (x > 5) {\n" @@ -5036,7 +5036,7 @@ class TestCondition : public TestFixture { " if (x != 1) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'x!=1' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\n", errout_str()); // #6890 check("void f(int i) {\n" @@ -5048,7 +5048,7 @@ class TestCondition : public TestFixture { " else {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x==-1' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " int x = i;\n" @@ -5059,7 +5059,7 @@ class TestCondition : public TestFixture { " else {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x!=-1' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " int x = i;\n" @@ -5070,7 +5070,7 @@ class TestCondition : public TestFixture { " else {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x>=-1' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " int x = i;\n" @@ -5081,7 +5081,7 @@ class TestCondition : public TestFixture { " else {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x>-1' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " int x = i;\n" @@ -5092,7 +5092,7 @@ class TestCondition : public TestFixture { " else {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x<-1' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " int x = i;\n" @@ -5103,7 +5103,7 @@ class TestCondition : public TestFixture { " else {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x<=-1' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " int x = i;\n" @@ -5114,7 +5114,7 @@ class TestCondition : public TestFixture { " else {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x>7' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" " int x = i;\n" @@ -5161,7 +5161,7 @@ class TestCondition : public TestFixture { " --pos;\n" " return pos;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) Condition 'pos>0' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\n", errout_str()); // #9721 check("void f(int x) {\n" @@ -5170,21 +5170,21 @@ class TestCondition : public TestFixture { " return;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Condition '-128>x' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\n", errout_str()); // #8778 check("void f() {\n" " for(int i = 0; i < 19; ++i)\n" " if(i<=18) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'i<=18' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\n", errout_str()); // #8209 check("void f() {\n" " for(int x = 0; x < 3; ++x)\n" " if(x == -5) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'x==-5' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\n", errout_str()); // #8407 check("int f(void) {\n" @@ -5193,14 +5193,14 @@ class TestCondition : public TestFixture { " else return 0;\n" " return -1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'i==0' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(unsigned int u1, unsigned int u2) {\n" " if (u1 <= 10 && u2 >= 20) {\n" " if (u1 != u2) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Condition 'u1!=u2' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\n", errout_str()); // #10544 check("void f(int N) {\n" @@ -5218,7 +5218,7 @@ class TestCondition : public TestFixture { check("bool f(const int *p, const int *q) {\n" " return p != NULL && q != NULL && p == NULL;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Return value 'p==NULL' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\n", errout_str()); check("struct S {\n" // #11789 " std::vector v;\n" @@ -5312,7 +5312,7 @@ class TestCondition : public TestFixture { " return -1;\n" " return *it;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'it!=vector.end()' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\n", errout_str()); // #11303 check("void f(int n) {\n" @@ -5322,7 +5322,7 @@ class TestCondition : public TestFixture { " buffer.back() == '\\0') {}\n" "}\n"); if (std::numeric_limits::is_signed) { - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'buffer.back()=='\\0'' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str()); } else { ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\0'' is always false\n", errout_str()); } @@ -5335,7 +5335,7 @@ class TestCondition : public TestFixture { " if (!it->s.empty()) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (style) Condition '!it->s.empty()' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\n", errout_str()); check("struct X { std::string s; };\n" "void f(const std::vector&v) {\n" @@ -5344,13 +5344,13 @@ class TestCondition : public TestFixture { " if (!it->s.empty()) {}\n" " }\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (style) Condition '!it->s.empty()' is always true\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\n", "", errout_str()); // #10508 check("bool f(const std::string& a, const std::string& b) {\n" " return a.empty() || (b.empty() && a.empty());\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Return value 'a.empty()' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\n", errout_str()); check("struct A {\n" " struct iterator;\n" @@ -5376,14 +5376,14 @@ class TestCondition : public TestFixture { " return -1;\n" " return -1;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Condition 's.empty()' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(std::string& p) {\n" " const std::string d{ \"abc\" };\n" " p += d;\n" " if(p.empty()) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'p.empty()' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\n", errout_str()); check("bool f(int i, FILE* fp) {\n" " std::string s = \"abc\";\n" @@ -5396,7 +5396,7 @@ class TestCondition : public TestFixture { check("void f(const std::string& s) {\n" // #9148 " if (s.empty() || s.size() < 1) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition 's.size()<1' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void bar(std::vector& vv) {\n" // #11464 " class F {\n" @@ -5491,7 +5491,7 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:7]: (style) Condition 'i==1' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\n", errout_str()); // #10863 check("void f(const int A[], int Len) {\n" @@ -5524,7 +5524,7 @@ class TestCondition : public TestFixture { check("void f() {\n" " for (int i = 1000; i < 20; ++i) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'i<20' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\n", errout_str()); check("int foo(int foo, int bar, bool baz, bool flag) {\n" " if (baz && flag) {\n" @@ -5535,7 +5535,7 @@ class TestCondition : public TestFixture { " }\n" " return foo;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (style) Condition 'flag' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\n", errout_str()); } void alwaysTrueTryCatch() @@ -5619,15 +5619,15 @@ class TestCondition : public TestFixture { " if (activate) {}\n" " else if (foo) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'activate' is always false\n" - "[test.cpp:5]: (style) Condition 'foo' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\n" + "[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\n", errout_str()); // #6904 check("void f() {\n" " const int b[2] = { 1,0 };\n" " if(b[1] == 2) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'b[1]==2' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\n", errout_str()); // #9878 check("void f(bool a, bool b) {\n" @@ -5644,14 +5644,14 @@ class TestCondition : public TestFixture { " if(x) {}\n" " if(x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The if condition is the same as the previous if condition\n", + ASSERT_EQUALS("[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str()); check("void f(int x) {\n" " if(x == 1) {}\n" " if(x == 1) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The if condition is the same as the previous if condition\n", + ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str()); check("void f(int x) {\n" @@ -5768,7 +5768,7 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) The if condition is the same as the previous if condition\n", + ASSERT_EQUALS("[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" @@ -5818,13 +5818,13 @@ class TestCondition : public TestFixture { " b = 1;\n" " return a + b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style) The if condition is the same as the previous if condition\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str()); check("void f(double d) {\n" // #12712 " if (std::isfinite(d)) {}\n" " if (std::isfinite(d)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The if condition is the same as the previous if condition\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str()); check("struct S { int x; };\n" // #12391 "int f(const struct S* a, const struct S* b) {\n" @@ -5856,22 +5856,22 @@ class TestCondition : public TestFixture { check("void f(char *p, unsigned int x) {\n" " assert((p + x) < p);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow '(p+x)= p);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\n", errout_str()); check("void f(char *p, unsigned int x) {\n" " assert(p > (p + x));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\n", errout_str()); check("void f(char *p, unsigned int x) {\n" " assert(p <= (p + x));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\n", errout_str()); check("void f(signed int x) {\n" // unsigned overflow => don't warn " assert(x + 100U < x);\n" @@ -5881,7 +5881,7 @@ class TestCondition : public TestFixture { // x + c < x -#define MSG(EXPR, RESULT) "[test.cpp:1]: (warning) Invalid test for overflow '" EXPR "'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always " RESULT ".\n" +#define MSG(EXPR, RESULT) "[test.cpp:1:30]: (warning) Invalid test for overflow '" EXPR "'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always " RESULT ". [invalidTestForOverflow]\n" check("int f(int x) { return x + 10 > x; }"); ASSERT_EQUALS(MSG("x+10>x", "true"), errout_str()); @@ -5909,7 +5909,7 @@ class TestCondition : public TestFixture { // x + y < x #undef MSG -#define MSG(EXPR, RESULT) "[test.cpp:1]: (warning) Invalid test for overflow '" EXPR "'; signed integer overflow is undefined behavior. Some mainstream compilers removes handling of overflows when optimising the code and change the code to '" RESULT "'.\n" +#define MSG(EXPR, RESULT) "[test.cpp:1:36]: (warning) Invalid test for overflow '" EXPR "'; signed integer overflow is undefined behavior. Some mainstream compilers removes handling of overflows when optimising the code and change the code to '" RESULT "'. [invalidTestForOverflow]\n" check("int f(int x, int y) { return x + y < x; }"); ASSERT_EQUALS(MSG("x+y2U && s[0]=='4' && s[0]=='2';\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Return value 's[0]=='2'' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) { if (i == 1 || 2) {} }\n"); // #12487 - ASSERT_EQUALS("[test.cpp:1]: (style) Condition 'i==1||2' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\n", errout_str()); check("enum E { E1 = 1, E2 = 2 };\n" "void f(int i) { if (i == E1 || E2) {} }\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'i==E1||E2' is always true\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\n", errout_str()); } void pointerAdditionResultNotNull() { check("void f(char *ptr) {\n" " if (ptr + 1 != 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\n", errout_str()); } void duplicateConditionalAssign() { @@ -6110,7 +6110,7 @@ class TestCondition : public TestFixture { check("void f(std::string s) {\n" " if (s=\"123\"){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious assignment in condition. Condition 's=\"123\"' is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\"123\"' is always true. [assignmentInCondition]\n", errout_str()); check("void f(std::string *p) {\n" " if (p=foo()){}\n" @@ -6120,8 +6120,8 @@ class TestCondition : public TestFixture { check("void f(uint32_t u) {\n" // #2490 " if ((u = 0x00000000) || (u = 0xffffffff)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'u=0x00000000' is always false\n" - "[test.cpp:2]: (style) Condition 'u=0xffffffff' is always true\n", + ASSERT_EQUALS("[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\n" + "[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\n", errout_str()); } @@ -6131,12 +6131,12 @@ class TestCondition : public TestFixture { check("void f(unsigned char c) {\n" " if (c == 256) {}\n" "}", dinit(CheckOptions, $.s = &settingsUnix64)); - ASSERT_EQUALS("[test.cpp:2]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(unsigned char* b, int i) {\n" // #6372 " if (b[i] == 256) {}\n" "}", dinit(CheckOptions, $.s = &settingsUnix64)); - ASSERT_EQUALS("[test.cpp:2]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(unsigned char c) {\n" " if (c == 255) {}\n" @@ -6152,12 +6152,12 @@ class TestCondition : public TestFixture { check("void f(signed char x) {\n" " if (x == 0xff) {}\n" "}", dinit(CheckOptions, $.s = &settingsUnix64)); - ASSERT_EQUALS("[test.cpp:2]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(short x) {\n" " if (x == 0xffff) {}\n" "}", dinit(CheckOptions, $.s = &settingsUnix64)); - ASSERT_EQUALS("[test.cpp:2]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(int x) {\n" " if (x == 0xffffffff) {}\n" @@ -6189,7 +6189,7 @@ class TestCondition : public TestFixture { check("void f(int x) {\n" " if (x < 3000000000) {}\n" "}", dinit(CheckOptions, $.s = &settingsUnix64)); - ASSERT_EQUALS("[test.cpp:2]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(const signed char i) {\n" // #8545 " if (i > -129) {}\n" // warn @@ -6199,10 +6199,10 @@ class TestCondition : public TestFixture { " if (i <= +127) {}\n" // warn " if (i <= +126) {}\n" "}\n", dinit(CheckOptions, $.s = &settingsUnix64)); - ASSERT_EQUALS("[test.cpp:2]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true.\n" - "[test.cpp:3]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true.\n" - "[test.cpp:5]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true.\n" - "[test.cpp:6]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true.\n", + ASSERT_EQUALS("[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(const unsigned char u) {\n" @@ -6223,14 +6223,14 @@ class TestCondition : public TestFixture { " if (255 <= u) {}\n" " if (255 >= u) {}\n" // warn "}\n", dinit(CheckOptions, $.s = &settingsUnix64)); - ASSERT_EQUALS("[test.cpp:3]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false.\n" - "[test.cpp:4]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true.\n" - "[test.cpp:6]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false.\n" - "[test.cpp:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true.\n" - "[test.cpp:11]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false.\n" - "[test.cpp:12]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true.\n" - "[test.cpp:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false.\n" - "[test.cpp:17]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true.\n", + ASSERT_EQUALS("[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\n" + "[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\n", errout_str()); } @@ -6293,7 +6293,7 @@ class TestCondition : public TestFixture { " S1 mS;\n" "};" ); - ASSERT_EQUALS("[test.cpp:13] -> [test.cpp:18]: (style) Condition 'mS.b' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\n", errout_str()); } void knownConditionIncDecOperator() { @@ -6315,37 +6315,37 @@ class TestCondition : public TestFixture { " float f = 1.0;\n" " if (f > 1.0f) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f>1.0f' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11199 " float f = 1.0;\n" " if (f > 1.0L) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f>1.0L' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11199 " float f = 1.0f;\n" " if (f > 1.0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f>1.0' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11199 " float f = 1.0f;\n" " if (f > 1.0L) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f>1.0L' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11199 " float f = 1.0L;\n" " if (f > 1.0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f>1.0' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11199 " float f = 1.0L;\n" " if (f > 1.0f) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f>1.0f' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11201 " float f = 0x1.4p+3;\n" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0 @@ -6353,34 +6353,34 @@ class TestCondition : public TestFixture { " if (f < 9.9) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'f>9.9' is always true\n" - "[test.cpp:4]: (style) Condition 'f<9.9' is always false\n", + "[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\n" + "[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #12330 " double d = 1.0;\n" " if (d < 0.0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'd<0.0' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #12330 " long double ld = 1.0;\n" " if (ld < 0.0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'ld<0.0' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #12330 " float f = 1.0;\n" " if (f < 0.0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f<0.0' is always false\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #12774 " float f = 1.0f;\n" " if (f > 1.01f) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'f>1.01f' is always false\n", + "[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #12774 @@ -6388,7 +6388,7 @@ class TestCondition : public TestFixture { " if (f > 1.01) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'f>1.01' is always false\n", + "[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" @@ -6396,7 +6396,7 @@ class TestCondition : public TestFixture { " if (f > 1) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'f>1' is always false\n", + "[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13508 @@ -6413,7 +6413,7 @@ class TestCondition : public TestFixture { " if (f > 1) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'f>1' is always false\n", + "[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n"// #13508 @@ -6430,7 +6430,7 @@ class TestCondition : public TestFixture { " if (nf > +1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'nf>+1.0' is always false\n", + "[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11200 @@ -6438,7 +6438,7 @@ class TestCondition : public TestFixture { " if (f > -1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'f>-1.0' is always true\n", + "[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13508 @@ -6455,7 +6455,7 @@ class TestCondition : public TestFixture { " if (pf > -1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'pf>-1.0' is always true\n", + "[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13508 @@ -6472,7 +6472,7 @@ class TestCondition : public TestFixture { " if (nf > 1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Condition 'nf>1.0' is always false\n", + "[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // / #13508