C++11-style [[unused]] attribute in gcc?

后端 未结 3 1146
眼角桃花
眼角桃花 2021-01-01 12:59

Under gcc/g++ 4.9 I can write:

int x __attribute__((unused)) = f();

to indicate that x is intentionally unused.

Is it possible to d

3条回答
  •  误落风尘
    2021-01-01 13:40

    There is [[maybe_unused]] attribute in C++17. It's implemented in GCC 7, see C++ Standards Support in GCC .

    Example from P0212R1 proposal:

    [[maybe_unused]] void f([[maybe_unused]] bool thing1,
                            [[maybe_unused]] bool thing2) {
        [[maybe_unused]] bool b = thing1 && thing2;
        assert(b);
    }
    

提交回复
热议问题