这是GCC错误吗?

4

当我编译混合了 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 修饰符后,它能够运行

导致问题的函数头原本带有 inline

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

我认为这样的函数不应该标记为inline。这是一个bug还是我做错了什么?[gcc 4.6.1,Ubuntu 11.10]


你是直接包含这个文件吗?完整的错误信息是什么? - Adrian Cornish
4
这是一个在编译较复杂的 C++ 项目时几乎总会使用的文件。很少有可能出现问题,更可能是你的项目和/或编译器调用有误。但如果没有看到一个包含最小自给自足代码示例以及用于编译它的编译器调用,我们就无法确定。 - PlasmaHH
你确定这是一个错误吗?看起来更像是一个警告。 - user1084944
1
使用 g++ -H 命令打印包含栈。 - Adrian Cornish
@James:关于所有涉及输入/输出的内容 - PlasmaHH
显示剩余4条评论
2个回答

7

这可能是由于优化设置或重新定义 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 functionint 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: functionint std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)’ can never be inlined because it uses variable argument lists

请检查您的代码是否重新定义了inline,或尝试不同的优化设置。

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


哦哦哦哦哦...是的!我们有一个宏来将 inline 视为 always_inline。太棒了,非常感谢。 - Cartesius00

0

C99之前的C语言没有inline关键字。请检查您的编译器配置。


他说:“当我编译混合使用C和C++的项目时,我遇到了这个错误。” - ivarec

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接