Properties of C++ template metaprograms ∗

Verifying properties of programs is a common way to ensure the proper behaviour of those programs. Invariants, pre- and postconditions are program properties often used when proving correctness of programs. C++ template metaprograms (TMPs) are special progams interpreted by the compiler. Metaprograms are widely used for the following purposes: executing algorithms in compile-time, optimizing runtime pro grams and emitting compilation errors and warnings to enforce certain semantic checks. In this paper we step to “meta-meta-level”: we present a tech nique to make safer C++ TMPs with static asserts. We describe how to check invariants, pre- and postconditions of TMPs and enforce the co mpiler to refuse metaprograms if any of the specified program properties is dissatisfied. We present some examples where semantic errors in TMPs are revealed by our method.