public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/8045] Missing "unused variable" warning
[not found] <bug-8045-3310@http.gcc.gnu.org/bugzilla/>
@ 2008-05-11 16:32 ` flameeyes at gentoo dot org
2009-07-08 22:09 ` manu at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: flameeyes at gentoo dot org @ 2008-05-11 16:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from flameeyes at gentoo dot org 2008-05-11 16:31 -------
I think this applies to 4.3 as well, as the following code does only warn in
the second function:
#include <stdlib.h>
#include <string.h>
char* oldstyle(const char *foo) {
size_t foolen;
if ( foo == NULL )
return NULL;
foolen = strlen(foo);
return strdup(foo);
}
char* newstyle(const char *foo) {
if ( foo == NULL )
return NULL;
const size_t foolen = strlen(foo);
return strdup(foo);
}
And I could really make use of such a warning in xine-lib's code :)
--
flameeyes at gentoo dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |flameeyes at gentoo dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8045
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/8045] Missing "unused variable" warning
[not found] <bug-8045-3310@http.gcc.gnu.org/bugzilla/>
2008-05-11 16:32 ` [Bug c++/8045] Missing "unused variable" warning flameeyes at gentoo dot org
@ 2009-07-08 22:09 ` manu at gcc dot gnu dot org
2010-05-01 16:40 ` gerald at pfeifer dot com
2010-05-01 16:47 ` gerald at pfeifer dot com
3 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-07-08 22:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from manu at gcc dot gnu dot org 2009-07-08 22:08 -------
Are there some cases where a declaration such T x = y can be considered an use
of 'x' by itself?
The following patch warns for this, but it also produces warnings for some
testcases in the testsuite.
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c (revision 149319)
+++ gcc/cp/init.c (working copy)
@@ -1261,11 +1261,11 @@ build_aggr_init (tree exp, tree init, in
if (init)
TREE_TYPE (init) = itype;
return stmt_expr;
}
- if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL)
+ if (TREE_CODE (exp) == PARM_DECL)
/* Just know that we've seen something for this node. */
TREE_USED (exp) = 1;
is_global = begin_init_stmts (&stmt_expr, &compound_stmt);
destroy_temps = stmts_are_full_exprs_p ();
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |4.4.0
Last reconfirmed|2005-12-11 23:03:44 |2009-07-08 22:08:57
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8045
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/8045] Missing "unused variable" warning
[not found] <bug-8045-3310@http.gcc.gnu.org/bugzilla/>
2008-05-11 16:32 ` [Bug c++/8045] Missing "unused variable" warning flameeyes at gentoo dot org
2009-07-08 22:09 ` manu at gcc dot gnu dot org
@ 2010-05-01 16:40 ` gerald at pfeifer dot com
2010-05-01 16:47 ` gerald at pfeifer dot com
3 siblings, 0 replies; 6+ messages in thread
From: gerald at pfeifer dot com @ 2010-05-01 16:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from gerald at pfeifer dot com 2010-05-01 16:39 -------
(In reply to comment #0)
> Consider the following code snippet:
> bash-2.05$ cat foo.cc
> struct X { int y; };
>
> void foo() {
> X c;
> X tmp2;
> X d = tmp2;
> }
>
> Both c and d are unused. However, we only get an 'unused variable' warning from c.
A current (2010-04-26) snapshot of GCC 4.6 detects both cases:
y.c: In function 'foo':
y.c:5:5: warning: unused variable 'd' [-Wunused-variable]
y.c:3:5: warning: unused variable 'c' [-Wunused-variable]
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8045
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/8045] Missing "unused variable" warning
[not found] <bug-8045-3310@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2010-05-01 16:40 ` gerald at pfeifer dot com
@ 2010-05-01 16:47 ` gerald at pfeifer dot com
3 siblings, 0 replies; 6+ messages in thread
From: gerald at pfeifer dot com @ 2010-05-01 16:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from gerald at pfeifer dot com 2010-05-01 16:47 -------
(In reply to comment #4)
> I think this applies to 4.3 as well, as the following code does only warn in
> the second function:
The current snapshot mentioned above now warns as follows:
y.c: In function 'oldstyle':
y.c:5:10: warning: variable 'foolen' set but not used
[-Wunused-but-set-variable]
y.c: In function 'newstyle':
y.c:19:16: warning: unused variable 'foolen' [-Wunused-variable]
In other words, it catches both cases.
Based on this comment, and the previous, which has the original testcase
covered, I am marking this report as FIXED based on the good work Jakub
has done.
--
gerald at pfeifer dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gerald at pfeifer dot com,
| |jakub at redhat dot com
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8045
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/8045] Missing "unused variable" warning
[not found] <20020925133600.8045.austern@apple.com>
2003-11-16 2:32 ` pinskia at gcc dot gnu dot org
@ 2003-12-23 10:18 ` yotamm at mellanox dot co dot il
1 sibling, 0 replies; 6+ messages in thread
From: yotamm at mellanox dot co dot il @ 2003-12-23 10:18 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From yotamm at mellanox dot co dot il 2003-12-23 10:00 -------
Here is an example. It also shows lack of out-of-array-access warning.
mtls47:62> cat bugunused.cpp
class C {
public:
int d(int i) const { return _d[2]; }
int _d[2];
};
C c;
int cd() {
return c.d(13);
}
mtls47:63> g++ -v
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/specs
Configured with: /var/tmp/portage/gcc-3.2.3-r2/work/gcc-3.2.3/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.2
--includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2/info --enable-shared
--host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib
--enable-languages=c,c++,f77,objc,java --enable-threads=posix --enable-long-long
--disable-checking --enable-cstdio=stdio --enable-clocale=generic
--enable-__cxa_atexit --enable-version-specific-runtime-libs
--with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/include/g++-v3
--with-local-prefix=/usr/local --enable-shared --enable-nls
--without-included-gettext
Thread model: posix
gcc version 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r2, propolice)
mtls47:64> g++ -c -Wall -Wunused bugunused.cpp
mtls47:65> echo $?
0
mtls47:66>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8045
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/8045] Missing "unused variable" warning
[not found] <20020925133600.8045.austern@apple.com>
@ 2003-11-16 2:32 ` pinskia at gcc dot gnu dot org
2003-12-23 10:18 ` yotamm at mellanox dot co dot il
1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-11-16 2:32 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-11-16 02:32 -------
The problem is that the front-end is gerenting code like this (see how the copy for d is after d is
declared:
{
{
struct X c
struct X tmp2
struct X d
({
(void)(d = tmp2);
});
}
}
--
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2003-08-02 17:37:55 |2003-11-16 02:32:29
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8045
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-05-01 16:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-8045-3310@http.gcc.gnu.org/bugzilla/>
2008-05-11 16:32 ` [Bug c++/8045] Missing "unused variable" warning flameeyes at gentoo dot org
2009-07-08 22:09 ` manu at gcc dot gnu dot org
2010-05-01 16:40 ` gerald at pfeifer dot com
2010-05-01 16:47 ` gerald at pfeifer dot com
[not found] <20020925133600.8045.austern@apple.com>
2003-11-16 2:32 ` pinskia at gcc dot gnu dot org
2003-12-23 10:18 ` yotamm at mellanox dot co dot il
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).