[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