Are anonymous unions allowed to declare friends, despite being pointless, given that all members must be public?
clang 3.6.0 doesn't allow it for either classes or functions; GCC 5.1.0 and MSVC 14.0 are fine with it. I don't see anything in the Standard prohibiting it. All 3 compilers correctly require all members to be public; none care about the redundant "
public:" access-specifier, either.
I'm wondering because this seems like a silly corner case of clang......or the Standard. =P
#include <cstdio>
static union
{
private: // correctly allowed by all 3 compilers because no members declared
public:
unsigned s_u;
float s_f;
friend int main();
friend class Meow;
};
static_assert(sizeof(s_u) == sizeof(s_f), "size mismatch");
class Meow { };
int main()
{
s_f = 1.0f;
std::printf("%08X\n", s_u);
return 0;
}
Melissa