Is there an easy/recommended way to automate testing of code that should not compile actually not compiling? For example, I have something like this under GTest:
TEST(Foo,Bar)
{
EXPECT_TRUE( func1() );
Foo x(1.0);
Foo::Bar<double> good(x);
#if 0 // should not compile with rvalue ref!
Foo::Bar<double> crashGetter(Foo(1.0));
#endif
}
Can the "change to #if 1, try to build, verify it still fails, put back #if 0" be automated for testing?
EDIT: this related question has someone more useful answers: "how-to-unit-test-deliberate-compilation-errors"
EDIT: This test is not for myself. The scenario I want to guard against is someone else hitting a compiler error, going in and "fixing" the header that #include'd and thinking "cool the unit tests still pass", thus leading to subtle bugs appearing as Rvalue refs get used wrongly in more and more code.
EDIT: best similar Q suggested by comments: How to unit test deliberate compilation errors?