将一个函数指针转换为const volatile仅在gcc上失败(不是clang或msvc)

时间:2018-06-12 03:07:49

标签: c++ gcc boost clang boost-python

以下代码使用boost-python来创建Python函数回调。它在clang和msvc上编译得很好,但在gcc上却没有。增强版本完全相同。

#include <boost/python.hpp>

typedef void CallbackType();

struct TheStruct {
    CallbackType *theMember;
};

BOOST_PYTHON_MODULE()
{
    boost::python::class_<TheStruct>("TheStruct")
            .def_readwrite("theFunction", &TheStruct::theMember);
}

更简化的版本,没有提升:

template<class T>
void runner(T const volatile*) { } 

int main() {
    void (*varname)();
    runner(varname);
}
clang和msvc很高兴。 gcc告诉我:

test.cpp: In function 'int main()':
test.cpp:6:19: error: no matching function for call to 'runner(void (*&)())'
     runner(varname);
                   ^
test.cpp:2:6: note: candidate: 'template<class T> void runner(const volatile T*)'
 void runner(T const volatile*) { }
      ^~~~~~
test.cpp:2:6: note:   template argument deduction/substitution failed:
test.cpp:6:19: note:   types 'const volatile T' and 'void()' have incompatible cv-qualifiers
     runner(varname);

为什么这会在gcc中失败,我怎么能在将来自己找到这样的文档,怎样才能让它编译?

0 个答案:

没有答案