Skip to content

Clang cannot compute at compile time typeid of a variable of concrete class type with vtable #63117

Closed
@ilya-biryukov

Description

@ilya-biryukov

On this code:

// Build with -std=c++20
#include <typeinfo>

struct base { virtual void enable_vtable(); };
struct derived : base {};

derived d;
static_assert(&typeid(d) == &typeid(derived));

Clang produces the following error:

error: static assertion expression is not an integral constant expression
note: typeid applied to object 'd' whose dynamic type is not constant

Even though typeid can be computed at compile time (since d is not a reference and has a concrete object type).
GCC and MSVC compile this code with no errors, see Godbolt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions