c++ - clang++ 和 cl.exe 之间 C++ 模板代码的差异处理
问题描述
我得到了一段 c++ 代码,可以通过命令行“cl.exe tt.cpp -c”用 cl.exe (msvc 2019) 很好地编译。这是代码片段。
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>
);
这是 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
当我使用 clang.exe ( 12.0.0 )将其转换为 llvm ir (或只是目标文件)时,我遇到了一些错误。这是带有 clang++.exe 的命令行,它发出一些错误消息。
>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\bin\clang++.exe" -c tt.cpp
或
>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\bin\clang++.exe" -S -emit-llvm tt.cpp
错误信息:
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.
对clang++.exe场景中的上述错误有什么意见吗?谢谢。
解决方案
推荐阅读
- php - 带有 php mysql pdo 的 Azure Windows Web 应用程序
- node.js - shopify-api-node:承诺不返回值
- reactjs - JSX 没有返回预期的 HTML
- file - 检查目录中是否存在重复文件的批处理脚本
- python - 为什么将字符串添加到列表时,增强赋值的行为会有所不同
- java - @OneToOne JPA 休眠无法确定类型
- c# - 在 POST 之前从视图中收集值
- javascript - Angularjs Scope变量对象未在单选按钮控制器中初始化
- sql - 将多个表中的数据合并到一个列中
- python - 了解 scipy.ndimage.filters.convolve 函数