clang-tidy: MSVC driver mode and cl flags
Since !4208 (merged) and !4307 (merged) we now explicitly pass --extra-arg-before=--driver-mode=cl
to clang-tidy
when using with the cl
compiler. This fixed warnings like that in #18731 (closed) about -std:...
options. However, now options like /EHsc
seem to be ignored and cause problems like that in #18731 (comment 722294).
I tried the following with clang-tidy 7 and 10.
With a source foo.cpp
:
#if __cplusplus < 201703L
#error "__cplusplus is not C++17"
#endif
#if _MSVC_LANG < 201703L
#error "_MSVC_LANG is not C++17"
#endif
int main()
{
try { } catch (...) { };
return 0;
}
I tried the following combinations:
>clang-tidy foo.cpp -- cl /GR /EHsc /std:c++17
C:\...\foo.cpp:2:2: error: "__cplusplus is not C++17" [clang-diagnostic-error]
#error "__cplusplus is not C++17"
^
C:\...\foo.cpp:5:2: error: "_MSVC_LANG is not C++17" [clang-diagnostic-error]
#error "_MSVC_LANG is not C++17"
^
>clang-tidy foo.cpp -- cl -GR -EHsc -std:c++17
error: unknown argument: '-EHsc' [clang-diagnostic-error]
error: unknown argument: '-std:c++17' [clang-diagnostic-error]
C:\...\foo.cpp:2:2: error: "__cplusplus is not C++17" [clang-diagnostic-error]
#error "__cplusplus is not C++17"
^
C:\...\foo.cpp:5:2: error: "_MSVC_LANG is not C++17" [clang-diagnostic-error]
#error "_MSVC_LANG is not C++17"
^
>clang-tidy --extra-arg-before=--driver-mode=cl foo.cpp -- cl /GR /EHsc -std:c++17
C:\...\foo.cpp:10:3: error: cannot use 'try' with exceptions disabled [clang-diagnostic-error]
try { } catch (...) { };
^
>clang-tidy --extra-arg-before=--driver-mode=cl foo.cpp -- cl -GR -EHsc -std:c++17
(works)
Without --extra-arg-before=--driver-mode=cl
, /std:...
is accepted but does nothing. With --extra-arg-before=--driver-mode=cl
, only the cl
option forms starting in -
instead of /
seem to work.