constexpr函数可以包含标签吗? [英] Can a constexpr function contain a label?
本文介绍了constexpr函数可以包含标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此程序:
constexpr void f() { x: ; }
由gcc编译,但clang表示:
is compiled by gcc, but clang says:
error: statement not allowed in constexpr function
那么此代码有效吗?
推荐答案
如 dcl.constexpr#3 说:
As pointed out in a comment by Nathan Pierson, Clang is correct, and the code is ill-formed. According to the current working draft (which includes C++20), dcl.constexpr#3 says:
constexpr函数的定义应满足以下要求:
The definition of a constexpr function shall satisfy the following requirements:
...
其功能主体不得封闭
...
标识符标签
...
...
这篇关于constexpr函数可以包含标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文