Static templated constexpr nested class member

陌路散爱 提交于 2019-12-01 20:27:04

From n4140

§ 9.2.2 [class.mem] (Emphasis mine)

A class is considered a completely-defined object type (3.9) (or complete type) at the closing } of the class-specifier. Within the class member-specification, the class is regarded as complete within function bodies, default arguments, using-declarations introducing inheriting constructors (12.9), exception-specifications, and brace-or-equal-initializers for non-static data members (including such things in nested classes). Otherwise it is regarded as incomplete within its own class member-specification.

Clang and GCC are correct. The class is not considered complete when you are declaring your static constexpr member, so you cannot construct it. This is why moving the definition of Bar out or removing the static constexpr works (because it is considered complete when defining non-static members)


To clarify, especially considering this question: Static constexpr member of an inner class

The standardese I quoted above basically means that unless otherwise specified a class is regarded incomplete within itself *. A static, constexpr, or static constexpr initializer does not fall under the otherwise specified portion, and therefore we can not use anything declared within the class, which includes a nested class type.

*meaning you can't use it or members of it within the class declaration. The most well known exception to that is within a member function.

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