Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#7242 closed Bugs (fixed)

GCC 4.8 warns unused local typedef

Reported by: Kohei Takahashi <flast@…> Owned by: John Maddock
Milestone: To Be Determined Component: static_assert
Version: Boost Release Branch Severity: Problem
Keywords: Cc:

Description

GCC 4.8 warns unused local typedef. see followings.

$ cat hoge.cpp
#include <boost/static_assert.hpp>

int main()
{
    BOOST_STATIC_ASSERT(true);
}
$ g++-4.8.0 -Wall -Iboost-trunk hoge.cpp
In file included from boost-trunk/boost/config.hpp:57:0,
                 from boost-trunk/boost/static_assert.hpp:17,
                 from hoge.cpp:1:
hoge.cpp: In function 'int main()':
boost-trunk/boost/static_assert.hpp:125:21: warning: typedef 'boost_static_assert_typedef_5' locally defined but not used [-Wunused-local-typedefs]
          BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
                     ^
hoge.cpp:5:5: note: in expansion of macro 'BOOST_STATIC_ASSERT'
     BOOST_STATIC_ASSERT(true);
     ^

To suppress this warnings, append __attribute__((unused)).

Change History (7)

comment:1 by larsbj@…, 10 years ago

Have you actually tried to use __attribute__((unused)) to suppress these warnings? I can not make it work.

comment:2 by Kohei Takahashi <flast@…>, 10 years ago

I tried followings, and it works for me.

#include <boot/static_assert.hpp>

int main()
{
	BOOST_STATIC_ASSERT(true) __attribute__((unused));
}

However, in some cases seems doesn't work and I think it's GCC defect. I'll try to narrow down the cause and report it to GCC bugzilla.

comment:3 by Kohei Takahashi <flast@…>, 10 years ago

The GCC defects fixed in trunk; http://gcc.gnu.org/PR54372 . The solution works well, now.

comment:4 by John Maddock, 10 years ago

Resolution: fixed
Status: newclosed

(In [82886]) Use variadic macros in static assert to make use easier. Add warning suppression for GCC. Minor doc fix. Fixes #5810. Fixes #7242. Fixes #7966.

comment:5 by laurent.rineau__boost_trac@…, 10 years ago

Will that patch be included in version 1.54?

comment:6 by anonymous, 10 years ago

Should be yes.

comment:7 by anonymous, 7 years ago

I see the same warning with clang-3.6.1.

The GCC syntax:

__attribute__((unused))

is accepted by clang, at least since clang-3.4. I suggest to adapt the following lines, of boost/static_assert.hpp so that clang>=3.4 is also taken into account:

#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
#  define BOOST_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
#else
#  define BOOST_STATIC_ASSERT_UNUSED_ATTRIBUTE
#endif

Should I open a new ticket?

Note: See TracTickets for help on using tickets.