You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C++23中FTDecay<int()&>类型是否合法?是编译器Bug吗?

在C++23标准下,FTDecay<int()&>的类型是什么?

给出如下代码示例:

template <class Signature>
struct Decompose;

template <class T>
struct Decompose<void(T)> {
    using Type = T;
};

template <class T>
using FTDecay = typename Decompose<void(T)>::Type;


FTDecay<int()&> x = "Hello";

当前MSVC、Clang和GCC编译最后一行时,都会生成涉及非法类型int (*)() &的错误信息,其中GCC的错误提示为:

error: cannot convert 'const char*' to 'FTDecay<int() &>' {aka 'int (*)() &'}
       in initialization

根据C++标准相关提案(P0172r0)的内容,指向“可憎函数类型”(即带cv/引用限定符的函数类型)的指针或引用属于非法语法(编译器必须诊断),所有主流编译器都会拒绝using X = int (*)() &;这类代码。

内容的提问来源于stack exchange,提问作者Dr. Gut

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 19:52:09