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"
" int bsd_signal(0);\n"
" return bsd_signal;\n"
"}");
ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
" struct hostent *hp;\n"
" if(!hp = gethostbyname(\"127.0.0.1\")) {\n"
" exit(1);\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\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:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\n", errout_str());
}
voidprohibitedFunctions_index() {
check("namespace n1 {\n"
" int index(){ return 1; };\n"
"}\n"
"int main()\n"
"{\n"
" n1::index();\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout_str());
check("std::size_t f()\n"
"{\n"
" std::size_t index(0);\n"
" index++;\n"
" return index;\n"
"}");
ASSERT_EQUALS("", errout_str());
check("int f()\n"
"{\n"
" return this->index();\n"
"}");
ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
" int index( 0 );\n"
"}");
ASSERT_EQUALS("", errout_str());
check("const char f()\n"
"{\n"
" const char var[6] = \"index\";\n"
" const char i = index(var, 0);\n"
" return i;\n"
"}");
ASSERT_EQUALS("[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\n",
"[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",
errout_str());
}
voidprohibitedFunctions_rindex() {
check("void f()\n"
"{\n"
" int rindex( 0 );\n"
"}");
ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
" const char var[7] = \"rindex\";\n"
" print(rindex(var, 0));\n"
"}");
ASSERT_EQUALS("[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\n", errout_str());
}
voidprohibitedFunctions_var() {
check("class Fred {\n"
"public:\n"
" Fred() : index(0) { }\n"
" int index;\n"
"};");
ASSERT_EQUALS("", errout_str());
}
voidprohibitedFunctions_gets() {
check("void f()\n"
"{\n"
" char *x = gets(a);\n"
"}");
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:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str());
}
voidprohibitedFunctions_alloca() {
check("void f()\n"
"{\n"
" char *x = alloca(10);\n"
"}"); // #4382 - there are no VLAs in C++
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: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"
"{\n"
" char *x = alloca(10);\n"
"}", s); // #4382 - there are no VLAs in C++
ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
" char *x = alloca(10);\n"
"}", s, false); // #7558 - no alternative to alloca in C89
ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
" char *x = alloca(10);\n"
"}", s, false);
ASSERT_EQUALS("", errout_str());
}
// ticket #3121
voidprohibitedFunctions_declaredFunction() {
check("int ftime ( int a )\n"
"{\n"
" return a;\n"
"}\n"
"int main ()\n"
"{\n"
" int b ; b = ftime ( 1 ) ;\n"
" return 0 ;\n"
"}");
ASSERT_EQUALS("", errout_str());
}
// test std::gets
voidprohibitedFunctions_std_gets() {
check("void f(char * str)\n"
"{\n"
" char *x = std::gets(str);\n"
" char *y = gets(str);\n"
"}");
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
voidprohibitedFunctions_multiple() {
check("void f(char * str)\n"
"{\n"
" char *x = std::gets(str);\n"
" usleep( 1000 );\n"
"}");
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());
}
voidprohibitedFunctions_c_declaration() {
check("char * gets ( char * c ) ;\n"
"int main ()\n"
"{\n"
" char s [ 10 ] ;\n"
" gets ( s ) ;\n"
" return 0;\n"
"}");
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:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\n", errout_str());
}
voidprohibitedFunctions_functionWithBody() {
check("char * gets ( char * c ) { return c; }\n"
"int main ()\n"
"{\n"
" char s [ 10 ] ;\n"
" gets ( s ) ;\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout_str());
}
voidprohibitedFunctions_crypt() {
check("void f(char *pwd)\n"
"{\n"
" char *cpwd;"
" crypt(pwd, cpwd);\n"
"}");
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"
" char *pwd = getpass(\"Password:\");"
" char *cpwd;"
" crypt(pwd, cpwd);\n"
"}");
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"
" int crypt = 0;"
" return crypt;\n"
"}");
ASSERT_EQUALS("", errout_str());
}
voidprohibitedFunctions_namespaceHandling() {
check("void f()\n"
"{\n"
" time_t t = 0;"
" auto lt = std::localtime(&t);\n"
"}");
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: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"
"{\n"
" time_t t = 0;"
" struct tm *foo = localtime(&t);\n"
"}");
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: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"
"{\n"
" return 123;\n"
"}");
ASSERT_EQUALS("", errout_str());
// Be quiet on other namespaces
check("void f()\n"
"{\n"
" foobar::getpwent();\n"
"}");
ASSERT_EQUALS("", errout_str());
// Be quiet on class member functions
check("void f()\n"
"{\n"
" foobar.getpwent();\n"
"}");
ASSERT_EQUALS("", errout_str());
}
voidinvalidFunctionUsage1() {
check("void f() { memset(a,b,sizeof(a)!=12); }");
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: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: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: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: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: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: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: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());
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: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());
check("void f(std::vector<int>& v) {\n"// #10754
" int N = -1;\n"
" for (long i = 0; i < g(); i++)\n"
" N = h(N);\n"
" v.resize(N);\n"
"}\n");
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<int>& v, int N) {\n"
" if (N < -1)\n"
" return;\n"
" v.resize(N);\n"
"}\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<int>& v, int N) {\n"
" if (N == -1) {}\n"
" v.resize(N);\n"
"}\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<int>& v, int N, bool b) {\n"
" if (b)\n"
" N = -1;\n"
" v.resize(N);\n"
"}\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<int>& v) {\n"
" int N = -1;\n"
" v.resize(N);\n"
"}\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());
}
voidinvalidFunctionUsageStrings() {
check("size_t f() { char x = 'x'; return strlen(&x); }");
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: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());
check("size_t f() {\n"
" char x;\n"
" if (y)\n"
" x = '\\0';\n"
" else\n"
" x = 'a';\n"
" return strlen(&x);\n"
"}");
ASSERT_EQUALS("[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\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());
TODO_ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\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: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("[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"
" struct {\n"
" uint16_t nr;\n"
" uint8_t d[40];\n"
" } data;\n"
" char buf[42];\n"
" } x;\n"
"};\n"
"int f(struct someStruct * const tp, const int k)\n"
"{\n"
" return strcmp(&tp->x.buf[k], \"needle\");\n"
"}");
ASSERT_EQUALS("", errout_str());
check("struct someStruct {\n"
" char buf[42];\n"
"};\n"
"int f(struct someStruct * const tp, const int k)\n"
"{\n"
" return strcmp(&tp->buf[k], \"needle\");\n"
"}");
ASSERT_EQUALS("", errout_str());
check("const char x = 'x'; size_t f() { char y = x; return strlen(&y); }");
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() { char y = x; return strlen(&y); }");
ASSERT_EQUALS("", errout_str());
check("size_t f() {\n"
" char * a = \"Hello world\";\n"
" char ** b = &a;\n"
" return strlen(&b[0][0]);\n"
"}");
ASSERT_EQUALS("", errout_str());
check("size_t f() {\n"
" char ca[] = \"asdf\";\n"
" return strlen((char*) &ca);\n"
"}");
ASSERT_EQUALS("", errout_str());
// #5225
check("int main(void)\n"
"{\n"
" char str[80] = \"hello worl\";\n"
" char d = 'd';\n"
" strcat(str, &d);\n"
" puts(str);\n"
" return 0;\n"
"}");
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: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:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\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:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str());
check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }");
ASSERT_EQUALS("[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\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"
" std::cout << log(-1) << std::endl;\n"
" std::cout << logf(-1) << std::endl;\n"
" std::cout << logl(-1) << std::endl;\n"
" std::cout << log10(-1) << std::endl;\n"
" std::cout << log10f(-1) << std::endl;\n"
" std::cout << log10l(-1) << std::endl;\n"
" std::cout << log2(-1) << std::endl;\n"
" std::cout << log2f(-1) << std::endl;\n"
" std::cout << log2l(-1) << std::endl;\n"
" std::cout << log1p(-2) << std::endl;\n"
" std::cout << log1pf(-2) << std::endl;\n"
" std::cout << log1pl(-2) << std::endl;\n"
"}");
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"
" std::cout << log(-1.0) << std::endl;\n"
" std::cout << logf(-1.0) << std::endl;\n"
" std::cout << logl(-1.0) << std::endl;\n"
" std::cout << log10(-1.0) << std::endl;\n"
" std::cout << log10f(-1.0) << std::endl;\n"
" std::cout << log10l(-1.0) << std::endl;\n"
" std::cout << log2(-1.0) << std::endl;\n"
" std::cout << log2f(-1.0) << std::endl;\n"
" std::cout << log2l(-1.0) << std::endl;\n"
" std::cout << log1p(-2.0) << std::endl;\n"
" std::cout << log1pf(-2.0) << std::endl;\n"
" std::cout << log1pl(-2.0) << std::endl;\n"
"}");
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"
" std::cout << log(-0.1) << std::endl;\n"
" std::cout << logf(-0.1) << std::endl;\n"
" std::cout << logl(-0.1) << std::endl;\n"
" std::cout << log10(-0.1) << std::endl;\n"
" std::cout << log10f(-0.1) << std::endl;\n"
" std::cout << log10l(-0.1) << std::endl;\n"
" std::cout << log2(-0.1) << std::endl;\n"
" std::cout << log2f(-0.1) << std::endl;\n"
" std::cout << log2l(-0.1) << std::endl;\n"
" std::cout << log1p(-1.1) << std::endl;\n"
" std::cout << log1pf(-1.1) << std::endl;\n"
" std::cout << log1pl(-1.1) << std::endl;\n"
"}");
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"
" std::cout << log(0) << std::endl;\n"
" std::cout << logf(0.) << std::endl;\n"
" std::cout << logl(0.0) << std::endl;\n"
" std::cout << log10(0.0) << std::endl;\n"
" std::cout << log10f(0) << std::endl;\n"
" std::cout << log10l(0.) << std::endl;\n"
" std::cout << log2(0.) << std::endl;\n"
" std::cout << log2f(0.0) << std::endl;\n"
" std::cout << log2l(0) << std::endl;\n"
" std::cout << log1p(-1.) << std::endl;\n"
" std::cout << log1pf(-1.0) << std::endl;\n"
" std::cout << log1pl(-1) << std::endl;\n"
"}");
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"