Why can't an incomplete type be casted to void?

后端 未结 2 1895
南旧
南旧 2021-01-19 18:15

Why does the following code give the following error?

Why does the type need to be complete in order to be casted to void?

struct Incomp         


        
2条回答
  •  遇见更好的自我
    2021-01-19 18:31

    I don't see anything prohibiting this, quoting N4140:

    §5.4/4 The conversions performed by

    [...]

    — a static_cast (5.2.9),

    [...]

    can be performed using the cast notation of explicit type conversion.

    §5.2.9/5 Otherwise, the static_cast shall perform one of the conversions listed below. No other conversion shall be performed explicitly using a static_cast.

    §5.2.9/6 Any expression can be explicitly converted to type cv void, in which case it becomes a discarded-value expression (Clause 5). [...]

    It's most likely a bug as tested on Rextester, an online VS2013 compiler, but compiles in rise4fun, Microsoft's online compiler which is bleeding edge.

提交回复
热议问题