| Issue |
244214
|
| Summary |
clang-tidy readability-string-compare does not like std::optional<std::string>
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
Sir-Walrus
|
```c++
$ cat a.cpp
#include <string>
#include <optional>
bool abc(std::optional<std::string> a, std::optional<std::string> b)
{
return a->compare(*b) == 0;
}
$ clang++ a.cpp
$ clang-tidy a.cpp --checks=readability-string-compare --fix
a.cpp:6:12: warning: do not use ‘compare’ to test equality of strings; use the string equality operator instead [readability-string-compare]
6 | return a->compare(*b) == 0;
| ^~~~~~~~~~~~~~ ~
| *a-> *b
/home/agrell/a.cpp:6:12: note: FIX-IT applied suggested code changes
/home/agrell/a.cpp:6:30: note: FIX-IT applied suggested code changes
6 | return a->compare(*b) == 0;
| ^
clang-tidy applied 2 of 2 suggested fixes.
$ cat a.cpp
#include <string>
#include <optional>
bool abc(std::optional<std::string> a, std::optional<std::string> b)
{
return *a-> == *b;
}
$ clang++ a.cpp
a.cpp:6:17: error: expected unqualified-id
6 | return *a-> == *b;
| ^
1 error generated.
```
https://godbolt.org/z/v487h9jjz
The issue does not reproduce with pointers to std::string; those correctly omit the ->.
Labels: clang-tidy, invalid-code-generation
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs