================
@@ -11,28 +11,24 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "llvm/Support/raw_ostream.h"
-#include <optional>
 
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::performance {
 
-static std::optional<std::string>
-makeCharacterLiteral(const StringLiteral *Literal) {
+static std::string makeCharacterLiteral(const StringLiteral *Literal) {
   std::string Result;
   {
     llvm::raw_string_ostream OS(Result);
     Literal->outputString(OS);
   }
   // Now replace the " with '.
-  auto OpenPos = Result.find_first_of('"');
-  if (OpenPos == std::string::npos)
-    return std::nullopt;
+  const size_t OpenPos = Result.find_first_of('"');
+  assert(OpenPos != std::string::npos);
----------------
localspook wrote:

> multi-line string

Assuming you mean:
```cpp
Str.find(""

  "k");
```
Works without changes, added tests.

> macro strings

This doesn't hit the assert, however it's probably still an FP to warn on cases 
like (https://godbolt.org/z/6s7rhneEM):
```cpp
#define ONE_CHAR "a"
void f() {
    std::string s;
    s.find(ONE_CHAR);
}
```
Since this is preexisting, I just added a FIXME.

https://github.com/llvm/llvm-project/pull/187069
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to