[Bug c++/54047] unused variable warning not for std::string
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jul 20 12:09:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54047
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-07-20 12:09:01 UTC ---
It's the case for all objects with a non-trivial constructor, not only
std::string.
Constructors might have side-effects, so you might not need to "use" the
variable, all you want is to construct it.
e.g. you don't want an unused variable warning for 'l' here:
void f(std::mutex& m, int& i) {
std::lock_guard<std::mutex> l(m);
i = 1;
}
I think this behaviour is intentional and correct.
More information about the Gcc-bugs
mailing list