public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41134]  New: [4.5 regression] Variable flagges unused if only used in template function
@ 2009-08-20 20:44 bangerth at gmail dot com
  2009-08-20 20:45 ` [Bug c++/41134] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bangerth at gmail dot com @ 2009-08-20 20:44 UTC (permalink / raw)
  To: gcc-bugs

Here's yet another case of a variable that is flagged as unused when it is
actually referenced. I agree that this is a corner case: the variable 
really *is* unused, the template function is not instantiated after all.
That said, this is not an uncommon idiom, the code is extracted from the
Threading Building Blocks library.

-------------------------------
static int i;
template <typename> int f() { return i; }
----------------------------------

deal.II> c++ -W -Wunused -c x.cc
x.cc:1:12: warning: 'i' defined but not used


W.


-- 
           Summary: [4.5 regression] Variable flagges unused if only used in
                    template function
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bangerth at gmail dot com


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


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

* [Bug c++/41134] [4.5 regression] Variable flagges unused if only used in template function
  2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
@ 2009-08-20 20:45 ` pinskia at gcc dot gnu dot org
  2009-08-20 20:47 ` [Bug c++/41134] [4.5 regression] Variable flagged " bangerth at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-08-20 20:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-08-20 20:44 -------
Well this is invalid code that is accepted by GCC anyways ....


-- 


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


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

* [Bug c++/41134] [4.5 regression] Variable flagged unused if only used in template function
  2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
  2009-08-20 20:45 ` [Bug c++/41134] " pinskia at gcc dot gnu dot org
@ 2009-08-20 20:47 ` bangerth at gmail dot com
  2009-08-20 20:50 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at gmail dot com @ 2009-08-20 20:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bangerth at gmail dot com  2009-08-20 20:47 -------
(In reply to comment #1)
> Well this is invalid code that is accepted by GCC anyways ....

How so??


-- 


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


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

* [Bug c++/41134] [4.5 regression] Variable flagged unused if only used in template function
  2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
  2009-08-20 20:45 ` [Bug c++/41134] " pinskia at gcc dot gnu dot org
  2009-08-20 20:47 ` [Bug c++/41134] [4.5 regression] Variable flagged " bangerth at gmail dot com
@ 2009-08-20 20:50 ` pinskia at gcc dot gnu dot org
  2009-08-20 20:54 ` bangerth at gmail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-08-20 20:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2009-08-20 20:49 -------
You cannot use a static variable in a template :).
Note the following is valid though:
namespace { int i; }
template <typename> int f() { return i; }

And still invokes the warning:
t4.cc:1:17: warning: '<unnamed>::i' defined but not used


-- 


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


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

* [Bug c++/41134] [4.5 regression] Variable flagged unused if only used in template function
  2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
                   ` (2 preceding siblings ...)
  2009-08-20 20:50 ` pinskia at gcc dot gnu dot org
@ 2009-08-20 20:54 ` bangerth at gmail dot com
  2009-08-20 21:11 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at gmail dot com @ 2009-08-20 20:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bangerth at gmail dot com  2009-08-20 20:54 -------
(In reply to comment #3)
> You cannot use a static variable in a template :).

I would be unaware of that restriction. It's true that you can't use objects
with internal linkage (such as static variables) as *template arguments* but
I would be surprised if you couldn't use them in the body of a template
function. That said, this point is tangential to what I wanted to say with
this PR, and your little programs makes my point as eloquently as my original
one ;-)

W.


-- 


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


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

* [Bug c++/41134] [4.5 regression] Variable flagged unused if only used in template function
  2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
                   ` (3 preceding siblings ...)
  2009-08-20 20:54 ` bangerth at gmail dot com
@ 2009-08-20 21:11 ` rguenth at gcc dot gnu dot org
  2009-08-20 21:20 ` bangerth at gmail dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-20 21:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2009-08-20 21:11 -------
Why is this a regression?  Which compiler version didn't warn here?

The question is really whether we want unused variables just in the case
where we can remove it and without further changes the program is still
valid or if we want to detect more elaborate cases where the programmer
can remove a variable with some extra work.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.5.0


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


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

* [Bug c++/41134] [4.5 regression] Variable flagged unused if only used in template function
  2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
                   ` (4 preceding siblings ...)
  2009-08-20 21:11 ` rguenth at gcc dot gnu dot org
@ 2009-08-20 21:20 ` bangerth at gmail dot com
  2009-08-21 21:47 ` jason at gcc dot gnu dot org
  2009-08-24 21:32 ` jason at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at gmail dot com @ 2009-08-20 21:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from bangerth at gmail dot com  2009-08-20 21:20 -------
(In reply to comment #5)
> Why is this a regression?  Which compiler version didn't warn here?

4.3.2. Current mainline warns.


> The question is really whether we want unused variables just in the case
> where we can remove it and without further changes the program is still
> valid or if we want to detect more elaborate cases where the programmer
> can remove a variable with some extra work.

Right, and I don't have the answer. All I'm saying is: this is, in a nutshell,
one of the header files of the threading building blocks. I used to be able
to compile my program with that file included with -W -Wunused and not get
a warning, but now I do get a warning if I happen to not use the template
function that is defined in the header file.

W.


-- 


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


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

* [Bug c++/41134] [4.5 regression] Variable flagged unused if only used in template function
  2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
                   ` (5 preceding siblings ...)
  2009-08-20 21:20 ` bangerth at gmail dot com
@ 2009-08-21 21:47 ` jason at gcc dot gnu dot org
  2009-08-24 21:32 ` jason at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-08-21 21:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jason at gcc dot gnu dot org  2009-08-21 21:47 -------


*** This bug has been marked as a duplicate of 41109 ***


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


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

* [Bug c++/41134] [4.5 regression] Variable flagged unused if only used in template function
  2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
                   ` (6 preceding siblings ...)
  2009-08-21 21:47 ` jason at gcc dot gnu dot org
@ 2009-08-24 21:32 ` jason at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-08-24 21:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jason at gcc dot gnu dot org  2009-08-24 21:32 -------
Subject: Bug 41134

Author: jason
Date: Mon Aug 24 21:31:54 2009
New Revision: 151061

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151061
Log:
        PR c++/41109
        PR c++/41110
        PR c++/41134
        * cp-tree.h (DECL_ODR_USED): New macro.
        (struct lang_decl_base): Add odr_used flag.
        * decl.c (duplicate_decls): Propagate it.  Use it for error.
        * pt.c (register_specialization): Use it for error.
        * decl2.c (mark_used): Use it as gating flag rather than TREE_USED.
        (cp_write_global_declarations): Use it for error.
        (tree_used_ok): Remove.
        * cp-tree.h: Remove tree_used_ok.
        * call.c (build_call_a): Don't call it.
        * init.c (build_offset_ref): Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wunused-17.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/decl2.c
    trunk/gcc/cp/init.c
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

end of thread, other threads:[~2009-08-24 21:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-20 20:44 [Bug c++/41134] New: [4.5 regression] Variable flagges unused if only used in template function bangerth at gmail dot com
2009-08-20 20:45 ` [Bug c++/41134] " pinskia at gcc dot gnu dot org
2009-08-20 20:47 ` [Bug c++/41134] [4.5 regression] Variable flagged " bangerth at gmail dot com
2009-08-20 20:50 ` pinskia at gcc dot gnu dot org
2009-08-20 20:54 ` bangerth at gmail dot com
2009-08-20 21:11 ` rguenth at gcc dot gnu dot org
2009-08-20 21:20 ` bangerth at gmail dot com
2009-08-21 21:47 ` jason at gcc dot gnu dot org
2009-08-24 21:32 ` jason at gcc dot gnu dot 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).