Title
Add `consteval` to `std::meta::exception` defaulted member functions
Status
new
Section
[meta.reflection.exception]
Submitter
Marek Polacek

Created on 2025-12-16.00:00:00 last changed 1 week ago

Messages

Date: 2025-12-20.15:08:52

Proposed resolution:

This wording is relative to N5032.

  1. Modify [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;
      };
    }
    
Date: 2025-12-16.00:00:00

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 [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;
History
Date User Action Args
2025-12-20 15:08:52adminsetmessages: + msg15836
2025-12-16 00:00:00admincreate