3

I am using GNU gcc 4.6.2 on Fedora 16. I am writing an application using a 3rd party API, after compilation, I got a lot warnings.

warning: ‘typedef’ was ignored in this declaration [enabled by default]

Just wondering how can I suppress this? I compile my program with -Wall flag.

In this doc, http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html, it mentioned something like -Wunused-local-typedefs.

I have tried -Wno-unused-local-typedefs, but doesn't work.

Thanks.

2607
  • 4,037
  • 13
  • 49
  • 64
  • 9
    Can you show an example declaration that causes that warning? – aschepler Mar 06 '12 at 16:15
  • http://stackoverflow.com/questions/6399898/is-the-typedef-name-optional-in-a-typedef-declaration shows a variety of examples that emit that warning. – Mark B Mar 06 '12 at 16:28
  • What is the 3rd party API? Was it written in C or C++? Perhaps this can help you: http://stackoverflow.com/questions/913344/how-can-i-remove-the-vs-warning-c4091-typedef-ignored-on-left-of-spreadsh ? – CygnusX1 Mar 06 '12 at 16:25
  • 1
    If you get that warning, it probably means you should remove the `typedef` keyword from the declaration. If the warning points to third party code, consider informing the author(s). – Keith Thompson Mar 06 '12 at 18:01

6 Answers6

10

-Wno-unused-local-typedefs works in GCC 4.8.

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
Andres Kievsky
  • 3,461
  • 32
  • 25
  • 1
    What's the point of your answer? Say that this is a bug in the old compiler? That he is using the option the wrong way? It doesn't help the original poster in any way... – mozzbozz Sep 11 '14 at 12:15
  • 1
    Please re-read the original question and how it ties to my answer. – Andres Kievsky Sep 11 '14 at 20:48
  • 4
    Probably we are at cross purposes... What I see is: The questioner is asking how to disable the warning. And that "-Wno-unused-local-typedefs" does not work for him. Yet you answer in only one line: "-Wno-unused-local-typedefs works in gcc 4.8 for me". I was wondering now what you were trying to imply (I didn't want to offend you, just wanted a clarification) ;) It would be much clearer if you'd answer with a few more words and not just a one-liner... I reread the question and the answer multiple times now and still don't get the message you try to deliver with your answer? rgds – mozzbozz Sep 12 '14 at 12:44
8

gcc allows you to specify that certain library include paths should be treated as system libraries with the -isystem switch which allows those headers special treatment with respect to the flags you use on the rest of your code. So for example if you have unused local typedefs from using certain Boost libraries in test.cpp (I ran into this using including the Boost signals2 library recently)

g++ -o test{,.cpp} -Wall -Wextra -Werror -I /usr/local/boost-1.55.0/include -L /usr/local/boost-1.55.0/lib

and the above does not build cleanly try the following

g++ -o test{,.cpp} -Wall -Wextra -Werror -isystem /usr/local/boost-1.55.0/include -L /usr/local/boost-1.55.0/lib

which will (provided the warnings coming from the Boost libraries you are including in test.cpp are your only problem of course).

bpw1621
  • 2,962
  • 2
  • 32
  • 35
7

According to the gcc-source-code(gcc/cp/decl.c:4108):

warning (0, "%<typedef%> was ignored in this declaration"); 

There is no command line flag(that is what the 0 stands for) to suppress this warning in gcc 4.6.2.

x539
  • 1,006
  • 6
  • 16
1

As -Wunused-local-typedefs is part of -Wall, make sure you don't have -Wall after -Wno-unused-local-typedefs. If you do, -Wall just turns the option back on again.

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
Johan
  • 266
  • 3
  • 5
0

In C++17, you should use [[maybe_unused]].

For an overview of all attributes, please see http://en.cppreference.com/w/cpp/language/attributes.

Proposal: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0212r0.pdf

(sorry, I could't post an example, as it's considered as badly indented by stackoverflow)

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
guest
  • 17
  • 1
  • 1
    `maybe_unused` doesn't work for gcc (Debian 6.3.0-18) 6.3.0 20170516. However, `__attribute__((unused))` works. Unused typedefs are typically used for [C static assertions](https://stackoverflow.com/questions/3385515/static-assert-in-c). – Ale Dec 14 '17 at 15:31
0

This GCC warning means that your typedef maybe duplicated and you should remove typedef keyword instead. For example:

typedef enum class Something {
  THING1,
  THING2,
} Something;

This code above is type duplicate, because enum class is defined as type already. So you must remove typedef keyword as well as Something at the end too!

Fading
  • 51
  • 3