Skip to content

[C++] Enhance functions in util/ubsan.h to support types that do not have a default constructor #48339

Closed

Description

@andishgar

Describe the enhancement requested

Currently, the functions in util/ubsan.h require a type that is trivially copyable. However, before performing its intended operation, it calls the default constructor of the type, as shown in the code below:

inline std::enable_if_t<std::is_trivially_copyable_v<T>, T> SafeLoadAs(
const uint8_t* unaligned) {
std::remove_const_t<T> ret;
std::memcpy(&ret, unaligned, sizeof(T));
return ret;
}

It is possible, however, for a type to be trivially copyable without having a default constructor, for example:

struct A {
  A(int a) : a(a) {}
  int a;
};

Component(s)

C++

Activity

  1. added a commit that references this issue on Dec 18, 2025
  2. added this to the 23.0.0 milestone on Dec 18, 2025
  3. pitrou commented on Dec 18, 2025

    @pitrou
    Member

    Issue resolved by pull request 48429
    #48429

  4. added a commit that references this issue on May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions