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

后端 未结 5 1110
無奈伤痛
無奈伤痛 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 10:53

    The actual way of indicating you don't actually use a parameter is not giving it a name:

    int f(int a, float) {
         return a*2;
    }
    

    will compile everywhere with all warnings turned on, without warning about the unused float. Even if the argument does have a name in the prototype (e.g. int f(int a, float f);), it still won't complain.

提交回复
热议问题