public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character
       [not found] <bug-81745-4@http.gcc.gnu.org/bugzilla/>
@ 2023-04-17  1:56 ` sjames at gcc dot gnu.org
  2023-04-17  2:00 ` sjames at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-04-17  1:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81745

--- Comment #11 from Sam James <sjames at gcc dot gnu.org> ---
C99 seems to explicitly say, within Clause J.2, in the second bullet point:
>
>1 The behavior is undefined in the following circumstances:
>
>    [...]
>    A nonempty source file does not end in a new-line character which is not >immediately preceded by a backslash character or ends in a partial >preprocessing token or comment (5.1.1.2). 

Came across this because Clang has this warning for -pedantic but GCC doesn't.

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

* [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character
       [not found] <bug-81745-4@http.gcc.gnu.org/bugzilla/>
  2023-04-17  1:56 ` [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character sjames at gcc dot gnu.org
@ 2023-04-17  2:00 ` sjames at gcc dot gnu.org
  2023-04-17  2:12 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-04-17  2:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81745

--- Comment #12 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to Sam James from comment #11)
> C99 seems to explicitly say, within Clause J.2, in the second bullet point:

This seems to be in C23 still.

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

* [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character
       [not found] <bug-81745-4@http.gcc.gnu.org/bugzilla/>
  2023-04-17  1:56 ` [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character sjames at gcc dot gnu.org
  2023-04-17  2:00 ` sjames at gcc dot gnu.org
@ 2023-04-17  2:12 ` pinskia at gcc dot gnu.org
  2023-04-17 11:15 ` [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character [-Wnewline-eof] vincent-gcc at vinc17 dot net
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-17  2:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81745

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=68994

--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Sam James from comment #11)
> Came across this because Clang has this warning for -pedantic but GCC
> doesn't.

GCC removed the pedwarning on purpose (between GCC 4.1 and 4.4), see PR 14331
and PR 68994. 

https://gcc.gnu.org/legacy-ml/gcc-patches/2007-04/msg00651.html
is the specific one about GCC's behavior and since it is considered undefined
at compile time (not a runtime one) GCC behavior is correct so is clang

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

* [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character [-Wnewline-eof]
       [not found] <bug-81745-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2023-04-17  2:12 ` pinskia at gcc dot gnu.org
@ 2023-04-17 11:15 ` vincent-gcc at vinc17 dot net
  2023-04-17 16:36 ` pinskia at gcc dot gnu.org
  2023-04-18  3:03 ` egallager at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2023-04-17 11:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81745

--- Comment #14 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Andrew Pinski from comment #13)
> GCC removed the pedwarning on purpose (between GCC 4.1 and 4.4), see PR
> 14331 and PR 68994. 

No, PR 14331 was just asking to remove the warning by default, not that
`-pedantic` shouldn't warn: "I checked through the gcc manual, and didn't found
any option to suppress the warning message "no newline at end of file".

And PR 68994 was complaining about the missing warning.

> https://gcc.gnu.org/legacy-ml/gcc-patches/2007-04/msg00651.html
> is the specific one about GCC's behavior and since it is considered
> undefined at compile time (not a runtime one) GCC behavior is correct so is
> clang

Even though GCC decides to add a newline to the logical file, so that the
missing diagnostic can be regarded as correct, I think that an optional warning
would be useful for portability.
https://gcc.gnu.org/legacy-ml/gcc-patches/2007-04/msg00651.html was suggesting
"add -W(no-)eof-newline". So why hasn't -Wno-eof-newline been added?

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

* [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character [-Wnewline-eof]
       [not found] <bug-81745-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2023-04-17 11:15 ` [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character [-Wnewline-eof] vincent-gcc at vinc17 dot net
@ 2023-04-17 16:36 ` pinskia at gcc dot gnu.org
  2023-04-18  3:03 ` egallager at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-17 16:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81745

--- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Vincent Lefèvre from comment #14)
> Even though GCC decides to add a newline to the logical file, so that the
> missing diagnostic can be regarded as correct, I think that an optional
> warning would be useful for portability.
> https://gcc.gnu.org/legacy-ml/gcc-patches/2007-04/msg00651.html was
> suggesting "add -W(no-)eof-newline". So why hasn't -Wno-eof-newline been
> added?

Because it was decided the warning was not needed at all so why have an option
to turn it on/off if it was not a good warning.

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

* [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character [-Wnewline-eof]
       [not found] <bug-81745-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2023-04-17 16:36 ` pinskia at gcc dot gnu.org
@ 2023-04-18  3:03 ` egallager at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: egallager at gcc dot gnu.org @ 2023-04-18  3:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81745

--- Comment #16 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #15)
> (In reply to Vincent Lefèvre from comment #14)
> > Even though GCC decides to add a newline to the logical file, so that the
> > missing diagnostic can be regarded as correct, I think that an optional
> > warning would be useful for portability.
> > https://gcc.gnu.org/legacy-ml/gcc-patches/2007-04/msg00651.html was
> > suggesting "add -W(no-)eof-newline". So why hasn't -Wno-eof-newline been
> > added?
> 
> Because it was decided the warning was not needed at all so why have an
> option to turn it on/off if it was not a good warning.

It might not have been *needed*, but some people still might *want* it anyways.
I think it's a good warning anyways just for style purposes, even if it isn't
strictly necessary.

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

end of thread, other threads:[~2023-04-18  3:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-81745-4@http.gcc.gnu.org/bugzilla/>
2023-04-17  1:56 ` [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character sjames at gcc dot gnu.org
2023-04-17  2:00 ` sjames at gcc dot gnu.org
2023-04-17  2:12 ` pinskia at gcc dot gnu.org
2023-04-17 11:15 ` [Bug preprocessor/81745] missing warning with -pedantic when a C file does not end with a newline character [-Wnewline-eof] vincent-gcc at vinc17 dot net
2023-04-17 16:36 ` pinskia at gcc dot gnu.org
2023-04-18  3:03 ` egallager at gcc dot gnu.org

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