Enabling C++14 in clang in Visual Studio

后端 未结 2 1568
小鲜肉
小鲜肉 2020-12-30 08:02

I\'ve installed clang 3.7 and I\'m using it with visual studio. When I try to compile:

auto f()
{
return 2;
}

I\'m getting error saying tha

相关标签:
2条回答
  • 2020-12-30 08:49

    I work on clang-cl. As antiduh says, clang-cl tries to mimic Visual Studio's cl. cl up to and including c++14 didn't have a switch for enabling language modes, it just always enabled all the latest stuff. Hence, clang-cl does too. MSVC gained some C++14 support in MSVC 2015, so if you tell clang-cl that you want it to emulate MSVC 2015 or later, it will automatically enable C++14. clang-cl by default emulates the version of MSVC found on your system. You can explicitly pass -fmsc-version=1900 to force emulation of 2015, which will then implicitly enable C++14.

    As of MSVC 2017, cl.exe supports a /std: flag, so clang-cl supports that too. It can be used to enable C++14 (the lowest level), C++17, C++20, or the newest-known version.

    The -Xclang flags are internal flags and are not considered a stable interface. So do not use those.

    0 讨论(0)
  • 2020-12-30 08:53

    clang-cl doesn't use the same option syntax as traditional clang - it's supposed to mimic Visual Studio's cl command line, not clang's command line.

    For instance, from clang-cl's documentation:

    CL.EXE COMPATIBILITY OPTIONS:
      /?                     Display available options
      /arch:<value>          Set architecture for code generation
      /C                     Don't discard comments when preprocessing
      /c                     Compile only
      /D <macro[=value]>     Define macro
      ...
    

    Notice that those options are similar to Microsoft's cl option syntax, not clang's option syntax.

    However, they have a little pass-through option to support cases like yours:

    OPTIONS:
      ...
      -Xclang <arg>         Pass <arg> to the clang compiler
      -mllvm <value>        Additional arguments to forward to LLVM's option processing
    

    And so it would seem that invoking clang-cl -Xclang -std=c++14 would be your best bet.

    0 讨论(0)
提交回复
热议问题