Consider the testcase below.

$ cat test.cpp
namespace x {
        extern const char ** const foo;
        extern const char ** const bar;
};

using namespace x;

namespace {
        const char* X;
};

const char ** const foo = &X;
const char ** const x::bar = &X;

$ g++ test.cpp -Wall -Wunused -Wextra -c -o test.o
$ nm test.o | c++filt
0000000000000000 b (anonymous namespace)::X
0000000000000000 R x::bar

foo is completely removed from the output, and no warning is shown.

It would be useful to show a warning here.

For example in the above testcase I forgot to add the x:: namespace qualifier
to foo (the extern declaration was in a header and I didn't notice it was part
of a namespace). 
Since I didn't get any warning, I got a linker error, and had to spend some
time tracing down this typo in my code.
Had I seen a warning from the compiler that 'foo' is not used
and will get removed I would have immediately noticed the absence of the x::
namespace qualifier.


-- 
           Summary: show a warning when a symbol is unused and completely
                    removed from the output file
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: edwintorok at gmail dot com
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


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

Reply via email to