如果在可变参数模板类的成员函数声明中我将类类型指定为默认模板模板参数,它是有效的 C++ 吗? [重复]

问题描述 投票:0回答:1

简而言之:此代码可以在 clang++ (10.0) 中编译,但不能在 g++ (12.2) 中编译。哪一个是正确的?

template<typename... T>
struct V{
  template<template<typename...> class U=V, typename T2>
  static void foo(T2){}
};

int main(){ 
  V<int>::foo(0);
}
c++ templates variadic-templates
1个回答
0
投票

仅供参考,错误是(使用 gcc 12.2):

<source>:3:42: error: invalid use of type 'V<T>' as a default value for a template template-parameter
    3 |   template<template<typename...> class U=V, typename T2>
      |                                          ^

这里的相关主题是注入类名。来自cppreference

在类模板中,注入的类名称可以用作引用当前模板的模板名称,也可以用作引用当前实例化的类名称。

这一点以及后来的 gcc 版本接受代码的事实暗示了 gcc 中的编译器错误,该错误已在较新版本中修复。

© www.soinside.com 2019 - 2024. All rights reserved.