When should I use [[maybe_unused]]?

后端 未结 2 1772
情话喂你
情话喂你 2020-12-15 03:31

What is good about using [[maybe_unused]]? Consider

int winmain(int instance, int /*prevInstance*/, const char */*cmdline*/, int show);

int win         


        
2条回答
  •  隐瞒了意图╮
    2020-12-15 04:20

    If the parameter is definitely unused, [[maybe_unused]] is not particularly useful, unnamed parameters and comments work just fine for that.

    [[maybe_unused]] is mostly useful for things that are potentially unused, like in

    void fun(int i, int j) {
        assert(i < j);
        // j not used here anymore
    }
    

    This can't be handled with unnamed parameters, but if NDEBUG is defined, will produce a warning because j is unused.

    Similar situations can occur when a parameter is only used for (potentially disabled) logging.

提交回复
热议问题