类模板中文本运算符的友元声明
Friend declaration of literal operator in class template
我正在尝试创建一个只能通过文字运算符构造的类,但它无法在 gcc 上构建。
下面是一个精简的示例:
#include <cstddef>
template<typename C>
class Foo;
Foo<char> operator "" _foo(const char*, std::size_t);
template<typename C>
class Foo
{
Foo() = default;
friend Foo<char> operator "" _foo(const char*, std::size_t);
};
Foo<char> operator "" _foo(const char* str, std::size_t size)
{
return Foo<char>();
}
int main()
{
auto foo = "Foo"_foo;
return 0;
}
它失败并显示以下消息:https://godbolt.org/z/kfcNMR
<source>:11:22: error: 'Foo<char> operator""_foo(const char*, std::size_t)' has invalid argument list
它适用于 clang 和 msvc,如果没有模板,它适用于 gcc:https://godbolt.org/z/exfm5Q
这是编译器错误还是我犯了错误?
这是一个错误,5年前就被报道了。
错误 61648 - g++ 接受非模板的文字运算符友元 类,但不适用于模板类
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61648
相关文章:
- 如何在嵌套类中正确使用友元声明?
- 类模板中文本运算符的友元声明
- 模板和隐式构造函数的类定义之外的友元声明
- 如何将友元声明用于具有约束的模板类
- 模板化友元声明在 G++ 5.4.0 下不起作用 - 编译器错误或错误代码
- 友元声明阻止外部函数访问类的私有部分
- C++:友元声明'声明一个非模板函数
- 友元声明及其表示的实体
- 嵌套类中需要前向声明的友元声明
- 多参数模板不能很好地处理友元声明
- 友元声明和显式模板实例化声明
- 为什么标准禁止部分专门化的友元声明
- is_constructible和is_destructibble不受友元声明的影响
- Pimpl习语和内部对象协作,无需友元声明
- C++中的友元声明-公共和私有之间的区别
- 单个成员而不是整个类的友元声明
- 关于 C++ 中友元声明的基本内容错误
- 有没有办法避免模板友元声明的外部可见性
- 如何解决c++中友元声明的循环依赖
- 指定默认实参的友元声明必须是定义