Language feature: Attributes


Attributes are something that provides some warnings or restraints to the compiler, and inform the reader of the specific situation.

The following attributes were defined in C++14 and C++17:


Indicates that the use of the name or entity declared with this attribute is allowed, but discouraged for some reason. The string literals that can be added into the expression can be used to advice on alternatives.


In case we don’t add break between cases, fallthrough will occur, and the compiler will complain about this. In order to assure it that we know what we’re doing (Both the compiler and the reader of this code), we can use the fallthrough attribute.


Nodiscard advices the compiler to throw a warning in case we do not interrogate the return value of a function marked with nodiscard.


The attribute suppresses the compiler warning for the parameters and locals that are there but they are not unused in the code.

You may also like...

Leave a Reply