Title
`source_location` is explicitly unspecified if is constexpr or not
Status
new
Section
[support.srcloc.class]
Submitter
Hana Dusíková

Created on 2025-12-27.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-12-27.00:00:00

Basically in [support.srcloc.class.general] following p1 there is a note from Jens from six years ago which says (emphasis mine):

[Note 1: The intent of `source_location` is to have a small size and efficient copying. It is unspecified whether the copy/move constructors and the copy/move assignment operators are trivial and/or constexpr. — end note]

But also reflection's `std::meta::source_location_of` returns it by value and is `consteval`. This means `source_location` needs to be specified to constexpr. And good news is ... all three major implementations have it constexpr implicitly.

Options are (from my perspective) to remove that part of the note "and/or constexpr" and just call it a day, or add

constexpr source_location(const source_location&) = default;
constexpr source_location(source_location&&) noexcept = default;
constexpr source_location& operator=(const source_location&) = default;
constexpr source_location& operator=(source_location&&) noexcept = default;

AFAIK this is how to explicitly say it must be constexpr but it can still be trivial, see demo.

History
Date User Action Args
2025-12-27 00:00:00admincreate