首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类/结构中的递归noexcept规范

类/结构中的递归noexcept规范
EN

Stack Overflow用户
提问于 2021-09-06 06:47:04
回答 1查看 84关注 0票数 0

跟进递归无例外规范的问题。如果我在类或结构的作用域中声明函数f,它应该在类/结构范围内随处可见。也是在not (说明符)中(如果它是递归调用的话,应该不重要)。MSVC v19.28和Clang12.0.1接受这个代码并编译这段代码,但是GCC 11.2不接受吗?为什么?是GCC编译器中的错误,还是MSVC和Clang中的错误?

代码语言:javascript
复制
struct S {

    template<typename T>
    static auto f(T && t) noexcept {
        return true;
    }

    template<typename T, typename... Ts>
    static auto f(T && t, Ts && ... ts) noexcept(noexcept(f(ts...))) {
        return f(ts...);
    }

};

int main() {
    S::f(true, 0, 5u);
}

GCC错误信息:

代码语言:javascript
复制
In instantiation of 'static auto S::f(T&&, Ts&& ...) [with T = bool; Ts 
= {int, unsigned int}]':
error: no matching function for call to 'S::f(int&, unsigned int&)'
    static auto f(T && t, Ts && ... ts) noexcept(noexcept(f(ts...))) {
                                                          ~^~~~~~~
note: candidate: 'template<class T> static auto S::f(T&&)'
    static auto f(T && t) noexcept {
                ^
note:   template argument deduction/substitution failed:
note:   candidate expects 1 argument, 2 provided
    static auto f(T && t, Ts && ... ts) noexcept(noexcept(f(ts...))) {
                                                          ~^~~~~~~
EN

回答 1

Stack Overflow用户

发布于 2021-09-07 19:44:40

我相信这是GCC 8中引入的GCC错误。正如你所看到的,当用这里 7.5编译时,所有的东西都编译成功了。

为什么要成功编译?

因为函数模板的专门化的noexcept-specifier只在需要时被实例化。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69070187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档