The dts.h initialization of regmatch_t currently breaks Solaris compilation:

In file included from /vol/gcc/src/hg/master/local/gcc/cobol/lexio.h:208,
                 from /vol/gcc/src/hg/master/local/gcc/cobol/lexio.cc:36:
/vol/gcc/src/hg/master/local/gcc/cobol/dts.h: In constructor 
‘dts::csub_match::csub_match(const char*)’:
/vol/gcc/src/hg/master/local/gcc/cobol/dts.h:36:35: error: invalid conversion 
from ‘int’ to ‘const char*’ [-fpermissive]
   36 |       static regmatch_t empty = { -1, -1 };
      |                                   ^~
      |                                   |
      |                                   int


The problem is that Solaris regmatch_t has additional members before
rm_so and rm_eo, as is always allowed by POSIX.1

typedef struct {
        const char      *rm_sp, *rm_ep; /* Start pointer, end pointer */
        regoff_t        rm_so, rm_eo;   /* Start offset, end offset */
        int             rm_ss, rm_es;   /* Used internally */
} regmatch_t;

so the initialization doesn't do what it's supposed to do.

Fixed by initializing the rm_so and rm_eo members explicitly.

Bootstrapped without regressions on amd64-pc-solaris2.11,
sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu.

Ok for trunk?

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2025-04-08  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

        gcc/cobol:
        PR cobol/119217
        * dts.h (csub_match): Initialize rm_so, rm_eo fields explicitly.

# HG changeset patch
# Parent  6f227ddea0046a0164509bdb8069e96184304054
cobol: Initialize regmatch_t portably [PR119217]

diff --git a/gcc/cobol/dts.h b/gcc/cobol/dts.h
--- a/gcc/cobol/dts.h
+++ b/gcc/cobol/dts.h
@@ -33,7 +33,8 @@ namespace dts {
       : input(input)
       , first(NULL), second(NULL), matched(false)
     {
-      static regmatch_t empty = { -1, -1 };
+      static regmatch_t empty;
+      empty.rm_so = empty.rm_eo = -1;
       regmatch_t& self(*this);
       self = empty;
     }

Reply via email to