This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/54047] unused variable warning not for std::string


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]