Skip to content

CppCon performance not quite true? #168724

@kelbon

Description

@kelbon

It strange issue, but there are CppCon video about libc++ shipped with clang:

https://www.youtube.com/watch?v=iw8hqKftP4I

And in first 9 minutes speaker says, that this code should compile on clang with libc++:

template<typename V, typename E>
struct EX {
  union U {
    [[no_unique_address]] V v;
    [[no_unique_address]] E e;
  };
  [[no_unique_address]] U u_;
  bool has_val_;
};

struct mystruct {
  int x;
  bool y;
  char z;
};

static_assert(sizeof(EX<mystruct, int>) == 8); // 12 in reality

But its not. Sizeof == 8, and i agree with compiler here

I also checked with std::expected itself:

#include <expected>

struct mystruct {
  int x;
  bool y;
  char z;
};


mystruct foo();

std::expected<mystruct, int> compute() {
  return foo();
}

static_assert(sizeof(std::expected<mystruct, int>) == 12); // again, 12

https://godbolt.org/z/jPfbMqchW

A talk generally good, but this first part (9 minutes) confuses me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ABIApplication Binary Interfacelibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions