Hacker News new | past | comments | ask | show | jobs | submit login

If 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.



You 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.


Offhand, 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).


Almost 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


Many 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).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: