C++ Logo

std-proposals

Advanced search

[std-proposals] Mark a class or an object as 'noexcept'

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Wed, 28 May 2025 10:36:16 +0100
There are times when I'm writing template code and I end up with
'noexcept' specifications something like:

    template<typename T>
    void Func(T&&) noexcept( noexcept( std::declval<T&>.clear() ) &&
noexcept(std::declval<T&>.some_other_method() ) );

when what I really want is that 'T' would be some sort of class whose
methods never throw.

Would it be helpful at all to be able to mark a class or an individual
object as 'noexcept'? Maybe something like:

  class noexcept MyClass { . . . };

or maybe even mark an object:

    MyClass noexcept my_object;

so that we get a compiler error if any of the class's methods are not
marked as 'noexcept'?

(I think marking the class would be a lot less work, as marking an
object I think would mean adding a cv-qualifier to the language)

Received on 2025-05-28 09:36:28