Menu ▾ ▴

#1279 "01 R1 OBJECT REFERENCE." without the optional word USAGE gives "syntax error, unexpected OBJECT"

GC 3.x
open
nobody
None
5 - default
2026-10-30
2026-10-30
No

cobc refuses 01 R1 OBJECT REFERENCE. with a syntax error, although the same declaration written 01 R1 USAGE OBJECT REFERENCE. is accepted. The standard does not require the word USAGE here, so legal source is rejected. A program that declares an object reference without USAGE cannot be compiled at all.

To reproduce

objb.cob (attached):

IDENTIFICATION DIVISION.
PROGRAM-ID. OBJB.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 R1 OBJECT REFERENCE.
PROCEDURE DIVISION.
DISPLAY "OK"
STOP RUN.
cobc -std=cobol2014 -fformat=free -fno-diagnostics-show-caret -x objb.cob

(-fno-diagnostics-show-caret only removes the source-context lines.)

What happens

3.2.0, exit 1:

objb.cob:5: error: syntax error, unexpected OBJECT

3.3-dev r5751 gives the same output, exit 1. Both versions behave the same without -std=cobol2014 (default dialect).

With line 5 written 01 R1 USAGE OBJECT REFERENCE. (saved as obju.cob), cobc -std=cobol2014 -fformat=free -fno-diagnostics-show-caret -x obju.cob compiles on both versions, exit 0, with

obju.cob:5: warning: OBJECTS is not implemented [-Wpending]

(3.2.0 also prints the C compiler's _FORTIFY_SOURCE redefined warning from the Ubuntu build flags), and ./obju prints OK, exit 0.

Under the default dialect (no -std) the USAGE form compiles to the same internal error as #1266, although R1 is never referenced.

3.2.0, cobc -fformat=free -fno-diagnostics-show-caret -x obju.cob, exit 134:

obju.cob:5: warning: OBJECTS is not implemented [-Wpending]
cobc: unexpected category: 0
cobc: tree.c:1606: internal compiler error

cobc: aborting codegen for obju.cob, last statement at line 8 (PROGRAM-ID: OBJU)

cobc: Please report this!
Aborted

3.3-dev r5751, the same command, exit 139:

obju.cob:5: warning: OBJECTS is not implemented [-Wpending]
cobc: unexpected category: 0
cobc: tree.c:1613: internal compiler error

cobc: aborting codegen for obju.cob, last statement at line 8 (PROGRAM-ID: OBJU)

attempt to reference invalid memory address (signal SIGSEGV)

cobc: aborting codegen for obju.cob, last statement at line 8 (PROGRAM-ID: OBJU)
cobc: Please report this!
Segmentation fault

The difference between the two dialects is the defaultbyte setting (init in default.conf, none in cobol2014.conf). cobc -std=cobol2014 -fdefaultbyte=init -fformat=free -x obju.cob aborts the same way on both versions. We mention this only as context; the cause is the one described in #1266.

What should happen

objb.cob compiles and prints OK. ISO/IEC 1989:2023 says (the same USAGE format is in the 2002 and 2014 editions):

  • §13.18.60.2, the USAGE clause general format: [ USAGE IS ] precedes the whole choice of usages, and OBJECT REFERENCE [ interface-name-1 | [ FACTORY OF ] ACTIVE-CLASS | [ FACTORY OF ] object-class-name-1 [ ONLY ] ] is one of them. No syntax rule makes the word USAGE required for OBJECT REFERENCE.
  • §13.18.60.4 general rule 22: "A data item described with a USAGE OBJECT REFERENCE clause is called an object reference. An object reference is a data item of class object and category object-reference." 22 b): "If none of the optional phrases is specified, this data item is called a universal object reference."
  • §13.18.60.3 syntax rule 14: "A USAGE clause with the MESSAGE-TAG, OBJECT REFERENCE, POINTER, FUNCTION-POINTER, or PROGRAM-POINTER phrase may be specified only for an elementary data item at level 1 or ..." R1 is at level 1 in working-storage.

Object references are not an optional element of the standard (Annex A.4.10 lists only multiple inheritance and parametric polymorphism as optional for object orientation). Whatever the state of the object-oriented features, the declaration is accepted when written with USAGE, and should be accepted without it.

Why it happens

In cobc/parser.y, usage_clause had the alternatives _usage_is usage and USAGE _is conflict_usage. OBJECT REFERENCE was the only alternative of conflict_usage, under the comment "tokens that explicit need USAGE _is (because of reduce/reduce conflicts)". So the grammar demanded the word USAGE for it.

Proposed fix

The attached object-orientation-gaps-bugs.patch is against 3.3-dev r5751. It moves the OBJECT REFERENCE alternative, with its action unchanged, into usage, and removes conflict_usage and its usage_clause alternative. The conflict no longer exists: bison 3.8.2 builds the patched grammar under its %expect 0 with no conflict. OBJECT REFERENCE now leaves the USAGE special context the way every other usage in usage does.

With the patch, cobc -std=cobol2014 -fformat=free -fno-diagnostics-show-caret -x objb.cob && ./objb, compile exit 0, run exit 0:

objb.cob:5: warning: OBJECTS is not implemented [-Wpending]
OK

Without -std=cobol2014, objb.cob now compiles as far as obju.cob does and then hits the #1266 internal error shown above (cobc: unexpected category: 0, tree.c:1613, exit 139). That one is not addressed here.

make check on 3.3-dev r5751 with the patch: 1373 behaved as expected, 9 skipped, 0 failed (unpatched: 1372, 9 skipped, 0 failed); the new test 115 passes. The patch adds the test "OBJECT REFERENCE without USAGE" to tests/testsuite.src/syn_definition.at (after "SYNCHRONIZED clause"; OBJECT REFERENCE with and without USAGE, ACTIVE-CLASS and FACTORY OF ACTIVE-CLASS; the unpatched compiler gives "syntax error, unexpected OBJECT" on three of its four entries) and entries to cobc/ChangeLog and tests/ChangeLog.

  • #1266: internal compiler error "unexpected category: 0" for object references.
  • No existing ticket reports the refusal of the declaration without USAGE.

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 re-run 2026-10-30.

2 Attachments

Discussion


Log in to post a comment.