C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Lakos rule

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 21 Dec 2023 17:41:44 +0000
On Thursday, December 21, 2023, Jason McKesson via Std-Proposals wrote:
>
>
> If the "throws: nothing" functions actually do throw (violating the
> standard, BTW),
>


Let's say I'm writing a C++ compiler for my new 128-Bit germanium-based
supercooled microcontroller, and I want to implement 'std::align' whose
prototype is as follows:

    void *align( std::size_t alignment,
             std::size_t size,
             void*& ptr,
             std::size_t& space );

This function does not have 'noexcept' written after it, even though it's
not supposed to throw. Let's say my first line in the body of this function
is:

    if ( nullptr == p ) throw std::runtime_error("Cannot align a nullptr");

Is my implementation of 'std::align' in violation of the Standard? If so,
then is the following statement true?
    "The C++ Standard does not mark 'std::align' as 'noexcept' in order to
accommodate implementations that violate the Standard".

This whole 'Lakos' thing isn't making sense to me. I've glanced over the
papers where people are hoping 'myvector.front()' will throw if the vector
is empty, but if the Standard says that 'vector::front' doesn't throw then
why accommodate the violators?

I've never had a problem doing:

    if ( vec.empty() ) throw SomeThing();
    vec.front().InvokeSomeMethod();

Or more frequently:

    assert( false == vec.empty() );
    vec.front().InvokeSomeMethod(); a

Received on 2023-12-21 17:41:47