RTTI in C++: typeid, dynamic_cast, type_info and When Not to Use Them

typeid and dynamic_cast in C++: what they report, what they cost and when a virtual function or std::variant does the same job better.

A magnifying glass over one of three identical boxes, revealing a blue circle inside, with a green check mark

A function receives a Shape&. Is it a circle? Most of the time the right answer is “it should not matter”: call a virtual function and let the object decide. But sometimes code really does need to know the concrete type behind a base-class pointer, to unwrap a plugin, handle one special case or count objects by kind. C++ answers that question at run time with RTTI.

This guide covers the two RTTI operators, typeid and dynamic_cast, along with std::type_info and std::type_index, what they cost and the designs that usually make them unnecessary. Every program below was compiled and tested with GCC, Clang and MSVC (C++17 and C++20, warnings as errors), and each output is captured verbatim.

The Short Answer

What is RTTI in C++? Run-time type identification: the language features that report an object’s actual (dynamic) type while the program runs. They are typeid, which returns a std::type_info describing a type, and dynamic_cast, which converts a pointer or reference along a class hierarchy after checking that the object really has the target type.

When does RTTI work? Only for polymorphic classes, meaning classes with at least one virtual function. For other types, typeid reports the static type and dynamic_cast does not compile.

Should I use it? Sparingly. A virtual function or std::variant usually expresses the same logic better. dynamic_cast is the right tool for cross-casting between interfaces and for code that cannot change the class hierarchy.

What Is RTTI in C++?

RTTI (run-time type identification) is the C++ mechanism that lets a program discover the dynamic type of an object through a pointer or reference to a base class. The compiler stores type information for every polymorphic class, usually next to its virtual function table, and typeid and dynamic_cast read it at run time.

Two terms matter throughout:

  • Static type: the type the compiler sees in the declaration. In Shape& shape = circle;, the static type of shape is Shape.
  • Dynamic type: the type of the object actually there at run time, here Circle. Only polymorphic classes carry enough information to recover it.

The three tools, side by side:

ToolAnswersResult on failureNeeds a polymorphic class
typeid(expr)“What exactly is this object’s type?”Throws std::bad_typeid for a null pointer dereferenceFor the dynamic type, yes; otherwise it reports the static type
dynamic_cast<T*>(p)“Can I treat this object as a T?”nullptrYes (it does not compile otherwise)
dynamic_cast<T&>(r)The same, for a referenceThrows std::bad_castYes
static_cast<T*>(p)Not a question: the programmer asserts the answerNo check; a wrong cast is undefined behaviorNo
Where RTTI finds the dynamic type Shape& shape static type: Shape what the compiler sees the Circle object in memory vtable pointer Circle data members dynamic type: Circle Circle class data type_info: Circle base classes: Shape virtual functions typeid(shape) follows the vtable pointer and returns the type_info for Circle. Comparing two results: 1 to 5 ns. dynamic_cast<T*>(p) reads the same data, then searches the base classes for T; nullptr if absent. Cost depends on the search: 3 to 57 ns. A class with no virtual functions has no vtable pointer, so there is nothing to read: typeid reports the static type and dynamic_cast does not compile.
Figure 1: typeid and dynamic_cast read type information that the compiler stores for every polymorphic class (simplified; the exact layout depends on the compiler). Timings from the benchmark below.

typeid and std::type_info

typeid takes a type or an expression and returns a reference to a std::type_info object. Two type_info objects compare equal exactly when they describe the same type.

The only portable things to do with a type_info are compare it, hash it and print its name(). The name itself is implementation-defined: GCC and Clang return a mangled name (7PolyDer), and MSVC returns class PolyDer. The examples print names through a small helper that demangles on GCC and Clang and drops MSVC’s class or struct prefix, so the output is the same on every compiler:

// type_name.h - a readable class name from std::type_info.
//
// type_info::name() is implementation-defined: GCC and Clang return a mangled
// name ("7PolyDer"), MSVC returns "class PolyDer" or "struct PolyDer". This
// helper demangles on GCC and Clang and drops MSVC's "class "/"struct " prefix,
// so the programs print the same text everywhere.
#pragma once

#include <cstdlib>
#include <memory>
#include <string>
#include <typeinfo>

#if defined(__GNUG__)
#include <cxxabi.h>
#endif

inline std::string readable_name(const std::type_info& type)
{
    std::string name = type.name();
#if defined(__GNUG__)
    int status = 0;
    std::unique_ptr<char, void (*)(void*)> demangled(
        abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free);
    if (status == 0 && demangled)
        name = demangled.get();
#endif
    for (const char* prefix : {"class ", "struct "})
        if (name.rfind(prefix, 0) == 0)
            name.erase(0, std::string(prefix).size());
    return name;
}

The first program shows what typeid reports in each case:

// typeid_basics.cpp - what typeid reports for polymorphic and
// non-polymorphic classes, and how std::type_index makes types usable as keys.
#include "type_name.h"

#include <iostream>
#include <map>
#include <memory>
#include <typeindex>
#include <typeinfo>
#include <vector>

// Polymorphic: has a virtual function, so objects carry their dynamic type.
struct Shape {
    virtual ~Shape() = default;
};
struct Circle : Shape {};
struct Square : Shape {};

// Not polymorphic: no virtual functions, so typeid sees only the static type.
struct Plain {};
struct PlainDerived : Plain {};

int main()
{
    Circle circle;
    Shape& shape = circle;
    std::cout << "static type of shape:        " << readable_name(typeid(Shape)) << '\n';
    std::cout << "typeid(shape) (polymorphic): " << readable_name(typeid(shape)) << '\n';

    PlainDerived derived;
    Plain& plain = derived;
    std::cout << "typeid(plain) (not polymorphic): " << readable_name(typeid(plain)) << '\n';

    // Top-level const and references are ignored.
    std::cout << std::boolalpha;
    std::cout << "typeid(const Circle) == typeid(Circle):  " << (typeid(const Circle) == typeid(Circle)) << '\n';
    std::cout << "typeid(Circle&) == typeid(Circle):       " << (typeid(Circle&) == typeid(Circle)) << '\n';
    std::cout << "typeid(shape) == typeid(Circle):         " << (typeid(shape) == typeid(Circle)) << '\n';

    // typeid on a null pointer to a polymorphic type throws std::bad_typeid.
    Shape* nothing = nullptr;
    try {
        std::cout << readable_name(typeid(*nothing)) << '\n';
    } catch (const std::bad_typeid&) {
        std::cout << "typeid(*nullptr) threw std::bad_typeid\n";
    }

    // std::type_index wraps type_info so it can be a map key.
    std::vector<std::unique_ptr<Shape>> shapes;
    shapes.push_back(std::make_unique<Circle>());
    shapes.push_back(std::make_unique<Square>());
    shapes.push_back(std::make_unique<Circle>());
    std::map<std::type_index, int> counts;
    for (const auto& s : shapes) {
        const Shape& current = *s;    // typeid(*s) would call unique_ptr::operator* inside typeid
        ++counts[typeid(current)];
    }
    std::cout << "circles: " << counts[typeid(Circle)] << ", squares: " << counts[typeid(Square)] << '\n';
}

Output (identical with GCC, Clang and MSVC):

static type of shape:        Shape
typeid(shape) (polymorphic): Circle
typeid(plain) (not polymorphic): Plain
typeid(const Circle) == typeid(Circle):  true
typeid(Circle&) == typeid(Circle):       true
typeid(shape) == typeid(Circle):         true
typeid(*nullptr) threw std::bad_typeid
circles: 2, squares: 1

Four rules come out of this:

  • Polymorphic classes report the dynamic type. typeid(shape) is Circle, because Shape has a virtual destructor.
  • Other classes report the static type. typeid(plain) is Plain even though the object is a PlainDerived. No error, no warning: just a different answer.
  • Top-level const and references are ignored. typeid(const Circle) and typeid(Circle&) both equal typeid(Circle).
  • Dereferencing a null pointer inside typeid throws std::bad_typeid instead of crashing, but only for polymorphic types.

std::type_index (from <typeindex>) wraps a type_info so it can be copied and used as a key in std::map or std::unordered_map. Counting objects by dynamic type is one of the few places where typeid is genuinely the simplest tool.

Note the line that binds *s to a reference before calling typeid. Writing typeid(*s) on a std::unique_ptr makes Clang warn that the expression “will be evaluated despite being used as an operand to ‘typeid'” (-Wpotentially-evaluated-expression), because the operand is a function call (unique_ptr::operator*) on a polymorphic type. With -Werror, that warning stopped the build until the expression was changed.

dynamic_cast: Checked Conversions

dynamic_cast converts a pointer or reference to a polymorphic class into a pointer or reference to another class in the same hierarchy, and checks at run time that the object really has that type:

// dynamic_cast_basics.cpp - downcasts that succeed and fail, the reference
// form that throws, cross-casts between sibling bases, and casting to void*.
#include <iostream>
#include <memory>
#include <typeinfo>

struct Account {
    virtual ~Account() = default;
};
struct Savings : Account {
    double rate = 0.025;
};
struct Checking : Account {};

// Two unrelated interfaces, and a class that implements both.
struct Printable {
    virtual ~Printable() = default;
};
struct Serializable {
    virtual ~Serializable() = default;
};
struct Report : Printable, Serializable {};

int main()
{
    std::unique_ptr<Account> a = std::make_unique<Savings>();
    std::unique_ptr<Account> b = std::make_unique<Checking>();

    // Pointer form: nullptr when the object is not of the requested type.
    if (auto* s = dynamic_cast<Savings*>(a.get()))
        std::cout << "a is Savings, rate " << s->rate << '\n';
    if (dynamic_cast<Savings*>(b.get()) == nullptr)
        std::cout << "b is not Savings: dynamic_cast returned nullptr\n";

    // Reference form: there is no null reference, so failure throws.
    try {
        Savings& s = dynamic_cast<Savings&>(*b);
        std::cout << s.rate << '\n';
    } catch (const std::bad_cast&) {
        std::cout << "dynamic_cast<Savings&>(*b) threw std::bad_cast\n";
    }

    // Cross-cast: from one base to a sibling base of the same object.
    Report report;
    Printable* p = &report;
    Serializable* sz = dynamic_cast<Serializable*>(p);
    std::cout << "cross-cast Printable* -> Serializable*: " << (sz != nullptr ? "ok" : "failed") << '\n';

    // The two base subobjects live at different addresses inside Report.
    // dynamic_cast<void*> finds the start of the whole object from either one.
    const void* from_p = dynamic_cast<void*>(p);
    const void* from_sz = dynamic_cast<void*>(sz);
    std::cout << "both bases lead to the same object: " << std::boolalpha
              << (from_p == from_sz && from_p == static_cast<void*>(&report)) << '\n';
    std::cout << "Printable* and Serializable* hold the same address: "
              << (static_cast<void*>(p) == static_cast<void*>(sz)) << '\n';
}

Output:

a is Savings, rate 0.025
b is not Savings: dynamic_cast returned nullptr
dynamic_cast<Savings&>(*b) threw std::bad_cast
cross-cast Printable* -> Serializable*: ok
both bases lead to the same object: true
Printable* and Serializable* hold the same address: false

The program covers the four forms in everyday use:

  1. Downcast with a pointer. dynamic_cast<Savings*>(a.get()) returns a valid pointer when a holds a Savings, and nullptr otherwise. The if (auto* s = ...) form tests and declares in one line.
  2. Downcast with a reference. There is no null reference, so a failed dynamic_cast<Savings&> throws std::bad_cast. Use this form when a mismatch is a bug rather than an expected case. The exception handling guide covers catching it properly.
  3. Cross-cast. Report implements both Printable and Serializable. Given a Printable*, dynamic_cast<Serializable*> finds the Serializable part of the same object, something static_cast cannot do because the two bases are unrelated. This is the classic use of dynamic_cast with multiple inheritance: asking an object whether it also supports another interface.
  4. Cast to void*. dynamic_cast<void*> returns the address of the complete object. The last two lines show why that matters: the Printable* and Serializable* point to different addresses inside the same Report, and only dynamic_cast<void*> maps both back to one address.

Upcasts (from derived to base) need no cast at all; they are implicit and always safe.

What dynamic_cast refuses to compile

Two mistakes are caught at compile time. The test suite builds both programs and passes only if the compiler rejects them with a matching message:

// dynamic_cast needs a polymorphic source type: Point has no virtual function.
struct Point { int x = 0; };
struct Point3 : Point { int z = 0; };

int main()
{
    Point3 p3;
    Point* p = &p3;
    Point3* back = dynamic_cast<Point3*>(p);   // error: Point is not polymorphic
    return back ? 0 : 1;
}
// dynamic_cast cannot start from void*: there is no type information to read.
struct Base { virtual ~Base() = default; };

int main()
{
    Base b;
    void* v = &b;
    Base* back = dynamic_cast<Base*>(v);   // error: void* is not a pointer to a class
    return back ? 0 : 1;
}

GCC 13.3 and Clang 18 report them like this:

not_polymorphic.cpp:9:20: error: cannot 'dynamic_cast' 'p' (of type 'struct Point*') to type 'struct Point3*' (source type is not polymorphic)
not_polymorphic.cpp:9:20: error: 'Point' is not polymorphic
from_void.cpp:8:18: error: cannot 'dynamic_cast' 'v' (of type 'void*') to type 'struct Base*' (source is not a pointer to class)
from_void.cpp:8:18: error: 'void' is not a class type

The first error is the reason RTTI is tied to virtual functions: a class without them has no place to store its type information. If you need dynamic_cast on a hierarchy, give the base class a virtual destructor, which it should have anyway if objects are deleted through base pointers.

Why static_cast Is Not a Substitute

static_cast also converts a base pointer to a derived pointer, with no run-time cost and no check. If the object is not of the target type, the result is undefined behavior: the program reads memory that belongs to some other object, or to no object at all.

While testing this article, replacing dynamic_cast<Savings&>(*b) with static_cast<Savings&>(*b) (where b holds a Checking) gave three different outcomes:

  • GCC 13 at -O2 warned with -Warray-bounds that the access was “partly outside array bounds”, because it could see the object’s real size. At -O0 it said nothing.
  • Clang 18 compiled it without a warning at both levels.
  • UndefinedBehaviorSanitizer caught it at run time: “member access within address … which does not point to an object of type ‘Savings’ … object is of type ‘Checking'”.

So the compiler catches a bad static_cast only by luck. Use static_cast for downcasts only when the type is already known by construction, and dynamic_cast whenever it is a question.

The Dynamic Type During Construction and Destruction

An object’s dynamic type changes while it is being built and torn down. Inside a base-class constructor, the derived part does not exist yet, so the object is, for RTTI and virtual calls, just the base:

// construction.cpp - during a constructor or destructor, an object's
// dynamic type is the class whose constructor or destructor is running.
#include "type_name.h"

#include <iostream>
#include <typeinfo>

struct Widget {
    Widget() { report("Widget constructor"); }
    virtual ~Widget() { report("Widget destructor"); }
    void report(const char* where) const
    {
        std::cout << where << ": typeid(*this) is " << readable_name(typeid(*this))
                  << ", kind() says " << kind() << '\n';
    }
    virtual const char* kind() const { return "widget"; }
};

struct Button : Widget {
    Button() { report("Button constructor"); }
    ~Button() override { report("Button destructor"); }
    const char* kind() const override { return "button"; }
};

int main()
{
    Button button;
    button.report("main");
}

Output:

Widget constructor: typeid(*this) is Widget, kind() says widget
Button constructor: typeid(*this) is Button, kind() says button
main: typeid(*this) is Button, kind() says button
Button destructor: typeid(*this) is Button, kind() says button
Widget destructor: typeid(*this) is Widget, kind() says widget

typeid(*this) and the virtual kind() agree at every step: Widget inside Widget‘s constructor and destructor, Button everywhere else. This is the same rule that makes a virtual call in a constructor call the base version, and the reason not to rely on typeid or dynamic_cast on this before construction finishes.

RTTI vs Virtual Functions vs std::variant

Most code that switches on a type with dynamic_cast can be written in a way the compiler checks. The program below computes the total area of a circle and a rectangle three ways:

// alternatives.cpp - one job done three ways: computing the area of mixed
// shapes with dynamic_cast, with a virtual function and with std::variant.
#include <iostream>
#include <memory>
#include <type_traits>
#include <variant>
#include <vector>

namespace with_rtti {
struct Shape { virtual ~Shape() = default; };
struct Circle : Shape { double r; explicit Circle(double r_) : r(r_) {} };
struct Rect : Shape { double w, h; Rect(double w_, double h_) : w(w_), h(h_) {} };

// Every new shape needs a new branch here, and the compiler cannot warn if one is missing.
double area(const Shape& s)
{
    if (auto* c = dynamic_cast<const Circle*>(&s))
        return 3.0 * c->r * c->r;            // pi rounded to 3 keeps the output exact
    if (auto* r = dynamic_cast<const Rect*>(&s))
        return r->w * r->h;
    return 0.0;                              // an unknown shape slips through silently
}
}    // namespace with_rtti

namespace with_virtual {
struct Shape {
    virtual ~Shape() = default;
    virtual double area() const = 0;         // every shape must implement it
};
struct Circle : Shape {
    double r;
    explicit Circle(double r_) : r(r_) {}
    double area() const override { return 3.0 * r * r; }
};
struct Rect : Shape {
    double w, h;
    Rect(double w_, double h_) : w(w_), h(h_) {}
    double area() const override { return w * h; }
};
}    // namespace with_virtual

namespace with_variant {
struct Circle { double r; };
struct Rect { double w, h; };
using Shape = std::variant<Circle, Rect>;    // a closed set of types, no base class

double area(const Shape& s)
{
    return std::visit([](const auto& v) -> double {
        using T = std::decay_t<decltype(v)>;
        if constexpr (std::is_same_v<T, Circle>)
            return 3.0 * v.r * v.r;
        else
            return v.w * v.h;                // a new alternative fails to compile here
    }, s);
}
}    // namespace with_variant

int main()
{
    {
        using namespace with_rtti;
        std::vector<std::unique_ptr<Shape>> shapes;
        shapes.push_back(std::make_unique<Circle>(1.0));
        shapes.push_back(std::make_unique<Rect>(2.0, 3.0));
        double total = 0;
        for (const auto& s : shapes)
            total += area(*s);
        std::cout << "dynamic_cast:     total area " << total << '\n';
    }
    {
        using namespace with_virtual;
        std::vector<std::unique_ptr<Shape>> shapes;
        shapes.push_back(std::make_unique<Circle>(1.0));
        shapes.push_back(std::make_unique<Rect>(2.0, 3.0));
        double total = 0;
        for (const auto& s : shapes)
            total += s->area();
        std::cout << "virtual function: total area " << total << '\n';
    }
    {
        using namespace with_variant;
        std::vector<Shape> shapes{Circle{1.0}, Rect{2.0, 3.0}};
        double total = 0;
        for (const auto& s : shapes)
            total += area(s);
        std::cout << "std::variant:     total area " << total << '\n';
    }
}

Output:

dynamic_cast:     total area 9
virtual function: total area 9
std::variant:     total area 9

All three give the same total. They differ in what happens when someone adds a Triangle:

ApproachAdding a new typeAdding a new operationChecked by the compiler
dynamic_cast chainAdd a branch in every function that switches on the typeWrite one new functionNo: a missing branch silently returns 0
Virtual functionWrite one new classAdd a function to every classYes: a pure virtual must be implemented
std::variant + std::visitAdd the type to the variant, then fix every visitorWrite one new visitorYes: a visitor that misses a type does not compile

Pick by what changes more often. A class hierarchy that grows (plugins, UI widgets) suits virtual functions, as described in the guide to polymorphism. A fixed set of types with many operations on them (tokens, messages, shapes in a geometry library) suits std::variant. A dynamic_cast chain is the tool of last resort: when the hierarchy belongs to someone else, or when only one or two call sites care about a special case.

How Fast Are typeid and dynamic_cast?

“RTTI is slow” is half true. bench/cast_cost.cpp in the repository times each operation over 10 million calls on a hierarchy five levels deep. The GCC and Clang ranges are over five runs at -O2 on an x86-64 Xeon at 2.10 GHz; the MSVC column is two Release runs on a Windows 11 PC, so compare it with the other columns by pattern, not by digit:

OperationGCC 13.3 (ns)Clang 18 (ns)MSVC (ns)
Virtual function call1.3 to 1.71.3 to 2.31.3
typeid(*b) == typeid(D5)0.9 to 1.00.9 to 1.94.4 to 4.6
dynamic_cast to the exact type3.3 to 3.83.1 to 5.211.7 to 12.7
dynamic_cast four levels up42.0 to 47.542.0 to 47.810.3 to 11.8
dynamic_cast that fails46.5 to 55.951.1 to 57.227.5 to 33.7
dynamic_cast cross-cast17.9 to 21.620.9 to 27.723.0 to 23.9

Three things stand out:

  • The cost depends on the runtime library, not on the language. GCC and Clang share libstdc++ and give nearly the same numbers. MSVC’s runtime is organized differently: its typeid comparison costs about four virtual calls instead of one, and its dynamic_cast to the exact type is slower, while walking four levels up is faster than on libstdc++.
  • A failing dynamic_cast is the most expensive case everywhere (28 to 57 ns here), because the runtime has to search the whole hierarchy before giving up. Code that tries a long list of casts until one succeeds pays that price for every miss.
  • The absolute numbers are small. Tens of nanoseconds matter inside a loop over millions of objects, and almost nowhere else.

Measure on your own compiler before optimizing, and if a hot loop really does switch on type, a virtual call (1 to 2 ns on every compiler here) is the faster design anyway.

Turning RTTI Off

GCC and Clang accept -fno-rtti, and MSVC accepts /GR-. Projects use them to save the space taken by type information, for example in embedded code or in large codebases such as LLVM and Chromium. With RTTI off:

  • With GCC and Clang, typeid and dynamic_cast no longer compile. GCC reports “cannot use ‘typeid’ with ‘-fno-rtti'” and “‘dynamic_cast’ not permitted with ‘-fno-rtti'”; Clang reports “use of typeid requires -frtti” and “use of dynamic_cast requires -frtti” (both measured on the programs above).
  • Virtual functions and std::variant keep working, which is one more reason to prefer them.
  • Exceptions still work: compilers keep the type information that catch needs even with RTTI off.

Common Mistakes with RTTI

  • Using typeid or dynamic_cast on a class with no virtual functions. typeid silently reports the static type, and dynamic_cast does not compile. Give polymorphic bases a virtual destructor.
  • Comparing name() strings instead of type_info objects. Names are implementation-defined and not guaranteed unique. Compare with == or use std::type_index.
  • Printing name() to users or logs and expecting readable text. GCC and Clang return mangled names; demangle them first.
  • Checking the pointer form for failure but not the reference form. dynamic_cast<T&> never returns null; catch std::bad_cast or use the pointer form.
  • Long if (dynamic_cast...) else if (dynamic_cast...) chains. They hide a missing case. Replace them with a virtual function or std::variant.
  • Calling typeid(*this) or dynamic_cast on this in a constructor and expecting the derived type.
  • Using static_cast for a downcast that might be wrong. It compiles, runs and corrupts memory.

Key Takeaways

  • RTTI means typeid, std::type_info, std::type_index and dynamic_cast. It works on polymorphic classes only.
  • typeid reports an object’s exact dynamic type; compare results with ==, never by name.
  • dynamic_cast checks a conversion: nullptr for pointers, std::bad_cast for references.
  • Cross-casting between interfaces and dynamic_cast<void*> are things only dynamic_cast can do.
  • A virtual function or std::variant is usually the better design, and the compiler checks it.
  • A typeid comparison costs 1 to 5 ns; a dynamic_cast costs 3 to about 57 ns, most when it fails. The exact numbers depend on the compiler’s runtime library.

Conclusion

RTTI is C++’s way of answering “what is this object, really?” at run time. typeid gives the exact answer, and dynamic_cast answers the more useful question of whether an object can be used as a particular type. Both work only where the language has kept type information, in polymorphic classes, and both are best kept for the cases a design cannot avoid: cross-casting between interfaces, unwrapping objects from code you do not own and the occasional special case. Everywhere else, a virtual function or a variant says the same thing in a form the compiler can check.

For the rest of C++’s type system and object model, see smart pointers, compound types and the C++ section.

Source Code and Tests

rtti workflow status

All programs on this page are in the basics/rtti directory of the MYCPLUS C++ examples repository.

Build and test:

cmake -S . -B build
cmake --build build --config Release
ctest --test-dir build -C Release --output-on-failure

What the build checks.

  • Compilers: GCC and Clang under C++17 and C++20 with -Wall -Wextra -pedantic -Werror, and MSVC with /W4 /WX /permissive-.
  • Output: each of the four programs prints exactly the output shown on this page, on every compiler.
  • Compile failures: dynamic_cast on a non-polymorphic class and from void* must fail to build, with a compiler message that names the problem.
  • Sanitizers: on Linux, every test also runs under AddressSanitizer and UndefinedBehaviorSanitizer.

The benchmark is built but not tested, because its numbers depend on the machine.

What I Verified

Everything in the Ubuntu column was run for this article on Ubuntu 24.04 (x86-64, GCC 13.3, Clang 18.1, CMake 3.28). The Windows column comes from run_all.ps1 in the repository, run on Windows 11 (build 26300) with MSVC.

CheckUbuntu 24.04Windows 11
Build with warnings as errorsGCC and Clang, C++17 and C++20: passedMSVC /W4 /WX /permissive-, C++17 and C++20: passed
CTest: 4 output comparisons and 2 programs that must not compile6 of 6 in all four configurations6 of 6 in C++17 and in C++20
AddressSanitizer and UndefinedBehaviorSanitizer, every test6 of 6, cleanNot applicable
Valgrind memcheck, every programNo errors, no leaksNot applicable
Deliberate mistakes that a test must catchAll 4 caughtAll 5 caught (4 shared with Linux, 1 Windows-only)

Not covered: -fno-rtti builds of the test suite (checked by hand above), 32-bit builds and compilers older than GCC 13, Clang 18 and current MSVC.

Scroll to Top