]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Initialize regmatch_t portably [PR119217]
authorRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Thu, 8 May 2025 07:29:56 +0000 (09:29 +0200)
committerRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Thu, 8 May 2025 07:29:56 +0000 (09:29 +0200)
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.

2025-04-08  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

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

gcc/cobol/dts.h

index c345dc7e64aba8896fb02627a3f2500c830004f9..dfd7c4c24f71bbdfe1476c63b993ddb0778aae87 100644 (file)
@@ -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;
     }