c++ - 是 GCC 错误吗?

标签 c++ c linux gcc g++

当编译我的项目混合 CC++ 时我得到这个错误(编译 C++ 文件时):

/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++locale.h:
In function ‘int std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)’:
/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++locale.h:70:3:
sorry, unimplemented:
function ‘int std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)’
can never be inlined because it uses variable argument lists

编译结束。

但是当我手动编辑文件时 /usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++locale.h 并删除 __convert_from_v 之前的 inline 修饰符 WORKS

导致问题的函数头最初是 inline:

inline int
__convert_from_v(const __c_locale& __cloc __attribute__ ((__unused__)),
                   char* __out,
                   const int __size __attribute__ ((__unused__)),
                   const char* __fmt, ...)

我想像这样的函数不应该被标记为inline。是bug还是我做错了什么??? [海湾合作委员会 4.6.1,Ubuntu 11.10]

最佳答案

这可能是由于优化设置或 inline 的重新定义导致 __convert_from_v 被内联。这是一个重现错误的小人工示例:

#define inline __always_inline
#include <bits/c++locale.h>

int main () {
  __locale_t loc;
  return std::__convert_from_v(loc, 0, 0, 0);
}

在 Ubuntu 11.10 上使用 g++ 4.6.1 编译出现错误:

/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++locale.h: In function ‘int std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)’:
/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++locale.h:70:3: sorry, unimplemented: function ‘int std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)’ can never be inlined because it uses variable argument lists

因此请检查您的代码以重新定义 inline 或尝试不同的优化设置。

我认为这个函数被标记为 inline 的原因是因为它是在头文件中定义的。如果没有 inline,您将在包含(通常是间接地)此 header 的每个翻译单元中定义它。

关于c++ - 是 GCC 错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8479950/

相关文章:

c++ - 通知 GUI 对象有关屏幕大小的信息 - 设计

c++ - 在 Windows 7 上使用 C++ 程序读取 Windows 注册表

c - C 中的指针数组?

c++ - 游戏的跨平台声音 API?

linux - bash 如何使用 CTRL+C 杀死子进程

c++ - 如何让列表可以隐式转换为我的类对象?

c++ - 观察中心时围绕球体旋转相机(使用四元数)

c - 我的二进制文件以相反的顺序输出

linux - 在 bash 中转换日期格式

linux - linux下使用minicom进行串行usb通信