How to clear unused variable warnings created by static assert?

Jonathan Wakely jwakely.gcc@gmail.com
Thu Jul 23 16:50:00 GMT 2015


I've just filled in the unsubscribe form at
https://gcc.gnu.org/lists.html#subscribe for both papa@arbolone.ca and
arbolone@hotmail.ca since it's apparently too difficult for some
people to manage on their own.

On 23 July 2015 at 17:45, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> And I've explained how to unsubscribe many times:
>
> https://gcc.gnu.org/ml/gcc-help/2015-07/msg00043.html
>
>
>
> On 23 July 2015 at 15:47,  <papa@arbolone.ca> wrote:
>> I have unsubscribe many, many times, but you have a serious problem
>> receiving the message. I am papa@arbolone.ca, please, please unsubscribe me.
>> This mailing list is useless to me, if this continues I will take more
>> offensive action, which is something both of us are trying to avoid.
>>
>> If you are reading this email, but you are not gcc-help administrator,
>> please, please, forward this email to the administrator or simple reply to
>> all. GCC-help should know what to do with this message. Thanks in advance
>> and please forgive me for any inconvenience.
>>
>> -----Original Message----- From: Jeffrey Walton
>> Sent: Thursday, July 23, 2015 8:50 AM
>> To: gcc-help@gcc.gnu.org
>> Subject: How to clear unused variable warnings created by static assert?
>>
>>
>> Our project has a static assert.  Its creating a noisy output at -Wall
>> and above. We attempted to manage it with a GCC diagnostic block, but
>> its not quite meeting expectations. The static assert creates a bunch
>> of unused variable warnings.
>>
>> We have a UNUSED macro that casts to a void (its the only portable way
>> I know to clear an unused warning), but we don't have a variable name
>> to use with it.
>>
>> How can we clear a warning like `unused variable 'assert_26'
>> [-Wunused-variable]|`?
>>
>> **********
>> Here's the static assert:
>>
>> template <bool b>
>> struct CompileAssert
>> {
>>    static char dummy[2*b-1];
>> };
>>
>> #define COMPILE_ASSERT(assertion) COMPILE_ASSERT_INSTANCE(assertion,
>> __LINE__)
>> #define COMPILE_ASSERT_INSTANCE(assertion, instance) static
>> CompileAssert<(assertion)> ASSERT_JOIN(assert_, instance)
>> #define ASSERT_JOIN(X, Y) DO_ASSERT_JOIN(X, Y)
>> #define DO_ASSERT_JOIN(X, Y) X##Y
>>
>> **********
>> Here's how we try to manage it in one of out header files:
>>
>> #ifndef FOO_BAR
>> #define FOO_BAR
>>
>> #define GCC_OPTIMIZE_AWARE ((__GNUC__ > 4 || (__GNUC__ == 4 &&
>> __GNUC_MINOR__ >= 7)) || defined(__clang__))
>>
>> #if GCC_DIAGNOSTIC_AWARE
>> # pragma GCC diagnostic push
>> # pragma GCC diagnostic ignored "-Wunused-value"
>> # pragma GCC diagnostic ignored "-Wunused-variable"
>> #endif
>>
>> ....
>> COMPILE_ASSERT(foo == bar);
>>
>> #if GCC_DIAGNOSTIC_AWARE
>> # pragma GCC diagnostic pop
>> #endif
>>
>> #endif // FOO_BAR
>>
>> **********
>>
>> Users include the header file, so we have no control over which
>> options they place on the command line.
>>
>> Here's an example of the warning it generates with -Wall and GCC 4.8
>> (even when guarded like above):
>>
>>    unused variable 'assert_26' [-Wunused-variable]|



More information about the Gcc-help mailing list