Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning a value to a constant syntax or semantic error?

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

 int a = 7;
 3 = a;

In standard C++ context-free grammar I found this statement syntactically valid.

like image 687
Abdul Rehman Avatar asked Oct 22 '15 09:10

Abdul Rehman


1 Answers

It is not a syntax error, as the grammar can derive from assignment-expression (5.17) up to integer_literal

It is then a semantic error, as stated in 5.17:

All require a modifiable lvalue as their left operand and return an lvalue referring to the left operand.

lvalue is a semantic concept, not a syntactic one.

like image 128
Jean-Baptiste Yunès Avatar answered Oct 23 '22 12:10

Jean-Baptiste Yunès