public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55203] New: No unused warning for variables of non-trivial types
@ 2012-11-04 10:48 l.lunak at suse dot cz
  2012-11-04 11:04 ` [Bug c++/55203] " l.lunak at suse dot cz
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: l.lunak at suse dot cz @ 2012-11-04 10:48 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

             Bug #: 55203
           Summary: No unused warning for variables of non-trivial types
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: l.lunak@suse.cz


GCC warns about unused variables e.g. of type 'int', but not 'std::string' :

$ cat a.cpp
#include <string>

void foo()
    {
    int i;
    std::string s;
    }
$ g++ -Wall -Wunused -c a.cpp
a.cpp: In function ‘void foo()’:
a.cpp:5:9: warning: unused variable ‘i’ [-Wunused-variable]
     int i;
         ^

In the function 's' is apparently unused too, but the compiler cannot tell it.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
@ 2012-11-04 11:04 ` l.lunak at suse dot cz
  2012-11-04 11:05 ` l.lunak at suse dot cz
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: l.lunak at suse dot cz @ 2012-11-04 11:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

Lubos Lunak <l.lunak at suse dot cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #1 from Lubos Lunak <l.lunak at suse dot cz> 2012-11-04 11:04:01 UTC ---
As the compiler cannot tell for sure in some cases, such as the ctor calling an
external function, the only reasonable way of handling this I see is explicit
tagging of types for which there should be an unused warning if only ctor/dtor
are called for a variable. Here's my attempt at attribute warn_unused.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
  2012-11-04 11:04 ` [Bug c++/55203] " l.lunak at suse dot cz
@ 2012-11-04 11:05 ` l.lunak at suse dot cz
  2012-11-07 14:55 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: l.lunak at suse dot cz @ 2012-11-04 11:05 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #2 from Lubos Lunak <l.lunak at suse dot cz> 2012-11-04 11:04:52 UTC ---
Created attachment 28609
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28609
gcc patch


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
  2012-11-04 11:04 ` [Bug c++/55203] " l.lunak at suse dot cz
  2012-11-04 11:05 ` l.lunak at suse dot cz
@ 2012-11-07 14:55 ` paolo.carlini at oracle dot com
  2013-06-15 18:13 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-07 14:55 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-07 14:54:59 UTC ---
Patches should go to gcc-patches. But I'm afraid it's too late for something
like this to make 4.8.0.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
                   ` (2 preceding siblings ...)
  2012-11-07 14:55 ` paolo.carlini at oracle dot com
@ 2013-06-15 18:13 ` paolo.carlini at oracle dot com
  2013-07-16  6:41 ` l.lunak at suse dot cz
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-15 18:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I guess this could be the right time to properly submit something to
gcc-patches (for 4.9)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
                   ` (3 preceding siblings ...)
  2013-06-15 18:13 ` paolo.carlini at oracle dot com
@ 2013-07-16  6:41 ` l.lunak at suse dot cz
  2013-07-16  9:57 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: l.lunak at suse dot cz @ 2013-07-16  6:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #5 from Lubos Lunak <l.lunak at suse dot cz> ---
Gcc patch is in, r200941.

Keeping open for libstdc++ to use the attribute for its relevant classes. I can
try to submit a patch when I find the time, but I doubt I'll get past the most
obvious classes, so anyone more knowledgeable about libstdc++ can feel free.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
                   ` (4 preceding siblings ...)
  2013-07-16  6:41 ` l.lunak at suse dot cz
@ 2013-07-16  9:57 ` redi at gcc dot gnu.org
  2013-07-16  9:58 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-16  9:57 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Which are the relevant classes?  It seems to me that we want to tag almost
everything except a few RAII types such as std::lock_guard and
std::unique_lock, which would be quite tedious.  It's certainly applicable on
all containers, and most streams except fstreams (which have constructors with
side-effects.)

I think your extend.texi change is wrong, a std::mutex that is unused is
useless, its constructor and destructor don't do anything useful. A
std::lock_guard that is unused is useless.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
                   ` (5 preceding siblings ...)
  2013-07-16  9:57 ` redi at gcc dot gnu.org
@ 2013-07-16  9:58 ` redi at gcc dot gnu.org
  2013-07-16 11:29 ` l.lunak at suse dot cz
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-16  9:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> std::lock_guard that is unused is useless.

Oops, I meant is *not* useless! Sorry.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
                   ` (6 preceding siblings ...)
  2013-07-16  9:58 ` redi at gcc dot gnu.org
@ 2013-07-16 11:29 ` l.lunak at suse dot cz
  2013-07-16 12:30 ` redi at gcc dot gnu.org
  2021-09-15 15:51 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: l.lunak at suse dot cz @ 2013-07-16 11:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #8 from Lubos Lunak <l.lunak at suse dot cz> ---
(In reply to Jonathan Wakely from comment #6)
> Which are the relevant classes?  It seems to me that we want to tag almost
> everything except a few RAII types such as std::lock_guard and
> std::unique_lock, which would be quite tedious.  It's certainly applicable
> on all containers, and most streams except fstreams (which have constructors
> with side-effects.)

 Correct. And I do not see a better way than tagging everything where it
applies.

> I think your extend.texi change is wrong, a std::mutex that is unused is
> useless, its constructor and destructor don't do anything useful. A
> std::lock_guard that is unused is *not* useless.

 Correct as well. But that doesn't come from my patch, that section was altered
by Jason Merrill before committing, and I overlooked that. Can you fix that
easily or should I submit a patch?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
                   ` (7 preceding siblings ...)
  2013-07-16 11:29 ` l.lunak at suse dot cz
@ 2013-07-16 12:30 ` redi at gcc dot gnu.org
  2021-09-15 15:51 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-16 12:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I can fix the docs some time.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/55203] No unused warning for variables of non-trivial types
  2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
                   ` (8 preceding siblings ...)
  2013-07-16 12:30 ` redi at gcc dot gnu.org
@ 2021-09-15 15:51 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-09-15 15:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-09-15
             Status|UNCONFIRMED                 |NEW

--- Comment #22 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed as a useful enhancement.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-09-15 15:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-04 10:48 [Bug c++/55203] New: No unused warning for variables of non-trivial types l.lunak at suse dot cz
2012-11-04 11:04 ` [Bug c++/55203] " l.lunak at suse dot cz
2012-11-04 11:05 ` l.lunak at suse dot cz
2012-11-07 14:55 ` paolo.carlini at oracle dot com
2013-06-15 18:13 ` paolo.carlini at oracle dot com
2013-07-16  6:41 ` l.lunak at suse dot cz
2013-07-16  9:57 ` redi at gcc dot gnu.org
2013-07-16  9:58 ` redi at gcc dot gnu.org
2013-07-16 11:29 ` l.lunak at suse dot cz
2013-07-16 12:30 ` redi at gcc dot gnu.org
2021-09-15 15:51 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).