C++11 为什么不使用GCC4.9编译带有共享\u ptr的原子\u加载?

C++11 为什么不使用GCC4.9编译带有共享\u ptr的原子\u加载?,c++11,gcc,C++11,Gcc,这不是使用gcc 4.9.3(来自docker repo)编译的: #包括 #包括没有提到任何麻烦 我只是把这个贴在这里,因为我花了几个小时来解决这个问题,所以其他人都不必为此浪费时间:) 编辑:添加编译器输出: test.cpp: In function 'int main()': test.cpp:6:30: error: no matching function for call to 'atomic_load(std::shared_ptr<int>*)' auto n

这不是使用gcc 4.9.3(来自docker repo)编译的:

#包括
#包括没有提到任何麻烦

我只是把这个贴在这里,因为我花了几个小时来解决这个问题,所以其他人都不必为此浪费时间:)

编辑:添加编译器输出:

test.cpp: In function 'int main()':
test.cpp:6:30: error: no matching function for call to 'atomic_load(std::shared_ptr<int>*)'
  auto n = std::atomic_load(&p);
                              ^
test.cpp:6:30: note: candidates are:
In file included from test.cpp:2:0:
/usr/local/include/c++/4.9.3/atomic:906:5: note: template<class _ITp> _ITp std::atomic_load(const std::atomic<_ITp>*)
     atomic_load(const atomic<_ITp>* __a) noexcept
     ^
/usr/local/include/c++/4.9.3/atomic:906:5: note:   template argument deduction/substitution failed:
test.cpp:6:30: note:   'std::shared_ptr<int>' is not derived from 'const std::atomic<_ITp>'
  auto n = std::atomic_load(&p);
                              ^
In file included from test.cpp:2:0:
/usr/local/include/c++/4.9.3/atomic:911:5: note: template<class _ITp> _ITp std::atomic_load(const volatile std::atomic<_ITp>*)
     atomic_load(const volatile atomic<_ITp>* __a) noexcept
     ^
/usr/local/include/c++/4.9.3/atomic:911:5: note:   template argument deduction/substitution failed:
test.cpp:6:30: note:   'std::shared_ptr<int>' is not derived from 'const volatile std::atomic<_ITp>'
  auto n = std::atomic_load(&p);
                              ^
test.cpp:在函数“int main()”中:
test.cpp:6:30:错误:对“原子加载(std::shared_ptr*)”的调用没有匹配的函数
自动n=标准::原子加载(&p);
^
考试。cpp:6:30:注:考生为:
在test.cpp中包含的文件中:2:0:
/usr/local/include/c++/4.9.3/atomic:906:5:注意:模板_itpstd::atomic_load(const std::atomic*)
原子负载(常量原子*uu a)无异常
^
/usr/local/include/c++/4.9.3/atomic:906:5:注意:模板参数推断/替换失败:
test.cpp:6:30:注意:“std::shared_ptr”不是从“const std::atomic”派生的
自动n=标准::原子加载(&p);
^
在test.cpp中包含的文件中:2:0:
/usr/local/include/c++/4.9.3/atomic:911:5:注意:模板_itpstd::atomic_load(const volatile std::atomic*)
原子负载(常量挥发性原子*uu a)无异常
^
/usr/local/include/c++/4.9.3/atomic:911:5:注意:模板参数推断/替换失败:
test.cpp:6:30:注意:“std::shared_ptr”不是从“const volatile std::atomic”派生的
自动n=标准::原子加载(&p);
^

这是libstdc++库中的一个遗漏。看这个。 在“运行时库”一节中提到了此功能的添加。 它不会显示在链接中,因为它是库,而不是编译器功能。
没有关于库功能支持的说明,但遗憾的是,它没有说明功能首次出现在哪个版本。

您忘记发布最有价值的信息:错误消息您链接到的页面专门讨论了GCC版本和语言兼容性<代码>原子加载(共享ptr)
是一个库兼容性问题。这一页显然不那么清晰。有可能,尽管可能不明智,在本地使用gcc 4.8或4.9对
/usr/include/c++/5/bits/shared_ptr_atomic.h
进行后端口编译。但我不知道是否有其他语义变化可能会以一种不妨碍编译的方式使其微妙地不兼容
docker run -it gcc:4.9 bash
# create a test.cpp with previous code:
cat > test.cpp << EOF
#include <memory>
#include <atomic>

int main() {
 auto p = std::make_shared<int>(3);
 auto n = std::atomic_load(&p);
}

EOF
# and compile:
g++ -std=c++11 test.cpp -o bla
test.cpp: In function 'int main()':
test.cpp:6:30: error: no matching function for call to 'atomic_load(std::shared_ptr<int>*)'
  auto n = std::atomic_load(&p);
                              ^
test.cpp:6:30: note: candidates are:
In file included from test.cpp:2:0:
/usr/local/include/c++/4.9.3/atomic:906:5: note: template<class _ITp> _ITp std::atomic_load(const std::atomic<_ITp>*)
     atomic_load(const atomic<_ITp>* __a) noexcept
     ^
/usr/local/include/c++/4.9.3/atomic:906:5: note:   template argument deduction/substitution failed:
test.cpp:6:30: note:   'std::shared_ptr<int>' is not derived from 'const std::atomic<_ITp>'
  auto n = std::atomic_load(&p);
                              ^
In file included from test.cpp:2:0:
/usr/local/include/c++/4.9.3/atomic:911:5: note: template<class _ITp> _ITp std::atomic_load(const volatile std::atomic<_ITp>*)
     atomic_load(const volatile atomic<_ITp>* __a) noexcept
     ^
/usr/local/include/c++/4.9.3/atomic:911:5: note:   template argument deduction/substitution failed:
test.cpp:6:30: note:   'std::shared_ptr<int>' is not derived from 'const volatile std::atomic<_ITp>'
  auto n = std::atomic_load(&p);
                              ^