llvm / llvm/llvm-project

Poor Clang diagnostic for string literal concatenation with undefined macro

Open
#174,966 0 comments 2 reactions 0 assignees View on GitHub
clang:diagnostics
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Example:

```
#define BAR "bar"
const char *s = "foo" BAAR;
```

The author intended to concatenate "foo" with the string defined by the `BAR` macro but misspelled it. The diagnostic doesn't even mentioned the misspelled (and therefore undefined) macro though:

```
$ build/bin/clang -c /tmp/a.c
/tmp/a.c:2:22: error: expected ';' after top level declarator
2 | const char *s = "foo" BAAR;
| ^
| ;
1 error generated.
```

Other compilers have similar output (https://godbolt.org/z/o1GqPYdrG), but maybe Clang could do better?

Contributor guide

Open the contributing guide

Research direction

Reproduce the diagnostic with build/bin/clang -c /tmp/a.c using the example in the issue, then compare the output with the compiler results linked on Godbolt. Trace the diagnostic path for the adjacent string literal and BAAR tokens. Done means Clang reports the undefined or misspelled macro rather than only suggesting a missing semicolon.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.