【发布时间】:2019-08-01 10:25:18
【问题描述】:
我第一次尝试在 mac 中使用 clang 编译我的 repo。 Clang 为 std 命名空间的所有用法提供错误。它总是说使用 ::std::whatever 而不是 std::whatever。我在 ADL 或其他方面做错了吗?
如果有人想查看完整源代码,请访问repo
当我将它编写为 ::std::whatever 时它会编译,但我想知道为什么它强制我添加全局范围解析运算符?
template <typename S, typename T>
class implements_left_stream
{
template <typename SS, typename TT>
static auto test ( int )
-> decltype ( std::declval<SS &>() << std::declval<TT>(), std::true_type() );
template <typename, typename>
static auto test ( ... ) -> std::false_type;
public:
static const bool value = decltype ( test<S, T> ( 0 ) ) ::value;
};
错误是:
speech/util.h:34:20: error: no template named 'declval' in namespace 'speech::impl::std'; did you mean '::std::declval'?
[build] -> decltype ( std::declval<SS &>() << std::declval<TT>(), std::true_type() );
[build] ^~~~~~~~~~~~
[build] ::std::declval
[build] /Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits:1147:1: note: '::std::declval' declared here
[build] declval() _NOEXCEPT;
【问题讨论】:
-
请创建一个minimal reproducible example 向我们展示(在问题正文中),它必须包含您
#include的头文件。 -
作为您的问题的可能提示,想想您在哪里做
#include <cxxabi.h>... -
最后,总是显式地包含声明或定义函数和结构的文件。对于
std::declval,它是<utility>。在包含它(在任何命名空间之外)的同时,您也可能会解决您的问题。 -
为什么在命名空间中包含头文件?为什么不在全局范围内做this?