gpt4 book ai didi

c++ - C++1y 模式下的 Clang >= 3.3 无法解析 header

转载 作者:IT老高 更新时间:2023-10-28 14:01:25 24 4
gpt4 key购买 nike

我有一个项目可以在 g++ 4.8.1 和 clang >= 3.3 在 c++11 模式下正确编译和运行。但是,当我切换到实验性 -std=c++1y模式,clang 3.3(但不是 g++)阻塞 <cstdio>通过 Boost.Test 间接包含的 header (所以我自己不能轻易更改它)

// /usr/include/c++/4.8/cstdio
#include <stdio.h>

// Get rid of those macros defined in <stdio.h> in lieu of real functions.
// ...
#undef gets
// ...

namespace std
{
// ...
using ::gets; // <-- error with clang++ -std=c++1y
// ...
}

带有以下错误消息:

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cstdio:119:11: error: no member named 'gets' in the global namespace

开启 this tutorial关于如何设置现代 C++ 环境,与 max_align_t 类似的查找问题遇到。建议使用 sed 脚本用 #ifdef __clang__ 包围未知符号。宏,但这似乎是一种脆弱的方法。

设置:带有

的普通 64 位 Linux Mint 15

g++ (Ubuntu 4.8.1-2ubuntu1~13.04) 4.8.1

Ubuntu clang version 3.3-3~raring1 (branches/release_33) (based on LLVM 3.3)

问题:

  • 是什么导致了这个错误?没有__clang__有问题的代码附近的任何地方的宏,并且c++ 11模式下的clang完全没有问题。
  • 这是一个语言问题吗(C++14 是否提到了 C++11 之外的其他关于将 C 兼容符号从全局导入到 std 命名空间的内容)?
  • 我需要更改包含路径的内容吗? (我使用 CMake 自动选择头文件路径,并在 CMakeLists.txt 中切换模式)
  • clang 有解决此问题的开关吗?

最佳答案

gets 手册页中的这条注释看起来很相关:

ISO C11 removes the specification of gets() from the C language, and since version 2.16, glibc header files don't expose the function declaration if the _ISOC11_SOURCE feature test macro is defined.

应该是

#if !_ISOC11_SOURCE
using ::gets;
#endif

关于c++ - C++1y 模式下的 Clang >= 3.3 无法解析 <cstdio> header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17775390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com