This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4494. Add consteval to std::meta::exception defaulted member functions

Section: 21.4.4 [meta.reflection.exception] Status: New Submitter: Marek Polacek Opened: 2025-12-16 Last modified: 2025-12-20

Priority: Not Prioritized

View all issues with New status.

Discussion:

CWG 3115 states that every function of consteval-only type shall be an immediate function. This caused a problem for std::meta::exception::what() which was marked constexpr but not consteval. To be able to mark it consteval, we had to tweak the rules about overriding by a consteval virtual function (CWG 3117 ).

But 21.4.4 [meta.reflection.exception] still defines std::meta::exception such that it contains these defaulted special member functions:

exception(const exception&) = default;
exception(exception&&) = default;

exception& operator=(const exception&) = default;
exception& operator=(exception&&) = default;

which aren't consteval (and since they're not templates, they won't be promoted to consteval as per P2564). I propose to make the four functions consteval:

consteval exception(const exception&) = default;
consteval exception(exception&&) = default;

consteval exception& operator=(const exception&) = default;
consteval exception& operator=(exception&&) = default;

Proposed resolution:

This wording is relative to N5032.

  1. Modify 21.4.4 [meta.reflection.exception] as indicated:

    namespace std::meta {
      class exception : public std::exception {
      private:
        optional<string> what_;  // exposition only
        u8string u8what_;        // exposition only
        info from_;              // exposition only
        source_location where_;  // exposition only
      public:
        consteval exception(u8string_view what, info from,
                            source_location where = source_location::current()) noexcept;
                            
        consteval exception(string_view what, info from,
                            source_location where = source_location::current()) noexcept;
                            
        consteval exception(const exception&) = default;
        consteval exception(exception&&) = default;
        
        consteval exception& operator=(const exception&) = default;
        consteval exception& operator=(exception&&) = default;
        
        constexpr const char* what() const noexcept override;
        consteval u8string_view u8what() const noexcept;
        consteval info from() const noexcept;
        consteval source_location where() const noexcept;
      };
    }