Suppress Compiler warning Function declared never referenced

前端 未结 9 781
你的背包
你的背包 2020-12-30 01:51

So i have some code like this:

void foo (int, int);

void bar ( )
{
    //Do Stuff

   #if (IMPORTANT == 1)
       foo (1, 2);
   #endif

}

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 01:58

    In C++17 you can declare your function with [[maybe_unused]]:

    [[maybe_unused]] void foo (int, int);
    

    This will suppress the warning and is the correct, idiomatic way to express a possibly unused function in C++17.

提交回复
热议问题