Closed
Description
#include <stack>
#include <string>
struct A {
std::string s;
};
void f1() {
std::stack<A> s;
s.push(A()); // no warning
}
void f2() {
std::stack<A> s;
s.push(A{}); // no warning
}
void f3() {
std::stack<A> s;
s.push(A{""}); // no warning
}
void f4() {
std::stack<A> s;
s.push({}); // no warning
}
void f5() {
std::stack<A> s;
s.push({""}); // no warning
}
void f6() {
std::stack<A> s;
s.emplace(A()); // warning
}
https://godbolt.org/z/sq6K8MchT
Interestingly the warning about the usage of unnecessary temporary objects is being reported so it seems like std::stack
is not excluded from this check in general:
<source>:35:15: warning: unnecessary temporary object created while calling emplace [modernize-use-emplace]]
s.emplace(A()); // warning
^~~