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

Created on 2025-12-27.00:00:00 last changed 12 hours ago

Messages

Date: 2026-03-31.16:35:58

Proposed resolution:

This wording is relative to N5032.

[Drafting note: [functions.within.classes] can be read to say that the functions are constexpr already, but given the note that contradicts this interpretion, explicit declarations can't hurt. — end drafting note]

  1. Modify [support.srcloc.class.general] as indicated:

    namespace std {
      struct source_location {
        // source location construction
        static consteval source_location current() noexcept;
        constexpr source_location() noexcept;
    
        constexpr source_location(const source_location&) noexcept = default;
        constexpr source_location& operator=(const source_location&) noexcept = default;
    
        // source location field access
        constexpr uint_least32_t line() const noexcept;
        constexpr uint_least32_t column() const noexcept;
        constexpr const char* file_name() const noexcept;
        constexpr const char* function_name() const noexcept;
    
      private:
        uint_least32_t line_;               // exposition only
        uint_least32_t column_;             // exposition only
        const char* file_name_;             // exposition only
        const char* function_name_;         // exposition only
      };
    }
    

    - 1- The type `source_location` meets the Cpp17DefaultConstructible, Cpp17CopyConstructible, Cpp17CopyAssignable, Cpp17Swappable, and Cpp17Destructible requirements ([utility.arg.requirements], [swappable.requirements]) models `semiregular`. is_nothrow_swappable_v<source_location> is `true`. All of the following conditions are `true`:

    1. (1.1) — is_nothrow_move_constructible_v<source_location>

    2. (1.2) — is_nothrow_move_assignable_v<source_location>

    3. (1.3) — is_nothrow_swappable_v<source_location>

    [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]

Date: 2026-03-31.16:35:58

[ Croydon 2026-03-28; Status changed: Immediate → WP. ]

Date: 2026-03-27.13:57:24

[ Croydon 2026-03-27; move to Immediate. ]

Date: 2026-03-15.00:00:00

[ 2026-03-26; Tim adds wording ]

Date: 2026-02-15.00:00:00

[ 2026-02-18; Reflector poll. ]

Set priority to 2 after reflector poll.

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
2026-03-31 16:35:58adminsetmessages: + msg16208
2026-03-31 16:35:58adminsetstatus: immediate -> wp
2026-03-27 13:57:24adminsetmessages: + msg16117
2026-03-27 13:57:24adminsetstatus: new -> immediate
2026-03-27 01:52:04adminsetmessages: + msg16102
2026-03-27 01:52:04adminsetmessages: + msg16101
2026-02-18 14:59:59adminsetmessages: + msg15952
2025-12-27 00:00:00admincreate