https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86993
Bug ID: 86993
Summary: assignment of read-only variable error reported at
wrong location
Product: gcc
Version: 6.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: malcolm.parsons at gmail dot com
Target Milestone: ---
For this C++ code:
int main() {
const int i = 5;
i = 5 + 6;
}
g++ 5.1 reports:
<source>: In function 'int main()':
<source>:3:7: error: assignment of read-only variable 'i'
i = 5 + 6;
^
but g++ 6.1 and later report:
<source>: In function 'int main()':
<source>:3:13: error: assignment of read-only variable 'i'
i = 5 + 6;
^
gcc doesn't have this issue for C code.
See https://godbolt.org/g/Hoojyt and https://godbolt.org/g/WQR5XS