For various reasons, I would like to be able to determine if the MS C ++ compiler respects a specific flag. I am using the compiler from the Windows 7.1 SDK:
C:\> cl /version Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64 Copyright (C) Microsoft Corporation. All rights reserved.
So let's say I want to know if this /GLEFGB flag is /GLEFGB this compiler (which is not because it does not exist):
C:\>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
Ok, a good start, but this is a warning and it does not set the exit status to void:
C:\>echo %errorLevel% 0
So, we have to do this if we enable warnings as errors using /WX , right?
C:\>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
Wrong. This is disappointing. Maybe the D9002 does not fall under /WX for some reason? Maybe we can explicitly make this a mistake using /we with this code? Guess if this will work?
C:\>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'
No, now we are mistaken, because, apparently, the tag for this compiler warning is not a legal argument for /we . I also tried /we9002 , which also does not work.
So now I have no ideas. Any thoughts on how to convince cl of an error with non-zero exit status if an invalid flag is passed? It is very difficult to interrogate the compiler to support the flag without this behavior.