Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy][BUG][C++23][False Positive] on no name placeholder with std::string type #121731

Open
yaoxinliu opened this issue Jan 6, 2025 · 6 comments · May be fixed by #121783
Open

[clang-tidy][BUG][C++23][False Positive] on no name placeholder with std::string type #121731

yaoxinliu opened this issue Jan 6, 2025 · 6 comments · May be fixed by #121783

Comments

@yaoxinliu
Copy link

yaoxinliu commented Jan 6, 2025

auto _ = std::vector<int>{};     // ok, no warning
auto _ = std::unique_ptr<int>{}; // ok, no warning
auto _ = "abc"sv;                // ok, no warning
auto _ = 1234;                   // ok, no warning
auto _ = 3.14;                   // ok, no warning
auto _ = "abcd"sv;               // ok, no warning
auto _ = {1, 2, 3};              // ok, no warning
auto _ = "abcd"s;                // warning by clang-tidy: Unused local variable '_' of type 'basic_string<char>'
auto _ = [] { return ""s; }();   // warning by clang-tidy: Unused local variable '_' of type 'basic_string<char>'

My clang-tidy version is 19.1.5.

Note that this false positive occur for std::string only, other types, even std::vector<int> and std::unique_ptr<int> which are obviously non-trivial classes, seem also good as expected.

@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2025

@llvm/issue-subscribers-clang-tidy

Author: None (yaoxinliu)

``` auto _ = "abc"sv; auto _ = 1234; // ok auto _ = 3.14; // ok auto _ = "abcd"sv; // ok auto _ = {1, 2, 3}; // ok auto _ = "abcd"s; // warning by clang-tidy: Unused local variable '_' of type 'basic_string<char>' auto _ = [] { return ""s; }(); // warning by clang-tidy: Unused local variable '_' of type 'basic_string<char>' ```

My clang-tidy version is 19.1.5.

@yaoxinliu yaoxinliu changed the title [clang-tidy][C+23] False warning on no name placeholder with std::string [clang-tidy][BUG][C+23] False warning on no name placeholder with std::string Jan 6, 2025
@yaoxinliu yaoxinliu changed the title [clang-tidy][BUG][C+23] False warning on no name placeholder with std::string [clang-tidy][BUG][C++23] False warning on no name placeholder with std::string Jan 6, 2025
@yaoxinliu yaoxinliu changed the title [clang-tidy][BUG][C++23] False warning on no name placeholder with std::string [clang-tidy][BUG][C++23][False Positive] on no name placeholder with std::string type Jan 6, 2025
HerrCai0907 added a commit to HerrCai0907/llvm-project that referenced this issue Jan 6, 2025
…s after C++26 for bugprone-unused-local-non-trivial-variable

Fixed: llvm#121731
According to https://eel.is/c++draft/basic.scope.scope#5, name independent declaration should not be warned as unused
@yaoxinliu
Copy link
Author

yaoxinliu commented Jan 6, 2025

@HerrCai0907, why does this false positive occur for std::string only?

@HerrCai0907
Copy link
Contributor

HerrCai0907 commented Jan 7, 2025

@HerrCai0907, why does this false positive occur for std::string only?

The other types are not non trivial. But i don't look details for the default non trivial type list.

@yaoxinliu
Copy link
Author

yaoxinliu commented Jan 7, 2025

@HerrCai0907, why does this false positive occur for std::string only?

The other types are not non trivial. But i don't look details for the default non trivial type list.

I tested std::vector<int> && std::unique_ptr<int>, which are obviously non-trivial types, and found them also ok as expected. @HerrCai0907

@HerrCai0907
Copy link
Contributor

see https://clang.llvm.org/extra/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.html#cmdoption-arg-IncludeTypes

@yaoxinliu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants