llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.53k forks source link

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

Open bradking opened 4 years ago

bradking commented 4 years ago
Bugzilla Link 45356
Version unspecified
OS Windows NT
CC @atnnn,@Ivan171,@mizvekov

Extended Description

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.

bradking commented 4 years ago

For reference, this came up in CMake here:

https://gitlab.kitware.com/cmake/cmake/-/issues/20512
dmenendez-gruposantander commented 2 years ago

I'm trying to use clang-tidy version 11.0 with CMake and this issue is a stopper for us. Any news on this issue? Has it been solved in a more recent version?

dmenendez-gruposantander commented 2 years ago

And it seems clang-tidy version 13.0 has the same issue.