https://gcc.gnu.org/g:324673c6ef9808daf6daf4f9b9deb1c1d1eb4a7a
commit r17-4735-g324673c6ef9808daf6daf4f9b9deb1c1d1eb4a7a Author: Robert Dubner <[email protected]> Date: Tue Sep 29 00:27:08 2026 -0400 cobol: Remove debugging condition; appease cppcheck. gcc/cobol/ChangeLog: * picture.cc (is_valid_picture): Appease cppcheck. (process_line): Likewise. (process_file): Likewise. (main): Likewise. Likewise. * semantic_token.h (struct lex_picture_t): Likewise. * symbols.cc (expand_picture): Remove obsolete PICTURE workaround. * util.cc (cbl_field_t::encode_numeric): Likewise. libgcobol/ChangeLog: * libgcobol.cc (defined): Remove always-on MATCH_DECLARATIVE debugging condition. (__gg__compare_numdisp_alpha): Appease cppcheck. gcc/testsuite/ChangeLog: * cobol.dg/group2/Compare_numeric-display_to_alphanumeric.cob: New test. * cobol.dg/group2/Compare_numeric-display_to_alphanumeric.out: New test. * cobol.dg/group2/Test_refmod_against_named-conditional.cob: New test. * cobol.dg/group2/Test_refmod_against_named-conditional.out: New test. Diff: --- gcc/cobol/picture.cc | 15 +++++----- gcc/cobol/semantic_token.h | 2 +- gcc/cobol/symbols.cc | 8 ------ gcc/cobol/util.cc | 3 -- .../Compare_numeric-display_to_alphanumeric.cob | 19 +++++++++++++ .../Compare_numeric-display_to_alphanumeric.out | 2 ++ .../Test_refmod_against_named-conditional.cob | 32 ++++++++++++++++++++++ .../Test_refmod_against_named-conditional.out | 4 +++ libgcobol/libgcobol.cc | 4 +-- 9 files changed, 68 insertions(+), 21 deletions(-) diff --git a/gcc/cobol/picture.cc b/gcc/cobol/picture.cc index 28489522fe88..0d7a4cefbe71 100644 --- a/gcc/cobol/picture.cc +++ b/gcc/cobol/picture.cc @@ -305,7 +305,7 @@ namespace picture_validation { matrix[rule.state][ch] = rule.next_state; i++; } - if( nextra ) { + if( nextra ) { // cppcheck-suppress knownConditionTrueFalse cbl_internal_error("%s: %d redundant rules", __func__, nextra); } @@ -396,7 +396,7 @@ namespace picture_validation { return true; } - bool is_boolean() const { return symbol_mask == p_one; } + bool is_boolean() const { return symbol_mask == p_one; } // cppcheck-suppress unusedPrivateFunction bool is_alphabetic() const { return symbol_mask == p_A; } bool is_national() const { return symbol_mask == p_N; } @@ -624,7 +624,7 @@ namespace picture_validation { } } if( prior_ch == '.' && ch == '.' ) return false; - if( ! add_contiguous(ch) ) return false; + if( ! add_contiguous(ch) ) return false; // cppcheck-suppress knownConditionTrueFalse if( ! picsym_settable(ch) ) { return false; } picsym_set(ch); @@ -921,6 +921,7 @@ is_valid_picture(const cbl_loc_t& loc, const char picture[]) { int count = result.first; if( count == 0 ) { dbgmsg("%s: odd zero repeat count for '%s'", __func__, paren); + // cppcheck-suppress unreadVariable constraint.bad_repeat = paren; // pointless, not used return output; } @@ -999,7 +1000,7 @@ process_line( const char picture[], int lineno = 1 ) { assert(picture); unsigned int mask = picture_validation::invalid_e; auto result = is_valid_picture(picture); - if( 0 == (mask & result.second) ) { + if( 0 == (mask & result.second) ) { // cppcheck-suppress knownConditionTrueFalse printf( "valid : %s (%s)\n", picture, picture_validation::state_str(result.second) ); } else { @@ -1008,7 +1009,7 @@ process_line( const char picture[], int lineno = 1 ) { picture, unsigned(p - picture), *p, picture_validation::state_str(result.second), lineno ); } - return result.second & picture_validation::invalid_e; + return result.second & picture_validation::invalid_e; // cppcheck-suppress knownConditionTrueFalse } static bool @@ -1032,7 +1033,7 @@ process_file(const char* filename) { if( p < picture + len ) *p = '\0'; process_line(picture, ++lineno); } - return len != -1; + return len != -1; // cppcheck-suppress knownConditionTrueFalse } int @@ -1053,7 +1054,7 @@ main(int argc, char* argv[]) { } if (picture) { - fOK = process_line(picture) ? 0 : 1; + fOK = process_line(picture) ? 0 : 1; // cppcheck-suppress knownConditionTrueFalse } else { if (optind < argc) { for (int i = optind; i < argc; ++i) { diff --git a/gcc/cobol/semantic_token.h b/gcc/cobol/semantic_token.h index 0fead8c3d35b..145d4f6f35f4 100644 --- a/gcc/cobol/semantic_token.h +++ b/gcc/cobol/semantic_token.h @@ -40,7 +40,7 @@ struct lex_picture_t { cbl_field_data_t *data; // NULL if error bool valid() const { return type != FldInvalid; } - void dump( cbl_name_t input ) const { + void dump( const cbl_name_t input ) const { auto len = strlen(input); int pad = len < 20? 20 - len : 0; fprintf( stderr, "%-20s %s: '%s'%*s @ %u of %u (%s)", diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc index 8a4f08362b08..13fd073c25b5 100644 --- a/gcc/cobol/symbols.cc +++ b/gcc/cobol/symbols.cc @@ -4958,14 +4958,6 @@ expand_picture(const char *picture) { memmove(pV, pV+1, strlen(pV)); } - - // AD HOC FIX for an improper trailing space - char *pspace = strchr(retval, ascii_space); - if( pspace ) - { - *pspace = NULLCH; - } - return retval; } diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index d2d627f7d146..6196671d446f 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -1964,9 +1964,6 @@ cbl_field_t::encode_numeric( const char input[], cbl_loc_t loc ) { // __gg__string_to_numeric_edited operates in ASCII space: char *expanded = expand_picture(data.picture); - // By the time you read this, this next statement ought to be - // obsolete. See RT issue 3682. - expanded[char_capacity()] = '\0'; if( type == FldNumericEdited ) { expand_expanded(expanded); diff --git a/gcc/testsuite/cobol.dg/group2/Compare_numeric-display_to_alphanumeric.cob b/gcc/testsuite/cobol.dg/group2/Compare_numeric-display_to_alphanumeric.cob new file mode 100644 index 000000000000..e57b9af4f285 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/Compare_numeric-display_to_alphanumeric.cob @@ -0,0 +1,19 @@ + *> Do not edit this generated file. See README.txt + *> { dg-do run } + *> { dg-options "-dialect mf" } + *> { dg-output-file "group2/Compare_numeric-display_to_alphanumeric.out" } + identification division. + program-id. prog. + data division. + working-storage section. + 01 zipcode pic 9(5). + 01 zipcodex redefines zipcode pic x(5). + procedure division. + move space to zipcodex + if zipcode equal space + display "space" + else + display "NOT space (BUG!)" end-if + goback. + end program prog. + diff --git a/gcc/testsuite/cobol.dg/group2/Compare_numeric-display_to_alphanumeric.out b/gcc/testsuite/cobol.dg/group2/Compare_numeric-display_to_alphanumeric.out new file mode 100644 index 000000000000..41733eba1e05 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/Compare_numeric-display_to_alphanumeric.out @@ -0,0 +1,2 @@ +space + diff --git a/gcc/testsuite/cobol.dg/group2/Test_refmod_against_named-conditional.cob b/gcc/testsuite/cobol.dg/group2/Test_refmod_against_named-conditional.cob new file mode 100644 index 000000000000..0b4a766027db --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/Test_refmod_against_named-conditional.cob @@ -0,0 +1,32 @@ + *> Do not edit this generated file. See README.txt + *> { dg-do run } + *> { dg-options "-dialect mf" } + *> { dg-output-file "group2/Test_refmod_against_named-conditional.out" } + identification division. + program-id. prog. + environment division. + configuration section. + special-names. + class digit-or-hyphen '0' thru '9' '-'. + data division. + working-storage section. + 01 foo pic x(7) value '123-x45'. + procedure division. + if foo(4:1) is digit-or-hyphen + display "4 is okay" + else + display "4 is bad" + end-if + if foo(5:1) is digit-or-hyphen + display "5 is bad" + else + display "5 is okay" + end-if + if foo(6:1) is digit-or-hyphen + display "6 is okay" + else + display "6 is bad" + end-if + goback. + end program prog. + diff --git a/gcc/testsuite/cobol.dg/group2/Test_refmod_against_named-conditional.out b/gcc/testsuite/cobol.dg/group2/Test_refmod_against_named-conditional.out new file mode 100644 index 000000000000..127b8bdd11c5 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/Test_refmod_against_named-conditional.out @@ -0,0 +1,4 @@ +4 is okay +5 is okay +6 is okay + diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index 2d2100de2cf9..c0924a81a2e7 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -183,7 +183,7 @@ strfromf64 (char *s, size_t n, const char *f, double v) #endif // Enable Declarative tracing via "match_declarative" environment variable. -#if defined(MATCH_DECLARATIVE) || true +#if defined(MATCH_DECLARATIVE) # undef MATCH_DECLARATIVE # define MATCH_DECLARATIVE getenv("match_declarative") #else @@ -14036,7 +14036,7 @@ __gg__compare_numdisp_alpha( cblc_field_t *left, int flags) { // 'left' is numdisp. We MOVE it to an alphanumeric of the correct size. - charmap_t *charmap_left = __gg__get_charmap(left->encoding); + const charmap_t *charmap_left = __gg__get_charmap(left->encoding); size_t left_size = left->capacity; if( left->attr & separate_e ) {
