COIN-OR::LEMON - Graph Library

Opened 11 years ago

Closed 11 years ago

#470 closed defect (fixed)

"Unused locally defined typedef" warning with gcc 4.8

Reported by: Alpar Juttner Owned by: Alpar Juttner
Priority: critical Milestone: LEMON 1.3 release
Component: core Version: hg main
Keywords: Cc:
Revision id:

Description

The warnings look very stupid, but makes Maintainer more fail.

Is there a compiler pragma for switching off this warning locally?

/home/alpar/projects/LEMON/hg/cplex-comp/lemon/core.h:109:38: warning: typedef ‘OutArcIt’ locally defined but not used [-Wunused-local-typedefs]
   typedef typename Digraph::OutArcIt OutArcIt;                          \
                                      ^
/home/alpar/projects/LEMON/hg/cplex-comp/lemon/core.h:143:3: note: in expansion of macro ‘TEMPLATE_DIGRAPH_TYPEDEFS’
   TEMPLATE_DIGRAPH_TYPEDEFS(Graph);                                     \
   ^
/home/alpar/projects/LEMON/hg/cplex-comp/test/graph_test.cc:34:3: note: in expansion of macro ‘TEMPLATE_GRAPH_TYPEDEFS’
   TEMPLATE_GRAPH_TYPEDEFS(Graph);
   ^
/home/alpar/projects/LEMON/hg/cplex-comp/lemon/core.h:110:52: warning: typedef ‘BoolNodeMap’ locally defined but not used [-Wunused-local-typedefs]
   typedef typename Digraph::template NodeMap<bool> BoolNodeMap;         \
                                                    ^

Change History (8)

comment:1 Changed 11 years ago by Alpar Juttner

It is not that easy. The point is that [TEMPLATE_]GRAPH_TYPEDEFS provides a bunch of convenience typedefs, many of which will be unused, of course.

First I tried to write something similar to ignore_unused_variable_warning(v) like this:

  template <class T> inline void ignore_unused_local_typedef()
  { 
    T *var;
    ignore_unused_variable_warning(var);
  }

It works well for local typedefs. However, TEMPLATE_GRAPH_TYPEDEFS may also be used outside a function body (e.g. in a class or in the global scope), when the above solution fails.

Then, I tried to use a #pragma directive to switch this warning off locally, something like:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
...
#pragma GCC diagnostic pop

However, #pragma cannot be used within #define. There are compiler dependent alternatives (_Pragma(...) on gcc, __pragma(...) on VC), but I couldn't have it worked.

So, currently the only solution I could find is to globally switch this warning off in lemon/core.h with

#pragma GCC diagnostic ignored "-Wunused-local-typedefs"

What do you think?

comment:2 in reply to:  1 Changed 11 years ago by Alpar Juttner

Replying to alpar:

So, currently the only solution I could find is to globally switch this warning off in lemon/core.h with

#pragma GCC diagnostic ignored "-Wunused-local-typedefs"

I merge this to branches 1.1, 1.2 and default, see [756022ac1674]

comment:3 Changed 11 years ago by Balazs Dezso

The changeset looks good to me.

comment:4 in reply to:  3 Changed 11 years ago by Alpar Juttner

Resolution: fixed
Status: newclosed

Replying to deba:

The changeset looks good to me.

I close this ticket, then.

comment:5 Changed 11 years ago by Peter Kovacs

Resolution: fixed
Status: closedreopened

I reopened this ticket because it seems that this solution causes a compiler warning with GCC 4.5.x:

lemon/core.h:42:32: warning: unknown option after ‘#pragma GCC diagnostic’ kind

Can we avoid this warning? Or is it acceptable?

comment:6 in reply to:  5 Changed 11 years ago by Alpar Juttner

Replying to kpeter:

Can we avoid this warning?

Yes we can, by applying the #pragma only to gcc version >=4.8. It is done in [6039b32a2351]. Futhermore, [115031ac8001] adds two other gcc backward compatibility fixes. Both chgsets are merged to branches 1.1, 1.2, and the main one.

Now, all these branches compiles in Maintainer mode with

  • GNU GCC versions 3.3, 4.3, 4.5, 4.7 and 4.8 and
  • Intel C++ 2011 and 2013

Or is it acceptable?

Not really. In fact, the Maintainer build mode converts all the warnings to errors.

comment:7 Changed 11 years ago by Peter Kovacs

Great. I think we can close this ticket again.

comment:8 Changed 11 years ago by Alpar Juttner

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.