llvm / llvm/llvm-project

unicode whitespace between `#` and directive name not diagnosed in skipped group

Open
#164,179 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clang:frontend confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

As noted in discussion of a [recent C++ NB comment](https://github.com/cplusplus/nbballot/issues/595), Clang treats Unicode whitespace as being whitespace as an extension (issuing a warning diagnostic, which becomes an error under `-pedantic-errors`). This is mostly a conforming extension, but we fail to produce a standard-mandated diagnostic if the whitespace occurs before the directive name in a skipped group:

```c++
#if 0
#line 1
#line 1
#endif
```

This is ill-formed; within a skipped group, the directive syntax is [only relaxed after the directive name](https://eel.is/c++draft/cpp.pre#5), so we're still required to issue a diagnostic for the Unicode whitespace (which forms a single-character pp-token, resulting in a token sequence that does not obey the grammar for a directive) if it occurs before the directive name. In order to conform, we should produce the `ExtWarn` diagnostic in this case too.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Clang's preprocessor handling for directives and skipped groups, using the two shown forms to compare whitespace before the directive name with whitespace after it. Find the existing ExtWarn path for Unicode whitespace and add regression coverage demonstrating that both forms produce the required diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.