gcc refuses to compile this admittedly completely useless code: int main(void) { if(0) "hello"[0] = 'H'; return 0; }
with bug.c: In function ‘main’: bug.c:2: error: assignment of read-only location Obviously, this assignment will cause problems if it is ever executed, and a warning is a good idea, but it is allowed in C if it will always be skipped, so it should not be a hard error. This happens with any compiler option I could think to try (including -ansi). I can see this with gcc 4.0.3, gcc 4.1(20060517) and gcc 4.2(20060513). -- Summary: gcc is overly strict in assignment to read-only data Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: truedfx at gentoo dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27676