How to test static_assert?
summary
Shows a concrete pattern that makes compile-time checks testable by ripping the condition out of static_assert into a type that either fires unconditionally or is harmless, then using tag dispatch plus a failure-return type (implemented as small rep_static_assert structs generated by a macro). Applied to sqlpp11 (≈100 static_asserts), this lets one-line compile-time tests live in a single file instead of thousands of failing-compile files, works around divergent Clang/GCC/MSVC diagnostics, and remains compatible with C++17 features like if constexpr and concepts.
AI-written summary · about
chapters (11)
- 0:00Start
- 0:21Kiss Templates
- 5:39Basic Approaches
- 9:35Blending Diagnostic Messages
- 15:35Tag Dispatch
- 19:06Determining the Return Type Automatically
- 20:30Testing the Static Assert
- 28:15Return Type
- 32:48Summary
- 41:28Testability
- 42:27Compiler Generated Return Type
related talks
01h 29mTesting Everything in Constexpr
53mPruning Error Messages From Your C++ Template Code
31mTesting Compile-time Constructs in a Runtime Unit Testing Framework
01h 02mImplementing `static` control flow in C++14
01h 40mTesting, Preconditions, Coverage and Templates in Safety-Critical C++ Code
01h 04mconstexpr: Introduction
01h 01m“Static Analysis and C++: More Than Lint"
01h 00mconstexpr: Applications
