When is a C ++ expression well formed?

Having configured according to the C ++ standard, I came to the statement in several cases:

Expression X must be well formed.

I told myself: "Well, intuitively, you know what a well-formed expression is, but can you give a formal explanation of what makes a C ++ expression a well-formed expression?"

I searched a bit, and I did not find anything that would give an official explanation on this. So here is my question:

Q: What are the quality characteristics of a well-formed expression in C ++?

+6
source share
2 answers

A well-formed expression must conform to the grammar of the expression (as defined by the standard) and must comply with semantic rules, for example, not to use names that have not been declared, or not to update the name in the same way with a different meaning.

 i = 0 X::i++ 

The expressions above are syntactically valid, but if i not declared or const or X not a namespace or class type, or X::i not declared or X::i does not support post-increment, then they do not satisfy the semantic requirements for a well-formed expression.

Q: What are the quality characteristics of a well-formed expression in C ++?

See paragraphs 1-15. You cannot reduce the whole C ++ language to a simple list.

+4
source

The C ++ standard does not define a correct expression, although it actually uses this phrase. There is a definition of a well-formed program

1.3.26 [defns.well.formed] a well-formed C ++ program built in accordance with syntax rules diagnosed by semantic rules and the Rule of single definition (3.2).

I think we can assume that a well-formed expression is an expression that does not make a program poorly formed (which is defined in 1.3.9 as unformed).

+7
source

Source: https://habr.com/ru/post/973885/


All Articles