I have this simple program:
test.cc
:
#include <limits>
#include <iostream>
#include <cmath>
int main() {
std::cout << (std::isinf(std::numeric_limits<long double>::infinity()) ? "true" : "false") << std::endl;
}
When I run it normally, the result is as expected:
g++ -std=c++17 -Wall -Wextra -pedantic -O0 -g3 test.cc && ./a.out
:
true
However, when I run it with valgrind, it instead prints false
.
g++ -std=c++17 -Wall -Wextra -pedantic -O0 -g3 test.cc && valgrind --leak-check=full -- ./a.out
:
==2680== Memcheck, a memory error detector
==2680== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2680== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==2680== Command: ./a.out
==2680==
false
==2680==
==2680== HEAP SUMMARY:
==2680== in use at exit: 0 bytes in 0 blocks
==2680== total heap usage: 2 allocs, 2 frees, 73,728 bytes allocated
==2680==
==2680== All heap blocks were freed -- no leaks are possible
==2680==
==2680== For lists of detected and suppressed errors, rerun with: -s
==2680== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Why does this happen?
(I use "g++ (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0" and "valgrind-3.15.0".)