llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.18k stars 12.04k forks source link

Clang C pre-processor allows invalid words #33241

Open llvmbot opened 7 years ago

llvmbot commented 7 years ago
Bugzilla Link 33894
Version 4.0
OS All
Reporter LLVM Bugzilla Contributor
CC @hubert-reinterpretcast

Extended Description

The following has a bad keyword, yet clang will parse it just fine.

if BADTEST

include

ele

include

endif

include

int main(int, char **) { exit(0); }

llvmbot commented 7 years ago

Assume you place the code into the file testcpp.cpp

clang++ testcpp.cpp

No error is present

clang++ -DBADTEST=1 testcpp.cpp

testcpp.cpp:3:2: error: invalid preprocessing directive

hubert-reinterpretcast commented 7 years ago

In various dialects of C and C++, the

ele

is not a diagnosable error, or is indeed specified to not be an error.

For dialects with "non-directive"s or "conditionally-supported-directive"s, the

ele

is considered to be such a directive.

A provision, present since ISO C90 (in subclause 6.8.1), specifies that directives in groups that are skipped are only processed up to the "name" for tracking nested conditionals. This appears to erase the question of the semantics for a non-directive.

In ISO C90, there are no non-directives; so, I read

ele

as a violation of a syntax rules (requiring a diagnostic).

In the C++17 DIS, it appears that

ele

shall be diagnosed as an error if the implementation does not document it as a supported conditionally-supported-directive.

hubert-reinterpretcast commented 7 years ago

Please provide the compiler invocation commands. In particular the description provided does not indicate whether BADTEST is defined via the command line, what language dialect is being used, and whether warnings or pedantic checking is enabled.