c++/10416: 'unused variable' warning ignores ctor/dtor side-effects
gccbugs@contacts.eelis.net
gccbugs@contacts.eelis.net
Tue Apr 15 18:56:00 GMT 2003
>Number: 10416
>Category: c++
>Synopsis: 'unused variable' warning ignores ctor/dtor side-effects
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Tue Apr 15 18:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Eelis van der Weegen
>Release: gcc 3.2
>Organization:
>Environment:
>Description:
Sometimes a variable is created only for the side-effects of its constructor/destructor. For example, in the following code:
struct Closer { ~Closer() { CloseClipboard(); } } closer;
the closer variable is only used to make sure the clipboard is closed when the function leaves (normally or exceptionally).
G++ apparently does not think this is valid use of a variable, and warns: "warning: unused variable".
>How-To-Repeat:
Compile:
void f () { struct atend { ~atend () { std::cout << "leaving f\n"; } } a; }
with -Wall.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list