The following example code compiled on 3.1, but does not on 3.2 anymore, resulting in the error "REDEFINES must follow the original definition".
01 WS.
05 A PIC X.
05 A REDEFINES A PIC X.
05 FILLER PIC X.
While the example looks like it should not compile because one has effectively defined an unreachable variable A (since even a fully qualified name would be ambiguous, e.g. A in WS), such a situation can arise when using copybooks with the REPLACING phrase, as an example:
COPYBOOK.cpy:
05 PREFIX1-A PIC X.
05 PREFIX2-A REDEFINES PREFIX1-A PIC X.
TESTPGM.cbl:
01 WS.
COPY 'COPYBOOK' REPLACING ==PREFIX1-A== BY ==A==
==PREFIX2-A== BY ==A==.
05 FILLER PIC X.
The FILLER in the examples is only used to trigger the error, because the code which would otherwise raise the error directly accesses f->redefines->sister which would otherwise be NULL (field.c:1322). The attached patch prevents the redefining variable from finding itself as a redefinition target, because otherwise with f = 05 A REDEFINES A ... f == f.redefines would be true.
Thank you for raising this issue. I can confirm that older versions did not raise even a warning by default here (you only get the
-Wredefinitionon explicit request) and that this is also valid COBOL "per standard" - as long as you don't try to accessA, everything should be fine.Your fix is also fine - applied with swapping the order, ChangeLog entry and changelog in [r5036].
Related
Commit: [r5036]