What are the differences between Scrum and Kanban?
What are the differences between Scrum and Kanban?
October 25, 2022
What is the difference between regression and confirmation testing?
What is the difference between regression and confirmation testing?
November 8, 2022

November 1, 2022

[[maybe_unused]] attribute in C++17?

The [[maybe_unused]] attribute is created for indicating in code that certain logic might not be used. This is often linked to preprocessor conditions where this might be used or might not be used. As compilers can give warnings on unused variables, this is a way of suppressing them by indicating intent.

#include <cassert>
[[maybe_unused]] void f([[maybe_unused]] bool thing1, [[maybe unused]] bool thing2)
{
  [[maybe_unused]] bool b = thing1 && thing2; assert(b);
// in release mode, assert is compiled out and b is unused
// no warning because it is declared [[maybe_unused]] 
} // parameters thing1 and thing2 are not used, no warning

int main() {;}
[[maybe_unused]] attribute in C++17?
This website uses cookies to improve your experience. By using this website you agree to our Data Privacy Statement
Read more