[gcc r17-2275] cobol: add diagnostic for SORT without defined key

"James K. Lowden via Gcc-cvs" <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:e7140c283c74706e75d0e515cd824c7043705234

commit r17-2275-ge7140c283c74706e75d0e515cd824c7043705234
Author: James K. Lowden <[email protected]>
Date:   Wed Jul 8 18:16:27 2026 -0400

    cobol: add diagnostic for SORT without defined key
    
    gcc/cobol/ChangeLog:
    
            PR cobol/126106
            * parse.y: Report error instead of crashing.

Diff:
---
 gcc/cobol/parse.y | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index 22445ed5b4c5..2d9263d983c5 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -9879,6 +9879,10 @@ sort_table:     SORT tableref[table] sort_keys sort_dup sort_seq {
 		    error_msg(@1, "%s has no OCCURS clause", $table->field->name);
                     YYERROR;
 		  }
+		  if( !$table->field->occurs.keys ) {
+		    error_msg(@1, "%s: no key defined", $table->field->name);
+                    YYERROR;
+		  }
                   cbl_key_t
                     key = cbl_key_t($table->field->occurs.keys[0]),
                     guess(1, &$table->field);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.