Can a constexpr function contain a label?

依然范特西╮ 提交于 2020-12-08 07:10:35

问题


This program:

constexpr void f() { x: ; }

is compiled by gcc, but clang says:

error: statement not allowed in constexpr function

So is this code valid?


回答1:


As pointed out in a comment, clang is correct, and the code is ill-formed. According to the current working draft (which includes C++20), dcl.constexpr#3 says:

The definition of a constexpr function shall satisfy the following requirements:

...

its function-body shall not enclose

...

an identifier label,

...

...



来源:https://stackoverflow.com/questions/64852653/can-a-constexpr-function-contain-a-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!