public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Local type inference with auto is in C2X
@ 2022-11-03 10:37 Florian Weimer
  2022-11-03 15:19 ` Michael Matz
  2022-11-03 18:04 ` Joseph Myers
  0 siblings, 2 replies; 5+ messages in thread
From: Florian Weimer @ 2022-11-03 10:37 UTC (permalink / raw)
  To: gcc

So apparently auto was voted in to the committee draft of C2X at the
last minute.  I wonder how this aligns with the WG14 charter, given the
lack of implementation experience with this feature, but it looks like
we are now stuck with it.

My main worry is that both Clang and GCC still enable implicit ints by
default.  This means that auto variables have type int always, and that
can subtly alter the meaning of programs.  The only indication that this
has happened in a code base is a warning that went away (!).  I don't
like that.

My original plan was to port upstreams & distributions away from
implicit ints (again, configure scripts are problematic), and then have
at least one GCC release that disables implicit ints in the default
language mode.  But I'm not sure if that's now possible: the porting
will not have propagated widely once GCC 13 releases, so rejecting
implicit ints in GCC 13 might be too early.  GCC 14 might want to switch
to C23/C24 mode by default, activating auto support, if the standard
comes out in 2023 (which apparently is the plan).  Then we would go from
warning to changed semantics in a single release.

Comments?

Thanks,
Florian


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

* Re: Local type inference with auto is in C2X
  2022-11-03 10:37 Local type inference with auto is in C2X Florian Weimer
@ 2022-11-03 15:19 ` Michael Matz
  2022-11-04 14:16   ` David Brown
  2022-11-03 18:04 ` Joseph Myers
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Matz @ 2022-11-03 15:19 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc

Hello,

On Thu, 3 Nov 2022, Florian Weimer via Gcc wrote:

> will not have propagated widely once GCC 13 releases, so rejecting
> implicit ints in GCC 13 might be too early.  GCC 14 might want to switch
> to C23/C24 mode by default, activating auto support, if the standard
> comes out in 2023 (which apparently is the plan).
> 
> Then we would go from
> warning to changed semantics in a single release.
> 
> Comments?

I would argue that changing the default C mode to c23 in the year that 
comes out (or even a year later) is too aggressive and early.  Existing 
sources are often compiled with defaults, and hence would change 
semantics, which seems unattractive.  New code can instead easily use 
-std=c23 for a time.

E.g. c99/gnu99 (a largish deviation from gnu90) was never default and 
gnu11 was made default only in 2014.


Ciao,
Michael.

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

* Re: Local type inference with auto is in C2X
  2022-11-03 10:37 Local type inference with auto is in C2X Florian Weimer
  2022-11-03 15:19 ` Michael Matz
@ 2022-11-03 18:04 ` Joseph Myers
  2022-11-03 18:33   ` Florian Weimer
  1 sibling, 1 reply; 5+ messages in thread
From: Joseph Myers @ 2022-11-03 18:04 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc

On Thu, 3 Nov 2022, Florian Weimer via Gcc wrote:

> My main worry is that both Clang and GCC still enable implicit ints by
> default.  This means that auto variables have type int always, and that
> can subtly alter the meaning of programs.  The only indication that this
> has happened in a code base is a warning that went away (!).  I don't
> like that.

My expectation is that the old use of auto as a storage class specifier is 
actually very rare in C code, so this particular sub-case (auto with no 
type specifier meaning implicit int) is even rarer and there isn't much 
porting to be done for it (unlike for the rest of implicit int).

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: Local type inference with auto is in C2X
  2022-11-03 18:04 ` Joseph Myers
@ 2022-11-03 18:33   ` Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2022-11-03 18:33 UTC (permalink / raw)
  To: Joseph Myers; +Cc: gcc

* Joseph Myers:

> On Thu, 3 Nov 2022, Florian Weimer via Gcc wrote:
>
>> My main worry is that both Clang and GCC still enable implicit ints by
>> default.  This means that auto variables have type int always, and that
>> can subtly alter the meaning of programs.  The only indication that this
>> has happened in a code base is a warning that went away (!).  I don't
>> like that.
>
> My expectation is that the old use of auto as a storage class specifier is 
> actually very rare in C code, so this particular sub-case (auto with no 
> type specifier meaning implicit int) is even rarer and there isn't much 
> porting to be done for it (unlike for the rest of implicit int).

Hmm, that's certainly a reassuring perspective.  Maybe I'm worrying
about nothing after all.

Thanks,
Florian


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

* Re: Local type inference with auto is in C2X
  2022-11-03 15:19 ` Michael Matz
@ 2022-11-04 14:16   ` David Brown
  0 siblings, 0 replies; 5+ messages in thread
From: David Brown @ 2022-11-04 14:16 UTC (permalink / raw)
  To: Michael Matz, Florian Weimer; +Cc: gcc

On 03/11/2022 16:19, Michael Matz via Gcc wrote:
> Hello,
> 
> On Thu, 3 Nov 2022, Florian Weimer via Gcc wrote:
> 
>> will not have propagated widely once GCC 13 releases, so rejecting
>> implicit ints in GCC 13 might be too early.  GCC 14 might want to switch
>> to C23/C24 mode by default, activating auto support, if the standard
>> comes out in 2023 (which apparently is the plan).
>>
>> Then we would go from
>> warning to changed semantics in a single release.
>>
>> Comments?
> 
> I would argue that changing the default C mode to c23 in the year that
> comes out (or even a year later) is too aggressive and early.  Existing
> sources are often compiled with defaults, and hence would change
> semantics, which seems unattractive.  New code can instead easily use
> -std=c23 for a time.
> 
> E.g. c99/gnu99 (a largish deviation from gnu90) was never default and
> gnu11 was made default only in 2014.
> 

That's true - and the software world still has not recovered from the 
endless mass of drivel that gcc (and other compilers) accepted in lieu 
of decent C as a result of not changing to C99 as the standard.

Good C programmers put the standards flag explicitly in their makefile 
(or other build system).  Bad ones use whatever the compiler gives them 
by default and believe "the compiler accepted it, it must be good code".

My vote would be to make "-std=c17 -Wall -Wextra -Wpedantic -Werror -O2" 
the default flags.  Force those who don't really know what they are 
doing, to learn - it's not /that/ hard, and the effort pays off quickly. 
  (Or they can give up and move to Python.)  Those who understand how to 
use their tools can happily change the standards and warnings to suit 
their needs.

And the person who first decided "implicit declaration of function" 
should merely be a /warning/ should be sentenced to 10 years Cobol 
programming.

It's probably a good thing that it is not I who decides the default 
flags for gcc !

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

end of thread, other threads:[~2022-11-04 14:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 10:37 Local type inference with auto is in C2X Florian Weimer
2022-11-03 15:19 ` Michael Matz
2022-11-04 14:16   ` David Brown
2022-11-03 18:04 ` Joseph Myers
2022-11-03 18:33   ` Florian Weimer

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).