我维护了一个开源程序,我的一个用户报告说它不会在clang
我以前从未使用过的 . 我得到的错误之一是*Warning: qualifier on function type 'junky_t' (aka 'void (const int &, const int &)') has unspecified behavior.*。我创建了一个演示该问题的小程序:
typedef void junky_t(const int &foo,const int &bar);
class demo {
public:;
const junky_t *junk;
};
这是我尝试编译时发生的情况:
$clang -DHAVE_CONFIG_H -g -g -O3 -Wall -MD -Wpointer-arith -Wshadow -Wwrite-strings -Wcast-align -Wredundant-decls -Wdisabled-optimization -Wfloat-equal -Wmultichar -Wmissing-noreturn -Woverloaded-virtual -Wsign-promo -funit-at-a-time -Weffc++ -D_FORTIFY_SOURCE=2 -MT demo.o -MD -MP -c -o demo.o demo.cpp
demo.cpp:5:5: warning: qualifier on function type 'junky_t' (aka 'void (const int &, const int &)') has unspecified behavior
const junky_t *junk;
^~~~~~~~~~~~~
1 warning generated.
也就是说,类demo
有一个函数指针,指向一个函数,该函数的签名采用许多 const 引用。const
类中的demo
应该防止junk
被更改。但是显然它是模棱两可的,因为可能会考虑函数本身const
,但事实并非如此。我用gcc
or编译它没有问题,llvm
但它不会clang
在 Mac 上编译。我应该怎么办?