Manoj Rao bio photo

Manoj Rao

Your Average Common Man

Email Twitter Github

Remember the annoying warnings that you feel helpless about? Well you shouldn’t because C++-11 introduced Attributes which are indicators to the compiler to either disable a warning or to flag a warning.

C++-17 introduced three main Attributes which are helpful.

[[nodiscard]]

As the name suggests, by annotating the code with [[nodiscard]] you are telling the compiler that the values returned should not be discarded. This is usefull when ignoring the returned value can cause errors in the program.

[[maybe_unused]]

In many cases, some of the variables or values allocated may not be used. Example for this are function parameters that are not used, or data members of a structure or a Class that are not used.

[[fallthrough]]

You have a switch statement and certain cases may not have an explicit break statement. In such cases, the compiler usually throws a warning. To avoid these warnings we should explicitly add [[fallthrough]] statements.

Source

C++17 - The Complete Guide


My Podcast!

If you like topics such as this then please consider subscribing to my podcast. I talk to some of the stalwarts in tech and ask them what their favorite productivity hacks are:

Available on iTunes Podcast

Visit Void Star Podcast’s page on iTunes Podcast Portal. Please Click ‘Subscribe’, leave a comment.

Get it iTunes