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] "modernize-use-emplace" does not provide diagnostic for std::optional #133108

Open
denzor200 opened this issue Mar 26, 2025 · 2 comments

Comments

@denzor200
Copy link

std::vector<std::pair<std::string, int>> v;
v.push_back(std::pair<std::string, int>("first", 1)); // OK - clang tidy provides warnings for that

std::optional<std::pair<std::string, int>> o;
o = std::pair<std::string, int>{"first", 1};          // BAD - silence

The full snippet here: https://godbolt.org/z/nW9dKscqo

@llvmbot
Copy link
Member

llvmbot commented Mar 26, 2025

@llvm/issue-subscribers-clang-tidy

Author: Denis Mikhailov (denzor200)

std::vector&lt;std::pair&lt;std::string, int&gt;&gt; v;
v.push_back(std::pair&lt;std::string, int&gt;("first", 1)); // OK - clang tidy provides warnings for that

std::optional&lt;std::pair&lt;std::string, int&gt;&gt; o;
o = std::pair&lt;std::string, int&gt;{"first", 1};          // BAD - silence

The full snippet here: https://godbolt.org/z/nW9dKscqo

@vbvictor
Copy link
Contributor

vbvictor commented Mar 28, 2025

According to the docs, it should not warn on operator=.

The check flags insertions to an STL-style container done by calling the push_back, push, or push_front methods with an explicitly-constructed temporary of the container element type.

Should it still be considered as a false negative?

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

No branches or pull requests

4 participants