Skip to content

clang incorrectly allows converting function pointers to and from void* in constant expressions #150340

@efriedma-quic

Description

@efriedma-quic

Consider:

void f();
constexpr auto p1 = (void*)f;
constexpr auto p2 = (void(*)())p1;

clang currently accepts, but these should be rejected. [expr.const] says an expression is not a constant expression if it contains a reinterpret_cast ... and converting a function pointer to an object pointer requires a reinterpret_cast.

gcc rejects, MSVC accepts p1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts-invalidclang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions