I did a static_assert to make sure that a valid type was used. I don't know if I just should have checked if the type is void, or whether any type can have size zero (I think it can with [[no_unique_address]]), but it was the warning message that was interesting:
template <typename T> class MyClass { public: static_assert(sizeof (T) > 0); }; Clang-Tidy:
Suspicious comparison of 'sizeof(expr)' to a constant
If I do this, the warning goes away:
static_assert(sizeof T > 0); What does the warning mean, and why does it go away when I take away the parentheses?
sizeof Tjust isn't valid for a typeT. My guess is that clang-tidy doesn't have a specific warning for that, but that you will instead get an error when compiling it properly: "error : expected parentheses around type name in sizeof expression"[[no_unique_address]]doesn't change the size of an object. It makes it possible for an instance of an empty class (which has at least the size 1) to share the address with another member variable.[[no_unique_address]]but it may affect the size of the parent.class MyClass { char dummy; [[no_unique_address]] EmptyClass foo; };- hereMyClasswill probably have size 1, not 2.sizeofis an operator, not a function. It doesn't need parentheses.sizeof charis perfectly legal, for example.