llvm / llvm/llvm-project

User-defined string literals not split

Open
#165,617 7 comments 0 reactions 1 assignee Claimed by @shivrm View on GitHub
clang-format
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

clang-format is currently unable to break user-defined string literals. For instance,
```cpp
"A very very very very very very very very very very very very very long string literal";
```
is split into
```cpp
"A very very very very very very very very very very very very very long "
"string literal";
```
to fit into the 80 characters column limit.

But
```cpp
unsigned operator ""_s(const char*);
"A very very very very very very very very very very very very very long string literal"_s;
```
remains the same ([Godbolt](https://godbolt.org/z/5zhde1M7E)). clang-format is allowed to break the string into
```cpp
"A very very very very very very very very very very very very very long "
"string literal"_s;
```
as explained by cppreference.com:
[Image](https://en.cppreference.com/w/cpp/language/user_literal.html)

Implementation-wise, this is because clang-format only recognizes a hardcoded set of string literal encodings to be breakable:
https://github.com/llvm/llvm-project/blob/9d1b6eec60490c09ab8367667fb70637695179c3/clang/lib/Format/ContinuationIndenter.cpp#L2520-L2527

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.