[clang] [Clang] Add __datasizeof (PR #67805)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 13 11:19:54 PDT 2023


================
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s
----------------
AaronBallman wrote:

We should also show it's strange behavior with VLAs in C++:
```
int n = 12;
__datasizeof(int[n++]); // Surprise, n is incremented, you're welcome
```
and with templates:
```
template <typename Ty>
constexpr int data_size_of() { return __datasizeof(Ty); }

static_assert(data_size_of<int>() == sizeof(int)); // etc
```
and I suppose with not-yet-complete types:
```
struct S {
  int i = __datasizeof(S);
  float f;
  char c;
}; // Test that i is the full class size, not the size at the point of parsing
```

https://github.com/llvm/llvm-project/pull/67805


More information about the cfe-commits mailing list