Issue 133114
Summary [clang-tidy] Check request: modernize-use-std-quoted
Labels clang-tidy
Assignees
Reporter denzor200
    
Needs a check that will find string literals that are written to a stream with quotes and will suggest to change the code with `std::quoted` usage.

BEFORE:
```
constexpr const char line[] = "The first line";
constexpr const char line2[] = "Stays \" unchanged";
const std::string line3 = get_string();
ss << '"' << line << '"';
ss << '"' << line2 << '"';
ss << '"' << line3 << '"';
ss << "\"Hello world!\"" << std::endl;
```

AFTER:
```
constexpr const char line[] = "The first line";
constexpr const char line2[] = "Stays \" unchanged";
const std::string line3 = get_string();
ss << std::quoted(line);
ss << '"' << line2 << '"'; // due to the `"` symbol in the middle of `line2`
ss << '"' << line3 << '"'; // not a literal
ss << std::quoted("Hello world!") << std::endl;
```

I suppose this check should provide an option to switch it to "unsafe" mode(This is the mode when change suggests for even not a string literal).

AFTER(UNSAFE-MODE):
```
constexpr const char line[] = "The first line";
constexpr const char line2[] = "Stays \" unchanged";
const std::string line3 = get_string();
ss << std::quoted(line);
ss << std::quoted(line2); // OK, but unsafe because `line2` contains `"` symbol
ss << std::quoted(line3); // OK, but unsage because `line3` not a literal
ss << std::quoted("Hello world!") << std::endl;
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to