Skip to content

consteval constructor cannot store this inside object #135281

Open
@snarkmaster

Description

@snarkmaster

Unlike GCC & MSVC, Clang refuses to compile this https://godbolt.org/z/WYr58Ge9s --

struct B {
  const void* immortal_;
  consteval B() : immortal_{this} {}
};
constexpr static B b;

The error suggests that the frontend wrongly thinks that this is a pointer to a temporary:

<source>:6:20: error: call to consteval function 'B::B' is not a constant expression
    6 | constexpr static B b;
      |                    ^
<source>:6:20: note: pointer to temporary is not a constant expression
<source>:6:20: note: temporary created here

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constevalC++20 constevaldiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions