3 ms·
"Make sure that what you assume won't compile actually doesn't compile." How do I do that properly? How do I test for undefined behaviour? I mean when I have
by xaedes 9y ago
"Make sure that what you assume won't compile actually doesn't compile."
How do I do that properly?
How do I test for undefined behaviour?
I mean when I have code where I know that (ab-)using it in a certain way will trigger undefined behaviour, how do I test that?
- saghm 9y agoIf you want to test that something doesn't compile, you just try to compile it and it either will succeed or fall. UB is a runtime thing, so that's not relevant to this point.
- xaedes 9y agoYou mean including code snippets of not compiling code in the automated(!) tests and compiling them from there? Hm, That makes sense. Anybody know a good framework for this? I can imagine that supporting different compilers output isn't a trivial thing that one should have to rebuild themselves. Btw: The undefined behaviour question was meant to be unrelated to the "not compiling" one.
- saghm 9y agoOffhand, I would just use whatever CI tool you're already using to test various compiler/OS combinations and then just write a bash script to run that compiles a test file (given as an argument) and exits with the opposite exit code that the compiler gives (i.e. 0 for failure, 1 for success).
- gpderetta 9y agoMany test systems allow for expected-fail tests. Also this being c++, of course there are ways to test that an expression does not compile via metaprogramming (i.e. SFINAE).
- saghm 9y agoAlmost forgot to respond to the UB part: you can use clang's UBSAN to help detect when undefined behavior occurs. https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html