[gcc r15-8940] libgcobol: Use auto for container iterator types

2025-03-26 Thread James K. Lowden via Gcc-cvs
https://gcc.gnu.org/g:96b048329c828d29ab5e3ac67da6bdc841eb608b

commit r15-8940-g96b048329c828d29ab5e3ac67da6bdc841eb608b
Author: Jonathan Wakely 
Date:   Tue Mar 18 21:21:28 2025 +

libgcobol: Use auto for container iterator types

libgcobol/ChangeLog:

* charmaps.cc (__gg__raw_to_ascii): Use auto for complicated
nested type.
(__gg__raw_to_ebcdic): Likewise.
(__gg__console_to_ascii): Likewise.
(__gg__console_to_ebcdic): Likewise.

Diff:
---
 libgcobol/charmaps.cc | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/libgcobol/charmaps.cc b/libgcobol/charmaps.cc
index 6a7975030df0..f990e0ff6984 100644
--- a/libgcobol/charmaps.cc
+++ b/libgcobol/charmaps.cc
@@ -439,8 +439,7 @@ __gg__raw_to_ascii(char **dest, size_t *dest_size, const 
char *in, size_t length
 
 // Check for that unicode code point in the subset of characters we
 // know about:
-std::unordered_map::const_iterator it =
-utf8_to_cp1252_values.find(unicode_point);
+auto it = utf8_to_cp1252_values.find(unicode_point);
 if( it == utf8_to_cp1252_values.end() )
 {
 // That unicode character isn't in our list
@@ -501,8 +500,7 @@ __gg__raw_to_ebcdic(char **dest, size_t *dest_size, const 
char *in, size_t lengt
 position );
 // Check for that unicode code point in the subset of characters we
 // know about:
-std::unordered_map::const_iterator it =
-utf8_to_cp1252_values.find(unicode_point);
+auto it = utf8_to_cp1252_values.find(unicode_point);
 if( it == utf8_to_cp1252_values.end() )
 {
 // That unicode character isn't in our list
@@ -769,8 +767,7 @@ void __gg__console_to_ascii(char * const str, size_t length)
 {
 // Check for that unicode code point in the subset of characters we
 // know about:
-std::unordered_map::const_iterator 
it
-= utf8_to_cp1252_values.find(unicode_point);
+auto it = utf8_to_cp1252_values.find(unicode_point);
 if( it == utf8_to_cp1252_values.end() )
 {
 // That unicode character isn't in our list
@@ -810,8 +807,7 @@ __gg__console_to_ebcdic(char * const str, size_t length)
 {
 // Check for that unicode code point in the subset of characters we
 // know about:
-std::unordered_map::const_iterator 
it
-= utf8_to_cp1252_values.find(unicode_point);
+auto it = utf8_to_cp1252_values.find(unicode_point);
 if( it == utf8_to_cp1252_values.end() )
 {
 // That unicode character isn't in our list


[gcc r15-8939] libgcobol: Fix uses of tolower and toupper with std::transform

2025-03-26 Thread James K. Lowden via Gcc-cvs
https://gcc.gnu.org/g:e2c93a07d739034e5375e69da38091efc87d56e9

commit r15-8939-ge2c93a07d739034e5375e69da38091efc87d56e9
Author: Jonathan Wakely 
Date:   Tue Mar 18 21:17:03 2025 +

libgcobol: Fix uses of tolower and toupper with std::transform

As explained in the libstdc++ manual[1] and elsewhere[2], using tolower
and toupper in std::transform directly is wrong. If char is signed then
non-ASCII characters with negative values lead to undefined behaviour.
Also, tolower and toupper are overloaded names in C++ so expecting them
to resolve to a unique function pointer is unreliable. Finally, the
 header was included, not , so they should have been
qualified as std::tolower and std::toupper.

[1] 
https://gcc.gnu.org/onlinedocs/libstdc++/manual/strings.html#strings.string.simple
[2] https://en.cppreference.com/w/cpp/string/byte/tolower

libgcobol/ChangeLog:

* intrinsic.cc (is_zulu_format): Qualify toupper and cast
argument to unsigned char.
(fill_cobol_tm): Likewise.
(iscasematch): Likewise for to lower.
(numval): Qualify calls to tolower.
(__gg__lower_case): Use lambda expression for
tolower call.
(__gg__upper_case): Likewise for toupper call.
* libgcobol.cc (mangler_core): Cast tolower argument to unsigned
char.
* valconv.cc (__gg__string_to_numeric_edited): Cast to upper
arguments to unsigned char.

Diff:
---
 libgcobol/intrinsic.cc | 28 +++-
 libgcobol/libgcobol.cc |  2 +-
 libgcobol/valconv.cc   |  4 ++--
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/libgcobol/intrinsic.cc b/libgcobol/intrinsic.cc
index e3d255a29d61..345d3ac73527 100644
--- a/libgcobol/intrinsic.cc
+++ b/libgcobol/intrinsic.cc
@@ -99,7 +99,7 @@ is_zulu_format(PCHAR left, PCHAR &right)
   bool retval = false;
   if( right > left )
 {
-retval = toupper(*(right-1)) == internal_Z;
+retval = std::toupper((unsigned char)*(right-1)) == internal_Z;
 }
   return retval;
   }
@@ -1984,7 +1984,8 @@ __gg__lower_case( cblc_field_t *dest,
   memset(dest->data, internal_space, dest_length);
   memcpy(dest->data, input->data+input_offset, std::min(dest_length, 
source_length));
   internal_to_ascii((char *)dest->data, dest_length);
-  std::transform(dest->data, dest->data + dest_length, dest->data, tolower);
+  std::transform(dest->data, dest->data + dest_length, dest->data,
+[](unsigned char c) { return std::tolower(c); });
   ascii_to_internal_str((char *)dest->data, dest_length);
   }
 
@@ -2431,7 +2432,7 @@ numval( cblc_field_t *dest,
   state = SPACE4;
   break;
   }
-if( tolower(ch) == 'd' )
+if( std::tolower(ch) == 'd' )
   {
   if( leading_sign )
 {
@@ -2439,7 +2440,7 @@ numval( cblc_field_t *dest,
 }
   ch = *p++;
   errpos += 1;
-  if( p > pend || tolower(ch) != 'b' )
+  if( p > pend || std::tolower(ch) != 'b' )
 {
 goto done;
 }
@@ -2447,7 +2448,7 @@ numval( cblc_field_t *dest,
   state = SPACE4;
   break;
   }
-if( tolower(ch) == 'c' )
+if( std::tolower(ch) == 'c' )
   {
   if( leading_sign )
 {
@@ -2455,7 +2456,7 @@ numval( cblc_field_t *dest,
 }
   ch = *p++;
   errpos += 1;
-  if( p > pend || tolower(ch) != 'r' )
+  if( p > pend || std::tolower(ch) != 'r' )
 {
 goto done;
 }
@@ -2494,7 +2495,7 @@ numval( cblc_field_t *dest,
   state = SPACE4;
   break;
   }
-if( tolower(ch) == 'd' )
+if( std::tolower(ch) == 'd' )
   {
   if( leading_sign )
 {
@@ -2502,7 +2503,7 @@ numval( cblc_field_t *dest,
 }
   ch = *p++;
   errpos += 1;
-  if( p > pend || tolower(ch) != 'b' )
+  if( p > pend || std::tolower(ch) != 'b' )
 {
 goto done;
 }
@@ -2510,7 +2511,7 @@ numval( cblc_field_t *dest,
   state = SPACE4;
   break;
   }
-if( tolower(ch) == 'c' )
+if( std::tolower(ch) == 'c' )
   {
   if( leading_sign )
 {
@@ -2518,7 +2519,7 @@ numval( cblc_field_t *dest,
 }
   ch = *p++;
   errpos += 1;
-  if( p > pend || tolower(ch) != 'r' )
+  if( p > pend || std::tolower(ch) != 'r' )
 {
 goto done;
 }
@@ -3736,7 +3737,8 @@ __gg__upper_case( cblc_field_t *dest,
   memset(dest->data, internal_space, dest_length);
   memcpy(dest->data, input->data+input_offset, std::min(dest_length, 
source_length));
   internal_to_ascii((char *)dest->data, dest_length);
-  std::transform(dest->data, dest->data + dest_lengt

[gcc r15-8941] cobol: Replace quadratic loop removing std::set elements

2025-03-26 Thread James K. Lowden via Gcc-cvs
https://gcc.gnu.org/g:57d711ba58f8a69dce22b2a543d8e6c668680865

commit r15-8941-g57d711ba58f8a69dce22b2a543d8e6c668680865
Author: Jonathan Wakely 
Date:   Wed Mar 19 20:33:36 2025 +

cobol: Replace quadratic loop removing std::set elements

There's no need to keep using std::find_if from the beginning of the
container after every removal, just update the iterator after erasing an
element.

This is how C++20 std::erase_if is implemented.

gcc/cobol/ChangeLog:

* except.cc (cbl_enabled_exceptions_t::turn_on_off): Replace
quadratic loop with a single pass.

Diff:
---
 gcc/cobol/except.cc | 32 ++--
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/gcc/cobol/except.cc b/gcc/cobol/except.cc
index ba49f78d897f..1485a337ab93 100644
--- a/gcc/cobol/except.cc
+++ b/gcc/cobol/except.cc
@@ -115,31 +115,27 @@ cbl_enabled_exceptions_t::turn_on_off( bool enabled,
 return true;
   }
 
-  /*
-   * std::remove_if cannot be used with std::set because its elements are 
const.
-   * std::set::erase_if became available only in C++20.
-   */
+  // std::set::erase_if became available only in C++20.
   if( enabled ) { // remove any disabled
 if( files.empty() ) {
   auto p = begin();
-  while( end() != (p = std::find_if( begin(), end(),
- [ec = type]( const auto& elem ) {
-   return
- !elem.enabled &&
- ec_cmp(ec, elem.ec); } )) ) {
-erase(p);
+  while( p != end() ) {
+   if( !p->enabled && ec_cmp(type, p->ec) ) {
+ p = erase(p);
+   } else {
+ ++p;
+   }
   }
 } else {
   for( size_t file: files ) {
 auto p = begin();
-while( end() != (p = std::find_if( begin(), end(),
-   [ec = type, file]( const auto& elem 
) {
- return
-   !elem.enabled &&
-   file == elem.file &&
-   ec_cmp(ec, elem.ec); } )) ) {
-  erase(p);
-}
+while( p != end() ) {
+ if( !p->enabled && file == p->file && ec_cmp(type, p->ec) ) {
+   p = erase(p);
+ } else {
+   ++p;
+ }
+   }
   }
 }
 auto elem = cbl_enabled_exception_t(enabled, location, type);


[gcc r15-8938] libgcobol: Simplify assignment operator by defaulting it

2025-03-26 Thread James K. Lowden via Gcc-cvs
https://gcc.gnu.org/g:b1a58dcb238c5a48e24f226c89287595ef7a9225

commit r15-8938-gb1a58dcb238c5a48e24f226c89287595ef7a9225
Author: Jonathan Wakely 
Date:   Tue Mar 18 21:16:46 2025 +

libgcobol: Simplify assignment operator by defaulting it

libgcobol/ChangeLog:

* common-defs.h (cbl_enabled_exceptions_t::operator=): Define as
defaulted.

Diff:
---
 libgcobol/common-defs.h | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libgcobol/common-defs.h b/libgcobol/common-defs.h
index d052f58b6dff..d2138770470a 100644
--- a/libgcobol/common-defs.h
+++ b/libgcobol/common-defs.h
@@ -444,11 +444,7 @@ class cbl_enabled_exceptions_t : protected 
std::set
   bool   empty() const { return std::set::empty(); }
   size_t  size() const { return std::set::size(); }
 
-  cbl_enabled_exceptions_t& operator=( const cbl_enabled_exceptions_t& that ) {
-std::set& self(*this);
-self = that;
-return *this;
-  }
+  cbl_enabled_exceptions_t& operator=( const cbl_enabled_exceptions_t& ) = 
default;
 };
 
 extern cbl_enabled_exceptions_t enabled_exceptions;


[gcc r15-8688] MAINTAINERS: Add myself

2025-03-28 Thread James K. Lowden via Gcc-cvs
https://gcc.gnu.org/g:eda74cd05447475d385b8a8216e3412da96a46da

commit r15-8688-geda74cd05447475d385b8a8216e3412da96a46da
Author: James K. Lowden 
Date:   Sun Mar 23 16:24:36 2025 -0400

MAINTAINERS: Add myself

ChangeLog:

* MAINTAINERS: Add myself.

Diff:
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 5b3fe407860f..90c8e2aa9950 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -163,6 +163,7 @@ Ada front end   Eric Botcazou   

 Ada front end   Marc Poulhiès   
 Ada front end   Pierre-Marie de Rodat   
 COBOL front end Robert Dubner   
+COBOL front end James K. Lowden 
 c++ Jason Merrill   
 c++ Nathan Sidwell  
 D front end Iain Buclaw 


[gcc r16-1396] cobol: Variety of small changes in answer to cppcheck diagnostics.

2025-06-10 Thread James K. Lowden via Gcc-cvs
https://gcc.gnu.org/g:70c3dd9a81cdefcaf24a66ec0c1ceddf5d3984dd

commit r16-1396-g70c3dd9a81cdefcaf24a66ec0c1ceddf5d3984dd
Author: James K. Lowden 
Date:   Tue Jun 10 10:34:28 2025 -0400

cobol: Variety of small changes in answer to cppcheck diagnostics.

Remove non-ASCII input and blank lines from gcobol.1. Restrict
cobol.clean target to compiler object files.

gcc/cobol/ChangeLog:

* Make-lang.in: cobol.clean does not remove libgcobol files.
* cdf.y: Suppress 1 cppcheck false positive.
* cdfval.h (scanner_parsing):  Partial via cppcheck for PR119324.
* gcobol.1: Fix groff errors.
* gcobolspec.cc (append_arg): Const parameter.
* parse_ante.h (intrinsic_call_2): Avoid NULL dereference.

Diff:
---
 gcc/cobol/Make-lang.in  |  3 +--
 gcc/cobol/cdf.y |  1 +
 gcc/cobol/cdfval.h  |  8 
 gcc/cobol/gcobol.1  | 12 +---
 gcc/cobol/gcobolspec.cc |  2 +-
 gcc/cobol/parse_ante.h  |  2 +-
 6 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in
index 993e4c6ffb02..5f293e1f9874 100644
--- a/gcc/cobol/Make-lang.in
+++ b/gcc/cobol/Make-lang.in
@@ -351,8 +351,7 @@ cobol.srcman:
 cobol.mostlyclean:
 
 cobol.clean:
-   rm -fr gcobol cobol1 cobol/*\
-   ../*/libgcobol/*
+   rm -fr gcobol cobol1 cobol/*
 
 cobol.distclean:
 
diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y
index 0440d0216af9..e4d2feaaf52e 100644
--- a/gcc/cobol/cdf.y
+++ b/gcc/cobol/cdf.y
@@ -891,6 +891,7 @@ verify_integer( const YDFLTYPE& loc, const cdfval_base_t& 
val ) {
   return true;
 }
 
+// cppcheck-suppress returnTempReference
 const cdfval_base_t&
 cdfval_base_t::operator()( const YDFLTYPE& loc ) {
   static cdfval_t zero(0);
diff --git a/gcc/cobol/cdfval.h b/gcc/cobol/cdfval.h
index 09c21ab08e50..c4387b080661 100644
--- a/gcc/cobol/cdfval.h
+++ b/gcc/cobol/cdfval.h
@@ -38,6 +38,14 @@
 
 bool scanner_parsing();
 
+/* cdfval_base_t has no constructor because otherwise: 
+ * cobol/cdf.h:172:7: note: ‘YDFSTYPE::YDFSTYPE()’ is implicitly deleted 
+ *  because the default definition would be ill-formed:
+ * 172 | union YDFSTYPE
+ * 
+ * We use the derived type cdfval_t, which can be properly constructed and
+ * operated on, but tell Bison only about its POD base class.
+ */
 struct YDFLTYPE;
 struct cdfval_base_t {
   bool off;
diff --git a/gcc/cobol/gcobol.1 b/gcc/cobol/gcobol.1
index 0ce890e97229..6db54009fcf7 100644
--- a/gcc/cobol/gcobol.1
+++ b/gcc/cobol/gcobol.1
@@ -39,7 +39,7 @@ compiles \*[lang] source code to object code, and optionally 
produces an
 executable binary or shared object.  As a GCC component, it accepts
 all options that affect code-generation and linking.  Options specific
 to \*[lang] are listed below.
-.Bl -tag -width \0\0debug
+.Bl -tag -width "\0\0debug"
 .It Fl main Ar filename
 .Nm
 will generate a
@@ -197,14 +197,12 @@ Otherwise, columns 1-6 are examined. If those characters 
are all digits
 or blanks, the file is assumed to be in
 .Em "fixed-form reference format",
 also with the indicator in column 7.
-
 If not auto-detected as 
 .Em "fixed-form reference format" 
 or 
 .Em "extended source format",
 the file is assumed to be in 
 .Em "free-form reference format".
-
 .Pp
 .
 .It Fl fcobol-exceptions Ar exception Op Ns , Ns Ar exception Ns ...
@@ -1088,7 +1086,7 @@ the directive must appear before
 .Pp
 To test a feature-set variable, use
 .Dl >>IF Ar feature Li DEFINED
-..
+.
 .Ss Copybooks
 .Nm
 supports the CDF
@@ -1294,7 +1292,7 @@ stores and converts
 numbers.  Converting the floating-point value to the numeric display
 value 0055110 is done by multiplying 55.10...\& by 1,000 and then
 truncating the result to an integer.  And it turns out that even
-though 55.11 can’t be represented in floating-point as an exact value,
+though 55.11 can't be represented in floating-point as an exact value,
 the product of the multiplication, 55110, is an exact value.
 .Pp
 In cases where it is important for conversions to have predictable
@@ -1325,7 +1323,7 @@ specified for a calculation, then the intermediate result 
becomes a
 .
 .Ss A warning about binary floating point comparison
 The cardinal rule when doing comparisons involving floating-point
-values: Never, ever, test for equality.  It’s just not worth the hassle.
+values: Never, ever, test for equality.  It's just not worth the hassle.
 .Pp
 For example:
 .Bd -literal
@@ -1361,7 +1359,7 @@ and you really test the code.  And then avoid it anyway.
 .Pp
 Finally, it is observably the case that the
 .Nm
-implementations of floating-point conversions and comparisons don’t
+implementations of floating-point conversions and comparisons don't
 precisely match the behavior of other \*[lang] compilers.
 .Pp
 You have been warned.
diff --git a/gcc/cobol/gcobolspec.cc b/gcc/cobol/gcobolspec.cc
index d1ffc97f8ca5..70784d7e3570 100644
--- a/gcc/cobol/gcobolspec.cc
+++ b/gcc/cobol/