Top-level constexprs in header files should be inline
#4,063 opened on Apr 2, 2022
Repository metrics
- Stars
- (1,813 stars)
- PR merge metrics
- (PR metrics pending)
Description
When we declare a static constexpr, it means that the value will be present in each compilation unit i.e. each object generated with a cpp file. That means, if a static constexpr is declared in a header file, that every cpp file that includes that header (even indirectly) will have it's own copy of that value.
It can be seen that, if static is removed, the compiler will detect the name clash (which is avoided by static).
These top-level constexprs present in header files should be inline, such that the declarations are merged when the executable is linked and only 1 copy will be present.
Tip: search using regex for ^static constexpr in src/*.h