On Fri, Apr 11, 2025 at 10:50:25AM +0200, Rainer Orth wrote:
> 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;

Why not static regmatch_t empty = { .rm_so = -1, .rm_eo = -1 };
?
While the FE needs to be valid C++14, the library is GNU++17 (compiled
by the just built GCC and not built with -pedantic*, so can use GCC
extensions or features from C++20 that are known to be implemented there).

Ah, I see dts.h include from the FE.  So that would need to be
#ifndef IN_GCC_FRONTEND
      static const regmatch_t empty = { .rm_so = -1, .rm_eo = -1 };
#else
      regmatch_t empty = {};
      empty.rm_so = empty.rm_eo = -1;
#endif
I don't see the point of makint it static if it needs to be modified
at runtime.
Though, maybe one would get better code generation even without
the static keyword in the first case.

>        regmatch_t& self(*this);
>        self = empty;
>      }


        Jakub

Reply via email to