Can a string literal be subscripted in a constant expression?

前端 未结 2 1571
误落风尘
误落风尘 2020-12-06 05:22

This is valid, because a constexpr expression is allowed to take the value of \"a glvalue of literal type that refers to a non-volatile object defined with cons

相关标签:
2条回答
  • 2020-12-06 05:37

    The intent is that this works and the paragraphs that state when an lvalue to rvalue conversion is valid will be amended with a note that states that an lvalue that refers to a subobject of a string literal is a constant integer object initialized with a constant expression (which is described as one of the allowed cases) in a post-C++11 draft.

    Your comment about the use within the preprocessor looks interesting but I'm unsure whether that is intended to work. I hear about this the first time at all.

    0 讨论(0)
  • 2020-12-06 05:45

    Regarding your question about #if, it was not the intent of the standards committee to increase the set of expressions which can be used in the preprocessor, and the current wording is considered to be a defect. This will be listed as core issue 1436 in the post-Kona WG21 mailing. Thanks for bringing this to our attention!

    0 讨论(0)
提交回复
热议问题