Skip to content

[specialized.algorithms.general] The note seems incorrect #6143

@frederick-vs-ja

Description

@frederick-vs-ja

[specialized.algorithms.general]/3 says that:

[Note 1: When invoked on ranges of potentially-overlapping subobjects ([intro.object]), the algorithms specified in [specialized.algorithms] result in undefined behavior. — end note]

However, this is a non-normative note, and maybe sometimes incorrect.

In this example

#include <memory>

int main()
{
    struct B {};
    struct D : B {};
    D d;
    std::construct_at(static_cast<B*>(&d));
    // or use an uninitialized_* algorithm to create a new B object
    // ... other operations
    std::construct_at(&d);
}

the newly created B object doesn't transparently replace the original base class subobject, and hence the lifetime of d is ended by the operation. But the program may still have well-defined behavior, as long as the pointer or reference to d or its base class subobject is carefully used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions