title: C++ testing for compile errors
body: <p>I'm a student, and I'm trying to write and run some test code for an assignment to check it before I turn it in. What I'm trying to do now is test that my code prevents value semantics properly. In my assignment, I have declared for each of my classes its own <i>private</i> copy constructor and assignment operator that have no definition, and so do nothing. When they are called in my test program, I am getting compile errors like I expected. Something like this:</p>
  <blockquote>
  <p>error: 'myClass::myClass(const &amp;myClass)' is private'</p>
  <p>error: 'myClass&amp; myClass::operator=(const myClass&amp;)' is private</p>
  </blockquote>
  <p>Is there a way to use try/catch so that my test code will compile and run, but show me that these errors did occur?
  I've tried:</p>
  <pre><code>myClass obj1(...);
  myClass obj2(...);
  try{
    obj1 = obj2;
    throw 1;
  }
  catch(int e){
    assert(e==1);
  }
  </code></pre>
  <p>but the compiler is still giving me the above errors. Are these not 'exceptions'? Will they not trigger a throw?</p>
  <p>If I'm understanding try/catch correctly, it handles runtime errors, not the kind errors I was getting above, correct?</p>
  <p>After doing some more research, it seems that there is no (easy) way of testing for certain compile errors natively within C++ (this maybe true for most languages, now that I think about it). I read a <a href="https://stackoverflow.com/questions/7282350/how-to-unit-test-deliberate-compilation-errors">post</a> that suggests writing some test code in a scripting language that attempts to compile snippets of C++ code and checks for any errors, and another <a href="https://stackoverflow.com/questions/9003061/how-to-test-that-some-code-doesnt-compile-in-c">post</a> that recommends using Boost.Build.</p>
  <p>What is the easiest/best way of doing what I'm trying to do?</p>
  <p>I looked at the documentation for Boost.Build and it's a bit over my head. If I used it, how would I test that a file, say 'test.cpp' compiles, and maybe handle specific compile errors that occur with 'test.cpp'?</p>
  <p>Thanks for your help!</p>
  <p>P.S. This is one of my first posts, hopefully I've done &quot;enough&quot; research, and done everything else properly. Sorry if I didn't.</p>