title: How can I make the Microsoft C++ compiler treat unknown flags as errors rather than warnings?
body: <p>For various reasons, I would like to be able to script the detection of whether the MS C++ compiler honors a particular flag. I'm using the compiler from the Windows 7.1 SDK:</p>
  
  <pre><code>C:\&gt; cl /version
  Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.
  </code></pre>
  
  <p>So lets say I want to know if the flag <code>/GLEFGB</code> is supported by this compiler (which it is not, because it doesn't exist):</p>
  
  <pre><code>C:\&gt;cl /c ./foo.cc /GLEFBG
  Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.
  
  cl : Command line warning D9002 : ignoring unknown option '/GEFBG'
  foo.cc
  </code></pre>
  
  <p>OK, good start, but it is a warning, and it doesn't set the exit status to invalid:</p>
  
  <pre><code>C:\&gt;echo %errorLevel%
  0
  </code></pre>
  
  <p>So we should be done if we turn on warnings as errors with <code>/WX</code>, right?</p>
  
  <pre><code>C:\&gt;cl /c ./foo.cc /WX /GLEFBG
  
  Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.
  
  cl : Command line warning D9002 : ignoring unknown option '/GEFBG'
  foo.cc
  </code></pre>
  
  <p>Wrong. This is getting disappointing. Maybe D9002 isn't captured by <code>/WX</code> for some reason? Maybe we can explicitly make it an error by using <code>/we</code> with that code? Care to guess whether this will work?</p>
  
  <pre><code>C:\&gt;cl /c ./foo.cc /WX /weD9002 /GLEFBG
  Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.
  
  cl : Command line error D8021 : invalid numeric argument '/weD9002'
  </code></pre>
  
  <p>Nope, now we error out because apparently the tag for this compiler warning is not a legal argument to <code>/we</code>. I also tried <code>/we9002</code>, which doesn't work either.</p>
  
  <p>So, now I am out of ideas. Any thoughts on how to convince <code>cl</code> to error out with a non-zero exit status if passed an invalid flag? It is really hard to interrogate the compiler for flag support without this sort of behavior.</p>