Menu ▾ ▴

#1301 PRESENT WHEN on a level-01 report group without a LINE clause generates C that does not compile

unclassified
open
nobody
None
5 - default
2026-11-05
2026-11-05
No

When a report group's level-01 entry has a PRESENT WHEN clause and its LINE clauses are on the subordinate entries, cobc generates C that uses an undeclared rf_N, and the C compiler stops. cobc itself gives no diagnostic about it, also with -Wall.

To reproduce

pw1.cob (attached, free format):

IDENTIFICATION DIVISION.
PROGRAM-ID. PW1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT RPT-FILE ASSIGN TO "pw1.out".
DATA DIVISION.
FILE SECTION.
FD RPT-FILE REPORT IS RPT.
WORKING-STORAGE SECTION.
01 AMT PIC 9(4) VALUE 0.
REPORT SECTION.
RD RPT.
01 DET TYPE IS DETAIL PRESENT WHEN AMT > 0.
   05 LINE PLUS 1.
      10 COLUMN 1 PIC 9(4) SOURCE AMT.
PROCEDURE DIVISION.
    OPEN OUTPUT RPT-FILE
    INITIATE RPT
    MOVE 0 TO AMT
    GENERATE DET
    MOVE 5 TO AMT
    GENERATE DET
    TERMINATE RPT
    CLOSE RPT-FILE
    DISPLAY "DONE"
    STOP RUN.
cobc -x -free pw1.cob && ./pw1 && cat pw1.out

What happens

3.3-dev r5751 stops with

/tmp/cob1000_694752_0.c: In function ‘PW1_’:
/tmp/cob1000_694752_0.c:124:9: error: ‘rf_20’ undeclared (first use in this function); did you mean ‘rl_20’?
  124 |         rf_20.suppress = 0;
      |         ^~~~~
      |         rl_20
/tmp/cob1000_694752_0.c:124:9: note: each undeclared identifier is reported only once for each function it appears in

and 3.2.0 with the same error. pw2.cob (a PAGE HEADING) and pw3.cob (a CONTROL FOOTING FINAL), attached, fail the same way, with or without -std=cobol2014; each compiles if the LINE clause is moved onto the level-01 entry.

What should happen

The program compiles, the first GENERATE prints nothing, and pw1.out holds 0005. PRESENT WHEN may be written in a level-01 report group description entry (ISO/IEC 1989:2023 13.15.2; 13.15.3 forbids it only together with GROUP INDICATE), and when its condition is false, 13.18.41.4 general rule 2 b) says: "Furthermore, if the entry is a level-01 entry, the effect on processing is as though the entire report group description were omitted." The same in 2002 and in the 2014 FCD.

Why it happens

In cobc/codegen.c, output_if writes the PRESENT WHEN test to rl_N.suppress (the report line) only for an entry with COB_REPORT_LINE, otherwise to rf_N.suppress (a report field). But finalize_report (cobc/tree.c) makes every level-01 entry a report line, so this group has an rl_N and no rf_N. Behind that, report_line_type and report_line_and in libcob/reportio.c print a line's child lines without checking its suppress flag, so a heading or footing still prints.

Proposed fix

The attached patch (against 3.3-dev r5751) has output_if use rl_N for a level-01 entry too, and has report_line_type and report_line_and skip the child lines of a suppressed line (only a level-01 entry without LINE has any). With it, pw1.out holds 0005, pw2 prints its heading only on the second page, and pw3 prints no footing, each identical to its LINE-on-01 spelling.

The libcob change also makes SUPPRESS PRINTING take effect for such a group when it is a report heading, a page heading, the first control heading, a control footing final or a report footing; each printed before, in programs already compiled too. pw4.cob, attached, printed CH A and now does not, like its LINE-on-01 spelling.

It adds the testsuite case "PRESENT WHEN on level 01 without LINE" to run_reportwriter.at (a DETAIL, a PAGE HEADING and a CONTROL FOOTING FINAL) and ChangeLog entries. make check: 1373 expected, 9 skipped, 0 failed (1372 unpatched); the new test fails without the patch.

PRESENT WHEN on a group between the level-01 entry and its LINE entries still fails; there the lines are lost even without it, a separate problem.

bugs #713 had PRESENT WHEN on a 02 LINE entry, which compiles; it was closed invalid.

Details

GnuCOBOL 3.2.0 (Ubuntu gnucobol3 3.2-4build1) and 3.3-dev r5751 (CI snapshot 3.3-dev.138 of 2026-10-29), x86_64 Linux, both run 2026-11-04.

5 Attachments

Discussion


Log in to post a comment.