Why is this constexpr static member function not seen as constexpr when called?

前端 未结 2 1737
猫巷女王i
猫巷女王i 2020-12-11 00:44

Why is this constexpr static member function, identified by the //! Nah comment, not seen as constexpr when called?

2条回答
  •  借酒劲吻你
    2020-12-11 01:22

    [class.mem]/2

    Within the class member-specification, the class is regarded as complete within function bodies, default arguments, exception-specifications, and default member initializers (including such things in nested classes). Otherwise it is regarded as incomplete within its own class member-specification.

    In the initializer of a static data member of a class, the class is incomplete. The initializer can only see the declarations of members which precede it, and any member functions it can see are considered declared but not defined. A call to a function that is declared but not defined can not be a constant expression.

提交回复
热议问题