Suppress unused variable warning in C++ => Compiler bug or code bug?

后端 未结 5 1111
無奈伤痛
無奈伤痛 2021-01-04 10:04

Presently, I am using the following function template to suppress unused variable warnings:

template
void
unused(T const &) {
  /* Do n         


        
5条回答
  •  情话喂你
    2021-01-04 11:01

    In GCC, you can define a macro as follows:

    #ifdef UNUSED
    #elif defined(__GNUC__)
    # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
    #elif defined(__LCLINT__)
    # define UNUSED(x) /*@unused@*/ x
    #else
    # define UNUSED(x) x
    #endif 
    

    Any parameters marked with this macro will suppress the unused warning GCC emits (and renames the parameter with a prefix of UNUSED_). For Visual Studio, you can suppress warnings with a #pragma directive.

提交回复
热议问题