public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Check for ISO C compilers should also allow C++
@ 2022-05-13 16:31 Jonathan Wakely
  2022-05-13 16:46 ` Florian Weimer
  2022-05-13 17:27 ` Joseph Myers
  0 siblings, 2 replies; 6+ messages in thread
From: Jonathan Wakely @ 2022-05-13 16:31 UTC (permalink / raw)
  To: libc-alpha, carlos, fweimer

Tested x86_64-linux.

There is a suggestion[1] to make clang++ stop defining __STDC__ but it's
blocked by this. The clang++ change will still be blocked while old
Glibc versions are still in use, but we can start the clock ticking by
fixing Glibc now.

[1] https://discourse.llvm.org/t/rfc-stop-defining-the-stdc-and-related-macros-in-c-mode/62468/1

From a quick grep, I don't think any other places in Glibc need a
similar change. Florian pointed out that gnulib overrides
<sys/cdefs.h> and so should make the same change in its version.

OK to push?

-- >8 --

The check for an ISO C compiler assumes that anything GCC-like will
define __STDC__, even if it's actually a C++ compiler. That's currently
true for G++ and compilers like clang++ that also define __GNUC__, but
it might not always be true.

The C++ standard leaves it implementation-defined whether or not
__STDC__ is defined by C++ compilers. And really the check should be
"ISO C or ISO C++ conforming compiler" anyway.
---
 misc/sys/cdefs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index f1faf8292c..aab0e7f6a9 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -27,8 +27,8 @@
 /* The GNU libc does not support any K&R compilers or the traditional mode
    of ISO C compilers anymore.  Check for some of the combinations not
    supported anymore.  */
-#if defined __GNUC__ && !defined __STDC__
-# error "You need a ISO C conforming compiler to use the glibc headers"
+#if defined __GNUC__ && !defined __STDC__ && !defined __cplusplus
+# error "You need a ISO C or C++ conforming compiler to use the glibc headers"
 #endif
 
 /* Some user header file might have defined this before.  */
-- 
2.35.1


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

* Re: [PATCH] Check for ISO C compilers should also allow C++
  2022-05-13 16:31 [PATCH] Check for ISO C compilers should also allow C++ Jonathan Wakely
@ 2022-05-13 16:46 ` Florian Weimer
  2022-05-13 17:27 ` Joseph Myers
  1 sibling, 0 replies; 6+ messages in thread
From: Florian Weimer @ 2022-05-13 16:46 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libc-alpha, carlos

* Jonathan Wakely:

> The check for an ISO C compiler assumes that anything GCC-like will
> define __STDC__, even if it's actually a C++ compiler. That's currently
> true for G++ and compilers like clang++ that also define __GNUC__, but
> it might not always be true.
>
> The C++ standard leaves it implementation-defined whether or not
> __STDC__ is defined by C++ compilers. And really the check should be
> "ISO C or ISO C++ conforming compiler" anyway.
> ---
>  misc/sys/cdefs.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
> index f1faf8292c..aab0e7f6a9 100644
> --- a/misc/sys/cdefs.h
> +++ b/misc/sys/cdefs.h
> @@ -27,8 +27,8 @@
>  /* The GNU libc does not support any K&R compilers or the traditional mode
>     of ISO C compilers anymore.  Check for some of the combinations not
>     supported anymore.  */
> -#if defined __GNUC__ && !defined __STDC__
> -# error "You need a ISO C conforming compiler to use the glibc headers"
> +#if defined __GNUC__ && !defined __STDC__ && !defined __cplusplus
> +# error "You need a ISO C or C++ conforming compiler to use the glibc headers"
>  #endif
>  
>  /* Some user header file might have defined this before.  */

The change and commit message make sense to me.  We can backport this,
too.

Thanks,
Florian


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

* Re: [PATCH] Check for ISO C compilers should also allow C++
  2022-05-13 16:31 [PATCH] Check for ISO C compilers should also allow C++ Jonathan Wakely
  2022-05-13 16:46 ` Florian Weimer
@ 2022-05-13 17:27 ` Joseph Myers
  2022-05-13 17:41   ` Jonathan Wakely
  1 sibling, 1 reply; 6+ messages in thread
From: Joseph Myers @ 2022-05-13 17:27 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libc-alpha, carlos, fweimer

On Fri, 13 May 2022, Jonathan Wakely via Libc-alpha wrote:

> Tested x86_64-linux.
> 
> There is a suggestion[1] to make clang++ stop defining __STDC__ but it's
> blocked by this. The clang++ change will still be blocked while old
> Glibc versions are still in use, but we can start the clock ticking by
> fixing Glibc now.
> 
> [1] https://discourse.llvm.org/t/rfc-stop-defining-the-stdc-and-related-macros-in-c-mode/62468/1
> 
> >From a quick grep, I don't think any other places in Glibc need a
> similar change. Florian pointed out that gnulib overrides
> <sys/cdefs.h> and so should make the same change in its version.

The change seems sane.  While we don't document what extensions (beyond 
C90 / C++98) are needed to use glibc's headers (e.g. long long, flexible 
array members, anonymous structs / unions; in at least some cases, 
alignment attributes and asm redirection of functions), I see no reason 
defining __STDC__ in C++ should be such a required extension.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH] Check for ISO C compilers should also allow C++
  2022-05-13 17:27 ` Joseph Myers
@ 2022-05-13 17:41   ` Jonathan Wakely
  2022-05-14  6:46     ` Fangrui Song
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2022-05-13 17:41 UTC (permalink / raw)
  To: Joseph Myers; +Cc: GNU C Library, Carlos O'Donell, Florian Weimer

On Fri, 13 May 2022 at 18:28, Joseph Myers wrote:
>
> On Fri, 13 May 2022, Jonathan Wakely via Libc-alpha wrote:
>
> > Tested x86_64-linux.
> >
> > There is a suggestion[1] to make clang++ stop defining __STDC__ but it's
> > blocked by this. The clang++ change will still be blocked while old
> > Glibc versions are still in use, but we can start the clock ticking by
> > fixing Glibc now.
> >
> > [1] https://discourse.llvm.org/t/rfc-stop-defining-the-stdc-and-related-macros-in-c-mode/62468/1
> >
> > >From a quick grep, I don't think any other places in Glibc need a
> > similar change. Florian pointed out that gnulib overrides
> > <sys/cdefs.h> and so should make the same change in its version.
>
> The change seems sane.  While we don't document what extensions (beyond
> C90 / C++98) are needed to use glibc's headers (e.g. long long, flexible
> array members, anonymous structs / unions; in at least some cases,
> alignment attributes and asm redirection of functions), I see no reason
> defining __STDC__ in C++ should be such a required extension.

Right. Its meaning in ISO C++ is entirely implementation-defined, and
G++ doesn't document any particular meaning for it, and clang++
doesn't either AFAIK, and follows a slightly different set of rules
for when it's defined (see the link above). So in C++ the only thing
that __STDC__ being defined tells you is that __STDC__ is defined :-)
That's not a very useful thing to test for in isolation.


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

* Re: [PATCH] Check for ISO C compilers should also allow C++
  2022-05-13 17:41   ` Jonathan Wakely
@ 2022-05-14  6:46     ` Fangrui Song
  2022-05-16 15:50       ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Fangrui Song @ 2022-05-14  6:46 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Joseph Myers, Florian Weimer, GNU C Library

On 2022-05-13, Jonathan Wakely via Libc-alpha wrote:
>On Fri, 13 May 2022 at 18:28, Joseph Myers wrote:
>>
>> On Fri, 13 May 2022, Jonathan Wakely via Libc-alpha wrote:
>>
>> > Tested x86_64-linux.
>> >
>> > There is a suggestion[1] to make clang++ stop defining __STDC__ but it's
>> > blocked by this. The clang++ change will still be blocked while old
>> > Glibc versions are still in use, but we can start the clock ticking by
>> > fixing Glibc now.
>> >
>> > [1] https://discourse.llvm.org/t/rfc-stop-defining-the-stdc-and-related-macros-in-c-mode/62468/1
>> >
>> > >From a quick grep, I don't think any other places in Glibc need a
>> > similar change. Florian pointed out that gnulib overrides
>> > <sys/cdefs.h> and so should make the same change in its version.
>>
>> The change seems sane.  While we don't document what extensions (beyond
>> C90 / C++98) are needed to use glibc's headers (e.g. long long, flexible
>> array members, anonymous structs / unions; in at least some cases,
>> alignment attributes and asm redirection of functions), I see no reason
>> defining __STDC__ in C++ should be such a required extension.
>
>Right. Its meaning in ISO C++ is entirely implementation-defined, and
>G++ doesn't document any particular meaning for it, and clang++
>doesn't either AFAIK, and follows a slightly different set of rules
>for when it's defined (see the link above). So in C++ the only thing
>that __STDC__ being defined tells you is that __STDC__ is defined :-)
>That's not a very useful thing to test for in isolation.
>

I agree with the spirit of the clang RFC but I am sad to know that glibc sys/cdefs.h blocks it.
Thanks for sending the patch!

It seems that the subject may be clearer if starting with "<sys/cdefs.h>: ..."

In addition, It will be clearer if the token `__STDC__` is mentioned on the subject line.

Reviewed-by: Fangrui Song <maskray@google.com>

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

* Re: [PATCH] Check for ISO C compilers should also allow C++
  2022-05-14  6:46     ` Fangrui Song
@ 2022-05-16 15:50       ` Jonathan Wakely
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2022-05-16 15:50 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Joseph Myers, Florian Weimer, GNU C Library

On Sat, 14 May 2022 at 07:46, Fangrui Song <maskray@google.com> wrote:
>
> On 2022-05-13, Jonathan Wakely via Libc-alpha wrote:
> >On Fri, 13 May 2022 at 18:28, Joseph Myers wrote:
> >>
> >> On Fri, 13 May 2022, Jonathan Wakely via Libc-alpha wrote:
> >>
> >> > Tested x86_64-linux.
> >> >
> >> > There is a suggestion[1] to make clang++ stop defining __STDC__ but it's
> >> > blocked by this. The clang++ change will still be blocked while old
> >> > Glibc versions are still in use, but we can start the clock ticking by
> >> > fixing Glibc now.
> >> >
> >> > [1] https://discourse.llvm.org/t/rfc-stop-defining-the-stdc-and-related-macros-in-c-mode/62468/1
> >> >
> >> > >From a quick grep, I don't think any other places in Glibc need a
> >> > similar change. Florian pointed out that gnulib overrides
> >> > <sys/cdefs.h> and so should make the same change in its version.
> >>
> >> The change seems sane.  While we don't document what extensions (beyond
> >> C90 / C++98) are needed to use glibc's headers (e.g. long long, flexible
> >> array members, anonymous structs / unions; in at least some cases,
> >> alignment attributes and asm redirection of functions), I see no reason
> >> defining __STDC__ in C++ should be such a required extension.
> >
> >Right. Its meaning in ISO C++ is entirely implementation-defined, and
> >G++ doesn't document any particular meaning for it, and clang++
> >doesn't either AFAIK, and follows a slightly different set of rules
> >for when it's defined (see the link above). So in C++ the only thing
> >that __STDC__ being defined tells you is that __STDC__ is defined :-)
> >That's not a very useful thing to test for in isolation.
> >
>
> I agree with the spirit of the clang RFC but I am sad to know that glibc sys/cdefs.h blocks it.
> Thanks for sending the patch!
>
> It seems that the subject may be clearer if starting with "<sys/cdefs.h>: ..."
>
> In addition, It will be clearer if the token `__STDC__` is mentioned on the subject line.
>
> Reviewed-by: Fangrui Song <maskray@google.com>

I made the suggested changes to the commit message and pushed the
patch, thanks for the reviews.


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

end of thread, other threads:[~2022-05-16 15:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 16:31 [PATCH] Check for ISO C compilers should also allow C++ Jonathan Wakely
2022-05-13 16:46 ` Florian Weimer
2022-05-13 17:27 ` Joseph Myers
2022-05-13 17:41   ` Jonathan Wakely
2022-05-14  6:46     ` Fangrui Song
2022-05-16 15:50       ` Jonathan Wakely

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 read-only IMAP folder(s) and NNTP newsgroup(s).