Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

MSVC slash options ignored even in 'cl' driver mode #44326

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR45356
Status NEW
Importance P normal
Reported by Brad King (brad.king@kitware.com)
Reported on 2020-03-30 06:11:43 -0700
Last modified on 2021-09-28 17:11:40 -0700
Version unspecified
Hardware PC Windows NT
CC alexfh@google.com, djasper@google.com, etienne@atnnn.com, heavenandhell171@gmail.com, klimek@google.com, mizvekov@gmail.com, samuelmkearney@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

It does not seem possible to invoke clang-tidy with a cl command line that uses slash-style options:

clang-tidy --extra-arg-before=--driver-mode=cl ... -- cl /GR /EHsc ...

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" [...]
#error "__cplusplus is not C++17"
 ^
C:\...\foo.cpp:5:2: error: "_MSVC_LANG is not C++17" [...]
#error "_MSVC_LANG is not C++17"
 ^

>clang-tidy foo.cpp -- cl -GR -EHsc -std:c++17
error: unknown argument: '-EHsc' [...]
error: unknown argument: '-std:c++17' [...]
C:\...\foo.cpp:2:2: error: "__cplusplus is not C++17" [...]
#error "__cplusplus is not C++17"
 ^
C:\...\foo.cpp:5:2: error: "_MSVC_LANG is not C++17" [...]
#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 [...]
  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.

Quuxplusone commented 4 years ago
For reference, this came up in CMake here:

    https://gitlab.kitware.com/cmake/cmake/-/issues/20512