Skip to content

C18 standard conformance non-compliance. #41571

Open
@llvmbot

Description

@llvmbot
Bugzilla Link 42226
Version 6.0
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@DougGregor,@hubert-reinterpretcast,@zygoloid,@TNorthover

Extended Description

This report is a technical point more than anything. Both the C90 and C18 standards have a "conformance chapter", chapter 4 on C18, that states the following on section 1:

"In this International Standard, “shall” is to be interpreted as a requirement on an implementation or on a program; conversely, “shall not” is to be interpreted as a prohibition"

The technical point is the following, in section 5.1.1.2 in C18 , there is a similar section in C90, phase 2 states the following:

"Each instance of a backslash character () immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place."

Consider the following program:

simple_case.c

int main(){ return 0; }
\

clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

gcc (Ubuntu 8.3.0-6ubuntu1~18.04) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The clang version above compiles it just fine, and the gcc version above issues the following warning:

"c.c:2:1: warning: backslash-newline at end of file
\

"

If instead we have:

elaborate_case.c
"
int main(){ return 0; }
\

"

then they both compile fine without warning.

Question: according to the standard "A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place.", are we not required by the standard to treat such a text file, the elaborate_case.c, as not a "source file"? That is, it should not compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac17clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions