inconsistent behavior for user-defined literal suffixes after header-name
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Testcase:
```c++
// Case 1
#define SUFFIX
#include "foo.h"SUFFIX
// Case 2
#include "foo.h\" // can't escape "s
```
Clang diagnoses an invalid user-defined literal in the first but not the second:
```console
:2:17: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
2 | #include "foo.h"SUFFIX
| ^
|
```
What I think *should* happen: a *header-name* is lexed, and ends at the first `"`. `\` has no special meaning. The first `#include` includes `foo.h`, and expands the macro. The second `#include` includes `foo.h\` (which is probably invalid) and treats the rest of the line as a comment.
What I think the standard requires: both includes lex a user-defined-string-literal, because [lex.pptoken]/5.4 only says to not lex a *string-literal* here and a *user-defined-string-literal* is not a *string-literal*. (I've reported this on the core reflector; I think it's a wording defect.)
What Clang actually seems to do: lexes both cases as a *header-name*, but diagnoses the first one *anyway* because it's followed by a ud-suffix that's not in our set of valid string ud-suffixes.
Presumably we should not be diagnosing invalid ud-suffixes after header-name tokens, given that we don't actually treat them as being part of the token.
Contributor guide
Research direction
Start by reproducing the two include cases from the issue and inspect Clang's preprocessing lexer handling of header-name tokens and following suffixes. Compare the diagnostics for both cases; done means header-name tokens are handled consistently and an invalid user-defined-literal suffix is not diagnosed when it is not part of the header-name token.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100