Assigning value to constant syntax or semantic error?

Is the second line of code considered as a syntax error or semantic error in C ++?

int a = 7; 3 = a; 

In a standard contextless C ++ grammar, I found this statement syntactically valid.

+7
c ++ compiler-construction syntax-error lvalue
source share
1 answer

This is not a syntax error, since the grammar can be deduced from an assignment expression (5.17) to integer_literal

This is a semantic error, as stated in 5.17:

All require modification of the lvalue as their left operand and return an lvalue referring to the left operand.

lvalue is a semantic concept, not a syntactic one.

+3
source share

All Articles