Skip to main content
added 200 characters in body
Source Link
Basile Starynkevitch
  • 32.9k
  • 6
  • 90
  • 133

Most likely your code has some undefined behavior (as others explained, you are much more likely to have bugs in your code than in the compiler, even if C++ compilers are so complex that they do have bugs; even the C++ specification has design bugs). And UB can be here even if the compiled executable happens to work (by bad luck).

So you should read Lattner' blog What Every C Programmer should know about undefined behavior (most of it applies for C++11 too).

The valgrind tool, and recent -fsanitize= instrumentation options to GCC (or Clang/LLVM), should also be helpful. And of course, enable all warnings: g++ -Wall -Wextra

Most likely your code has some undefined behavior. And UB can be here even if the compiled executable happens to work (by bad luck).

So you should read Lattner' blog What Every C Programmer should know about undefined behavior (most of it applies for C++11 too).

The valgrind tool, and recent -fsanitize= instrumentation options to GCC (or Clang/LLVM), should also be helpful. And of course, enable all warnings: g++ -Wall -Wextra

Most likely your code has some undefined behavior (as others explained, you are much more likely to have bugs in your code than in the compiler, even if C++ compilers are so complex that they do have bugs; even the C++ specification has design bugs). And UB can be here even if the compiled executable happens to work (by bad luck).

So you should read Lattner' blog What Every C Programmer should know about undefined behavior (most of it applies for C++11 too).

The valgrind tool, and recent -fsanitize= instrumentation options to GCC (or Clang/LLVM), should also be helpful. And of course, enable all warnings: g++ -Wall -Wextra

Source Link
Basile Starynkevitch
  • 32.9k
  • 6
  • 90
  • 133

Most likely your code has some undefined behavior. And UB can be here even if the compiled executable happens to work (by bad luck).

So you should read Lattner' blog What Every C Programmer should know about undefined behavior (most of it applies for C++11 too).

The valgrind tool, and recent -fsanitize= instrumentation options to GCC (or Clang/LLVM), should also be helpful. And of course, enable all warnings: g++ -Wall -Wextra