forked from OSchip/llvm-project
Add test coverage for more C DRs
This completes the initial pass over all of the C DRs.
This commit is contained in:
parent
b32a5666a8
commit
2fc5a34100
|
@ -322,3 +322,63 @@ struct dr492_t {
|
|||
};
|
||||
int m13;
|
||||
} dr492;
|
||||
|
||||
/* WG14 DR496: yes
|
||||
* offsetof questions
|
||||
*/
|
||||
void dr496(void) {
|
||||
struct A { int n, a [2]; };
|
||||
struct B { struct A a; };
|
||||
struct C { struct A a[1]; };
|
||||
|
||||
/* The standard does not require either of these examples to work, but we
|
||||
* support them just the same. The first one is invalid because it's
|
||||
* referencing a member of a different struct, and the second one is invalid
|
||||
* because it references an array of another struct. Clang calculates the
|
||||
* correct offset to each of those fields.
|
||||
*/
|
||||
_Static_assert(__builtin_offsetof(struct B, a.n) == 0, "");
|
||||
/* First int below is for 'n' and the second int is for 'a[0]'; this presumes
|
||||
* there is no padding involved.
|
||||
*/
|
||||
_Static_assert(__builtin_offsetof(struct B, a.a[1]) == sizeof(int) + sizeof(int), "");
|
||||
|
||||
/* However, we do not support using the -> operator to access a member, even
|
||||
* if that would be a valid expression. FIXME: GCC accepts this, perhaps we
|
||||
* should as well.
|
||||
*/
|
||||
(void)__builtin_offsetof(struct C, a->n); /* expected-error {{expected ')'}} \
|
||||
expected-note {{to match this '('}}
|
||||
*/
|
||||
|
||||
/* The DR asked a question about whether defining a new type within offsetof
|
||||
* is allowed. C2x N2350 made this explicitly undefined behavior, but Clang
|
||||
* has always supported defining a type in this location, and GCC also
|
||||
* supports it.
|
||||
*/
|
||||
(void)__builtin_offsetof(struct S { int a; }, a);
|
||||
}
|
||||
|
||||
/* WG14 DR499: yes
|
||||
* Anonymous structure in union behavior
|
||||
*/
|
||||
void dr499(void) {
|
||||
union U {
|
||||
struct {
|
||||
char B1;
|
||||
char B2;
|
||||
char B3;
|
||||
char B4;
|
||||
};
|
||||
int word;
|
||||
} u;
|
||||
|
||||
/* Validate that B1, B2, B3, and B4 do not have overlapping storage, only the
|
||||
* anonymous structure and 'word' overlap.
|
||||
*/
|
||||
_Static_assert(__builtin_offsetof(union U, B1) == 0, "");
|
||||
_Static_assert(__builtin_offsetof(union U, B2) == 1, "");
|
||||
_Static_assert(__builtin_offsetof(union U, B3) == 2, "");
|
||||
_Static_assert(__builtin_offsetof(union U, B4) == 3, "");
|
||||
_Static_assert(__builtin_offsetof(union U, word) == 0, "");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/* RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic -Wno-c11-extensions %s
|
||||
RUN: %clang_cc1 -std=c99 -verify=expected -pedantic -Wno-c11-extensions %s
|
||||
RUN: %clang_cc1 -std=c11 -verify=expected -pedantic %s
|
||||
RUN: %clang_cc1 -std=c17 -verify=expected -pedantic %s
|
||||
RUN: %clang_cc1 -std=c2x -verify=expected -pedantic %s
|
||||
*/
|
||||
|
||||
/* WG14 DR502:
|
||||
* Flexible array member in an anonymous struct
|
||||
*/
|
||||
void dr502(void) {
|
||||
/* This is EXAMPLE 3 from 6.7.2.1 and is intended to show that a flexible
|
||||
* array member can be used when the only other members of the class are from
|
||||
* an anonymous structure member.
|
||||
*/
|
||||
struct s {
|
||||
struct { int i; };
|
||||
int a[]; /* c89only-warning {{flexible array members are a C99 feature}} */
|
||||
};
|
||||
|
||||
/* This is a slightly modified example that looks to see whether the
|
||||
* anonymous structure itself can provide a flexible array member for the
|
||||
* containing class.
|
||||
*
|
||||
* The committee does not think this is valid because it would mean the
|
||||
* anonymous structure would have size 0. Additionally, the anonymous
|
||||
* structure has no additional members and so the flexible array member is
|
||||
* not valid within the anonymous structure.
|
||||
*/
|
||||
struct t {
|
||||
int i;
|
||||
struct { int a[]; }; /* expected-error {{flexible array member 'a' not allowed in otherwise empty struct}}
|
||||
c89only-warning {{flexible array members are a C99 feature}}
|
||||
expected-warning {{'' may not be nested in a struct due to flexible array member}}
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
|
@ -2632,7 +2632,7 @@ conformance.</p>
|
|||
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_496">496</a></td>
|
||||
<td>NAD</td>
|
||||
<td>offsetof questions</td>
|
||||
<td class="unknown" align="center">Unknown</td>
|
||||
<td class="full" align="center">Yes</td>
|
||||
</tr>
|
||||
<tr id="497">
|
||||
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_497">497</a></td>
|
||||
|
@ -2650,7 +2650,7 @@ conformance.</p>
|
|||
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_499">499</a></td>
|
||||
<td>C17</td>
|
||||
<td>Anonymous structure in union behavior</td>
|
||||
<td class="unknown" align="center">Unknown</td>
|
||||
<td class="full" align="center">Yes</td>
|
||||
</tr>
|
||||
<tr id="500">
|
||||
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_500">500</a></td>
|
||||
|
@ -2668,13 +2668,13 @@ conformance.</p>
|
|||
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_502">502</a></td>
|
||||
<td>NAD</td>
|
||||
<td>Flexible array member in an anonymous struct</td>
|
||||
<td class="unknown" align="center">Unknown</td>
|
||||
<td class="full" align="center">Yes</td>
|
||||
</tr>
|
||||
<tr id="503">
|
||||
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_503">503</a></td>
|
||||
<td>NAD</td>
|
||||
<td>Hexadecimal floating-point and strtod</td>
|
||||
<td class="unknown" align="center">Unknown</td>
|
||||
<td class="na" align="center">N/A</td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue