diff handling of C++ template code between clang++ and cl.exe

Viewed 72

I got a piece of c++ code which could be compiled well with cl.exe (msvc 2019) by the command line of "cl.exe tt.cpp -c". Here is the code piece.

using void_t = void;

template <class _Ty, class = void>
struct _Add_reference { 
    using _Lvalue = _Ty;
    using _Rvalue = _Ty;
};


template <class _Ty>
struct _Add_reference<_Ty, void_t<_Ty&>> { 
    using _Lvalue = _Ty&;
    using _Rvalue = _Ty&&;
};

template <class _Ty>
using add_lvalue_reference_t = typename _Add_reference<_Ty>::_Lvalue;

template <class _Ty> 
constexpr bool _Is_copy_assignable_unchecked_v = __is_assignable_no_precondition_check(
    add_lvalue_reference_t<_Ty>, 
    add_lvalue_reference_t<const _Ty>
);

Here is the command line with cl.exe:

>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64\cl.exe" -c tt.cpp

While when I use clang.exe ( 12.0.0) to convert it to llvm ir (or just object file), I got some errors. Here is the command line with clang++.exe which issues some error message.

>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\bin\clang++.exe" -c tt.cpp or >"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\bin\clang++.exe" -S -emit-llvm tt.cpp Error message:

tt.cpp:24:29: error: expected '(' for function-style cast or type construction
        add_lvalue_reference_t<_Ty>,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
tt.cpp:26:1: error: expected '(' for function-style cast or type construction
);
^
2 errors generated.

Any comments on the above error in the scenario of clang++.exe? Thanks.

0 Answers
Related