使用 clang & libstdc++ 时不能使用 experimental::optional 的常量引用
Cannot use a constant reference of experimental::optional when using clang & libstdc++
我正在使用实验::可选<> 变量的常数引用,但是当我使用 operator->()在上面,我有一个编译错误,但仅在使用 clang 和 libstdc 。
时#include <experimental/optional>
#include <iostream>
#include <vector>
int main(void)
{
std::experimental::optional<std::vector<int>> opt;
const auto &rf = opt;
opt.emplace();
opt->push_back(1);
std::cout << "opt->size() = " << opt->size()
<< " rf->size() = " << rf->size() << "n";
return 0;
}
运行此程序:
$ clang++ -W -Wall -std=c++14 -stdlib=libc++ test.cc && ./a.out
opt->size() = 1 rf->size() = 1 # OK
$ g++ -W -Wall -std=c++14 test.cc && ./a.out
opt->size() = 1 rf->size() = 1 # OK
$ clang++ -W -Wall -std=c++14 test.cc
In file included from test.cc:1:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/optional:576:16: error: call to '__constexpr_addressof' is ambiguous
{ return __constexpr_addressof(this->_M_get()); }
^~~~~~~~~~~~~~~~~~~~~
test.cc:14:40: note: in instantiation of member function 'std::experimental::fundamentals_v1::optional<std::vector<int, std::allocator<int> > >::operator->' requested here
<< " rf->size() = " << rf->size() << "n";
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/optional:173:20: note: candidate function [with _Tp = const std::vector<int, std::allocator<int> >, $1 = <>]
constexpr _Tp* __constexpr_addressof(_Tp& __t)
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/optional:180:17: note: candidate function [with _Tp = const std::vector<int, std::allocator<int> >, $1 = <>]
inline _Tp* __constexpr_addressof(_Tp& __t)
^
1 error generated.
每当我使用常数参考时,就会发生此错误:显然是非恒定引用是可以的。
我正在使用Linux Mint 18与这些版本的G /libstdc 5.4.0和clang 3.8.0:
$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ dpkg-query -s libstdc++-5-dev
...
Version: 5.4.0-6ubuntu1~16.04.4
...
$ clang++ --version
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
这是我的程序中的错误,libstdc 还是clang ?
update :clang 3.9.0 的问题消失了。(如下所述,理查德·史密斯(Richard Smith)和维尔·沃特莱恩(Ville Voutilainen)所解释的那样,Libstdc 似乎期望编译器以某种方式行为与Clang 3.8.0不符。)
对我来说肯定看起来像一个叮当虫,因为它诊断为模棱两可的过载具有相互分辨的enable_if约束,因此不应该有可能模棱两可。
相关文章:
- std::experimental::source_location 在编译时
- 在 G++ v8.2.0 中使用 std::experimental::可选
- 未定义的引用,尽管存在符号,但 std::experimental::可选
- std::filesystem 和 std::experimental::filesystem 之间的路径差异
- C++ VS 错误:<实验/文件系统>提供 std::experimental::文件系统的标头已被Microsoft弃用,将被删除
- MatMul op 在 tensorflow 中是如何工作的?
- 添加 OP 张量流调试
- cv2有什么区别.StereoSGBM_create() 和 cv2.StereoBM_create() 函数用于 Op
- 使用 std::experimental::optional,给出编译错误
- 如何从C++代码运行自定义 GPU tensorflow::op?
- std::p riority_queue::p op什么时候会抛出异常
- experimental::filesystem::d irectory_iterator& operator++()
- std::experimental::source_location Visual Studio 中的实现
- 为什么捕获std :: Isringstream的RVALUE的OP会失败
- 在Vulkan中重新固定图形管道,保证了No-Op
- [expr.unary.op]/9 似乎暗示"运算符!()' 不能应用于下面的类型 A.但编译器不同意这一点
- 在 Ubuntu 16.04 下运行协程示例会得到"'experimental/coroutine' file not found"
- 为什么我不能将 op 结果乘以常量特征张量数组
- C++ grpc::experimental:interceptor 如何从自定义拦截器返回状态和消息
- 不兼容的操作原则到三元op