pre-typedef'ing a variadic-function-pointer 参数

pre-typedef'ing a variadic-function-pointer argument

本文关键字:variadic-function-pointer 参数 ing pre-typedef      更新时间:2023-10-16

我有一个函数foo,它以可变函数指针为参数。

我想在函数声明之前使用"using"来定义参数的类型。

template <typename ... vARGS>
using TFuncType = void(*)(vARGS ... V_args);
template <typename ... vARGS>
void foo(TFuncType<vARGS ...> funcptr) {}
void bar(int i) {}
int main() {
  foo(&bar); // This line fails to compile.
}

这不会编译。错误(通过使用c++1z的clang(是:

/make/proj/test/variadic-funcparam-deduce2.cpp:39:5: error: no matching function for call to 'foo'
foo(&bar);
^~~
/make/proj/test/variadic-funcparam-deduce2.cpp:33:36: note: candidate template ignored: substitution failure [with vARGS = int]
template <typename ... vARGS> void foo(TFuncType<vARGS ...> funcptr) {}

为什么"int"替换失败?

如果我在foo((:中显式写入类型,我可以成功编译

template <typename ... vARGS>
void foo(void(*funcptr)(vARGS ... V_args)) {}

但是,即使明确指定模板参数,并使用预广播的TFuncType<int>作为参数,我也无法使初始("使用"(版本发挥作用,即:

int main() {
  TF_call<int> fptr = &bar; // This line is OK.
  foo<int>(fptr);
}

有人知道上面是什么吗?

使用typedef'd("using"(变量和/或我缺少的函数指针有什么奇怪的地方吗?

我相信这可能与我从这个答案中复制的以下文本有关,该答案本身取自14.5.7[临时别名]第2段中的C++标准:

当模板id指代别名模板的专业化时,它等效于通过替换的类型id中的模板参数的模板参数别名模板[注意:永远不会推导出别名模板名称--结束语]

如果我正确地解释了这一点,那就意味着GCC接受代码实际上是不符合要求的。