mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH v2] prevent from redefining __STDC_UTF_{16,32}__ macros
@ 2024-01-25 14:14 Jules Maselbas
  2024-02-26  2:17 ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Jules Maselbas @ 2024-01-25 14:14 UTC (permalink / raw)
  To: musl; +Cc: Jules Maselbas

Undefine any previous __STDC_UTF_{16,32}__ macros before defining
them to prenvent any warnings of redefining macros.

---
v2:
 - changed `#if !define(...)` guard to `#undef`, as suggested by Rich Felker

I encountered this "issue" trying to compile a program with the -isystem
option to override toolchain/installed musl headers with one from source.

 include/stdc-predef.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/stdc-predef.h b/include/stdc-predef.h
index af1a2799..5ccd884d 100644
--- a/include/stdc-predef.h
+++ b/include/stdc-predef.h
@@ -7,7 +7,10 @@
 #define __STDC_IEC_559__ 1
 #endif
 
+#undef __STDC_UTF_16__
 #define __STDC_UTF_16__ 1
+
+#undef __STDC_UTF_32__
 #define __STDC_UTF_32__ 1
 
 #endif
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] [PATCH v2] prevent from redefining __STDC_UTF_{16,32}__ macros
  2024-01-25 14:14 [musl] [PATCH v2] prevent from redefining __STDC_UTF_{16,32}__ macros Jules Maselbas
@ 2024-02-26  2:17 ` Rich Felker
  2024-02-26  3:47   ` Gabriel Ravier
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2024-02-26  2:17 UTC (permalink / raw)
  To: Jules Maselbas; +Cc: musl

On Thu, Jan 25, 2024 at 03:14:40PM +0100, Jules Maselbas wrote:
> Undefine any previous __STDC_UTF_{16,32}__ macros before defining
> them to prenvent any warnings of redefining macros.
> 
> ---
> v2:
>  - changed `#if !define(...)` guard to `#undef`, as suggested by Rich Felker
> 
> I encountered this "issue" trying to compile a program with the -isystem
> option to override toolchain/installed musl headers with one from source.
> 
>  include/stdc-predef.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/include/stdc-predef.h b/include/stdc-predef.h
> index af1a2799..5ccd884d 100644
> --- a/include/stdc-predef.h
> +++ b/include/stdc-predef.h
> @@ -7,7 +7,10 @@
>  #define __STDC_IEC_559__ 1
>  #endif
>  
> +#undef __STDC_UTF_16__
>  #define __STDC_UTF_16__ 1
> +
> +#undef __STDC_UTF_32__
>  #define __STDC_UTF_32__ 1
>  
>  #endif
> -- 
> 2.43.0

I merged this, but now gcc warns about undefining them if system
header warnings aren't suppressed. I'm not sure what the justification
is for that... *sigh*

Rich

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] [PATCH v2] prevent from redefining __STDC_UTF_{16,32}__ macros
  2024-02-26  2:17 ` Rich Felker
@ 2024-02-26  3:47   ` Gabriel Ravier
  2024-02-26  7:14     ` Jens Gustedt
  0 siblings, 1 reply; 5+ messages in thread
From: Gabriel Ravier @ 2024-02-26  3:47 UTC (permalink / raw)
  To: musl, Rich Felker, Jules Maselbas

On 2/26/24 02:17, Rich Felker wrote:
> On Thu, Jan 25, 2024 at 03:14:40PM +0100, Jules Maselbas wrote:
>> Undefine any previous __STDC_UTF_{16,32}__ macros before defining
>> them to prenvent any warnings of redefining macros.
>>
>> ---
>> v2:
>>   - changed `#if !define(...)` guard to `#undef`, as suggested by Rich Felker
>>
>> I encountered this "issue" trying to compile a program with the -isystem
>> option to override toolchain/installed musl headers with one from source.
>>
>>   include/stdc-predef.h | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/include/stdc-predef.h b/include/stdc-predef.h
>> index af1a2799..5ccd884d 100644
>> --- a/include/stdc-predef.h
>> +++ b/include/stdc-predef.h
>> @@ -7,7 +7,10 @@
>>   #define __STDC_IEC_559__ 1
>>   #endif
>>   
>> +#undef __STDC_UTF_16__
>>   #define __STDC_UTF_16__ 1
>> +
>> +#undef __STDC_UTF_32__
>>   #define __STDC_UTF_32__ 1
>>   
>>   #endif
>> -- 
>> 2.43.0
> I merged this, but now gcc warns about undefining them if system
> header warnings aren't suppressed. I'm not sure what the justification
> is for that... *sigh*
>
> Rich

It appears as though since 2001 GCC makes it so that any redefinition or 
undefinition of any macro with a name starting with "__STDC_" (with 
hard-coded exceptions for __STDC_FORMAT_MACROS, __STDC_LIMIT_MACROS and 
__STDC_CONSTANT_MACROS) always results in a warning (from reading the 
code this doesn't seem to be tied to any -W switch, so it's simply 
entirely impossible to work around)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] [PATCH v2] prevent from redefining __STDC_UTF_{16,32}__ macros
  2024-02-26  3:47   ` Gabriel Ravier
@ 2024-02-26  7:14     ` Jens Gustedt
  2024-02-26 14:36       ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Jens Gustedt @ 2024-02-26  7:14 UTC (permalink / raw)
  To: musl, Gabriel Ravier, Rich Felker, Jules Maselbas

Hi

Am 26. Februar 2024 04:47:22 MEZ schrieb Gabriel Ravier <gabravier@gmail.com>:
> On 2/26/24 02:17, Rich Felker wrote:
> > On Thu, Jan 25, 2024 at 03:14:40PM +0100, Jules Maselbas wrote:
> >> Undefine any previous __STDC_UTF_{16,32}__ macros before defining
> >> them to prenvent any warnings of redefining macros.
> >> 
> >> ---
> >> v2:
> >>   - changed `#if !define(...)` guard to `#undef`, as suggested by Rich Felker
> >> 
> >> I encountered this "issue" trying to compile a program with the -isystem
> >> option to override toolchain/installed musl headers with one from source.
> >> 
> >>   include/stdc-predef.h | 3 +++
> >>   1 file changed, 3 insertions(+)
> >> 
> >> diff --git a/include/stdc-predef.h b/include/stdc-predef.h
> >> index af1a2799..5ccd884d 100644
> >> --- a/include/stdc-predef.h
> >> +++ b/include/stdc-predef.h
> >> @@ -7,7 +7,10 @@
> >>   #define __STDC_IEC_559__ 1
> >>   #endif
> >>   +#undef __STDC_UTF_16__
> >>   #define __STDC_UTF_16__ 1
> >> +
> >> +#undef __STDC_UTF_32__
> >>   #define __STDC_UTF_32__ 1
> >>     #endif
> >> -- 
> >> 2.43.0
> > I merged this, but now gcc warns about undefining them if system
> > header warnings aren't suppressed. I'm not sure what the justification
> > is for that... *sigh*
> > 
> > Rich
> 
> It appears as though since 2001 GCC makes it so that any redefinition or undefinition of any macro with a name starting with "__STDC_" (with hard-coded exceptions for __STDC_FORMAT_MACROS, __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS) always results in a warning (from reading the code this doesn't seem to be tied to any -W switch, so it's simply entirely impossible to work around)
> 

The way to go would be to #ifdef them, not to use #undef. 
These are really a language feature and not library, so anything that this should do is repair work for older compilers.  The compiler's setting, if any, should prime over the C library. 

With C23 these two macros become mandatory.

Jens

-- 
Jens Gustedt - INRIA & ICube, Strasbourg, France

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] [PATCH v2] prevent from redefining __STDC_UTF_{16,32}__ macros
  2024-02-26  7:14     ` Jens Gustedt
@ 2024-02-26 14:36       ` Rich Felker
  0 siblings, 0 replies; 5+ messages in thread
From: Rich Felker @ 2024-02-26 14:36 UTC (permalink / raw)
  To: Jens Gustedt; +Cc: musl, Gabriel Ravier, Jules Maselbas

On Mon, Feb 26, 2024 at 08:14:52AM +0100, Jens Gustedt wrote:
> Hi
> 
> Am 26. Februar 2024 04:47:22 MEZ schrieb Gabriel Ravier <gabravier@gmail.com>:
> > On 2/26/24 02:17, Rich Felker wrote:
> > > On Thu, Jan 25, 2024 at 03:14:40PM +0100, Jules Maselbas wrote:
> > >> Undefine any previous __STDC_UTF_{16,32}__ macros before defining
> > >> them to prenvent any warnings of redefining macros.
> > >> 
> > >> ---
> > >> v2:
> > >>   - changed `#if !define(...)` guard to `#undef`, as suggested by Rich Felker
> > >> 
> > >> I encountered this "issue" trying to compile a program with the -isystem
> > >> option to override toolchain/installed musl headers with one from source.
> > >> 
> > >>   include/stdc-predef.h | 3 +++
> > >>   1 file changed, 3 insertions(+)
> > >> 
> > >> diff --git a/include/stdc-predef.h b/include/stdc-predef.h
> > >> index af1a2799..5ccd884d 100644
> > >> --- a/include/stdc-predef.h
> > >> +++ b/include/stdc-predef.h
> > >> @@ -7,7 +7,10 @@
> > >>   #define __STDC_IEC_559__ 1
> > >>   #endif
> > >>   +#undef __STDC_UTF_16__
> > >>   #define __STDC_UTF_16__ 1
> > >> +
> > >> +#undef __STDC_UTF_32__
> > >>   #define __STDC_UTF_32__ 1
> > >>     #endif
> > >> -- 
> > >> 2.43.0
> > > I merged this, but now gcc warns about undefining them if system
> > > header warnings aren't suppressed. I'm not sure what the justification
> > > is for that... *sigh*
> > > 
> > > Rich
> > 
> > It appears as though since 2001 GCC makes it so that any
> > redefinition or undefinition of any macro with a name starting
> > with "__STDC_" (with hard-coded exceptions for
> > __STDC_FORMAT_MACROS, __STDC_LIMIT_MACROS and
> > __STDC_CONSTANT_MACROS) always results in a warning (from reading
> > the code this doesn't seem to be tied to any -W switch, so it's
> > simply entirely impossible to work around)
> > 
> 
> The way to go would be to #ifdef them, not to use #undef. 
> These are really a language feature and not library, so anything
> that this should do is repair work for older compilers. The
> compiler's setting, if any, should prime over the C library.
> 
> With C23 these two macros become mandatory.

I think the gcc folks originally saw them as library-dependent, maybe
because of the char16_t/char32_t library functions. This is why we had
to define them ourselves in the first place. However indeed they are a
matter of how the compiler translates literals.

I'm okay with just switching to the original patch with #ifndef. But
it's probably unfortunate that gcc is this aggressive about the issue.

Rich

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-26 14:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-25 14:14 [musl] [PATCH v2] prevent from redefining __STDC_UTF_{16,32}__ macros Jules Maselbas
2024-02-26  2:17 ` Rich Felker
2024-02-26  3:47   ` Gabriel Ravier
2024-02-26  7:14     ` Jens Gustedt
2024-02-26 14:36       ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).