struct S
{
union
{
int arr1[10];
char arr2[sizeof(arr1)];
};
};
It compiles successfully with gcc 4.9.2 in c++03 and c++11 mode. However when I change S
to be a template like so:
template <size_t N>
struct S
{
union
{
int arr1[N];
char arr2[sizeof(arr1)];
};
};
I get the following error output:
error: int S<10ul>::<anonymous union>::arr1 [10]’ is inaccessible
int arr1[N];
error: within this context
char arr2[sizeof(arr1)];
Clang compiles both versions only in c++11 mode. Is this a legal piece of code? There is an open question on this particular problem on stackoverflow. Some people quoted the standard however none of them seem to give a definitive answer.
Thanks,
Piotr
Recently I have come across some discrepancies between gcc and clang. Consider the following piece of code:struct S { union { int arr1[10]; char arr2[sizeof(arr1)]; }; };
It compiles successfully with gcc 4.9.2 in c++03 and c++11 mode. However when I change
S
to be a template like so:template <size_t N> struct S { union { int arr1[N]; char arr2[sizeof(arr1)]; }; };
I get the following error output:
error: int S<10ul>::<anonymous union>::arr1 [10]’ is inaccessible
int arr1[N];
error: within this context
char arr2[sizeof(arr1)];
Clang compiles both versions only in c++11 mode. Is this a legal piece of code?
There is an open question on this particular problem on stackoverflow. Some people quoted the standard however none of them seem to give a definitive answer.
Thanks,
Piotr
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.