Fun with (user-defined) attributes

Speaker: Jonathan Müller

Audience level: Intermediate | Advanced

category

C++11 added a generalized attribute syntax to annote your code with additional information - basically comments that your compiler will read. It also standardized a couple of attributes. C++14 and 17 went on to add more standardized attributes. But C++17 also added another feature regarding attributes, often overlooked: Compilers are now required to completely ignore attributes they don't know without issuing any diagnostic.

That opens the door to the realm of custom, user-defined attributes. You can now define your own attributes and use them for your own tools!

In this talk, we'll explore what is possible with user-defined attributes. We'll take a look how custom attributes can be used for static analyzers, documentation generators and libraries. But most importantly, we will write our own parser for custom attributes and use it for boilerplate code generation - enum to string conversion, serialization, ... - or emulation of possible future language features like comparisons by default.

Video