Skip to content

User-defined string literals not split #165617

@Meinersbur

Description

@Meinersbur

clang-format is currently unable to break user-defined string literals. For instance,

"A very very very very very very very very very very very very very long string literal";

is split into

"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

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). clang-format is allowed to break the string into

"A very very very very very very very very very very very very very long "
"string literal"_s;

as explained by cppreference.com:
Image

Implementation-wise, this is because clang-format only recognizes a hardcoded set of string literal encodings to be breakable:

if ((Text.ends_with(Postfix = "\"") &&
(Text.starts_with(Prefix = "@\"") || Text.starts_with(Prefix = "\"") ||
Text.starts_with(Prefix = "u\"") ||
Text.starts_with(Prefix = "U\"") ||
Text.starts_with(Prefix = "u8\"") ||
Text.starts_with(Prefix = "L\""))) ||
(Text.starts_with(Prefix = "_T(\"") &&
Text.ends_with(Postfix = "\")"))) {

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions