-
Define constant static template members as constexpr · 3fc930f1Nicolas Capens authored
The static Opcode and Emitter members of the InstImpl<> template class have constant values, so we can make them constexpr and define them in the header. Note that we can't make them constexpr in the template class definition, since that requires in-class initialization, and GCC considers the definition of the static members of the concrete instantiations to be doing duplicate initialization (this might be a compiler bug, since Clang and MSVC allow it). Fortunately, constexpr is a specifier, which implies const, a qualifier, meaning a definition which is constexpr is compatible with a declaration which is only const. Declaring them as const in the class has the added benefit that if we instantiated the template without providing initialization of these members, we'd get a compilation error instead of using the in-class initializer of the primary template. Note also that defining these static members in the header doesn't lead to multiple definition errors because in C++17, static constexpr member variables are implicitly inline. Lastly, constexpr applied to a pointer affects the pointer value itself, not the pointee, so "constexpr const char *s" is a constexpr pointer to const characters. Thus while constexpr implies const, the second const isn't redundant because it applies to the pointee type. Bug: b/192890685 Change-Id: Ia7c6a889d08007d42393979f3b08bcfc5fa8c614 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/55428 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by:
Nicolas Capens <nicolascapens@google.com> Reviewed-by:
Alexis Hétu <sugoi@google.com>
3fc930f1
×