On Fri, 30 Jan 2026, Torbjörn SVENSSON wrote:

> Ok for trunk and releases/gcc-15?
> 
> --
> 
> When building GCC with host=mingw, the following warning can be seen
> multiple times in the build log if the MinGW GCC version is older than
> r13-4881-g9149a5b7e0a:
> 
> In file included from /build/gcc/c/c-typeck.cc:27:0:
> /build/gcc/system.h:1172:0: warning: "CONST_CAST2" redefined
>  #define CONST_CAST2(TOTYPE,FROMTYPE,X) (const_cast<TOTYPE> (X))
> 
> In file included from 
> /usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/include/c++/x86_64-w64-mingw32/bits/gthr.h:148:0,
>                  from 
> /usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/include/c++/ext/atomicity.h:35,
>                  from 
> /usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/include/c++/memory:73,
>                  from /build/gcc/gcc/system.h:231,
>                  from /build/gcc/gcc/c/c-typeck.cc:27:
> /usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/include/c++/x86_64-w64-mingw32/bits/gthr-default.h:33:0:
>  note: this is the location of the previous definition
>  #define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; 
> TOTYPE _nq;})(X))._nq)
> 
> To ensure that the recent definition is used, always undefine any
> potential define before defining the new macro.

I think it's better if we'd remove CONST_CAST2 the few remaining
uses are all from within C++ code?

Richard.

> gcc/ChangeLog:
> 
>       * system.h: Avoid redefinition of CONST_CAST2 macro.
> 
> Signed-off-by: Torbjörn SVENSSON <[email protected]>
> ---
>  gcc/system.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/gcc/system.h b/gcc/system.h
> index 588e65453f5..c6f76ae9d65 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -1168,6 +1168,7 @@ extern void fancy_abort (const char *, int, const char 
> *)
>     change after the fact).  Beyond these uses, most other cases of
>     using this macro should be viewed with extreme caution.  */
>  
> +#undef CONST_CAST2
>  #ifdef __cplusplus
>  #define CONST_CAST2(TOTYPE,FROMTYPE,X) (const_cast<TOTYPE> (X))
>  #else
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

Reply via email to