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