Po Lu via Gcc <gcc@gcc.gnu.org> writes: > Jonathan Wakely via Gcc <gcc@gcc.gnu.org> writes: > >> On Wed, 10 May 2023, 03:32 Eli Zaretskii, <e...@gnu.org> wrote: >> >>> >>> And then people will start complaining about GCC unnecessarily >>> erroring out, which is a compiler bug, since there's no problem >>> producing correct code in these cases. >>> >> >> >> What is the correct code for this? >> >> void foo(int); >> void bar() { foo("42"); } >> >> Why should this compile? > > Because keeping that from compiling will also keep this from compiling: > > bar () > { > extern foo (); > > return foo ("42"); > }
Good. The above code is nonsense, the chances that foo will be incorrectly called are high. >> You keep demanding better rationale for the change, but your argument >> amounts to nothing more than "it compiles today, it should compile >> tomorrow". > > And so it should. Because for every invalid piece of code you can think > of, there are hundereds or thousands of combinations that may as well be > valid. For example, on the 68020, vax, or similarly reasonable 32-bit > machine: > > foo (ptr) > { > register char *str; > > str = ptr; > > /* do stuff with str */ > > puts (str); > } > > /* In another translation unit. */ > > bar () > { > foo ("42"); > } What is this meant to produce? This is, at best, a "works by coincidence", rather than being code anyone should be writing. Such code is already written, when building it, pass -fpermissive. You benefit from the error otherwise. (and no, this isn't an issue of style, the code in question *does not* convey sufficient information for the compiler to always do the right thing) Have a lovely day. -- Arsen Arsenović
signature.asc
Description: PGP signature