Skip to content

Commit bcda3a6

Browse files
committed
Updated test cases and annoted what should be worked on
1 parent 3b9b9e8 commit bcda3a6

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ C23 Feature Support
348348
but C23 added them to ``<float.h>`` in
349349
`WG14 N2848 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2848.pdf>`_.
350350

351-
- Clang now diagnoses `N3006 Underspecified object declarations
351+
- Clang now diagnoses `N3006 Underspecified object declarations`
352352
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3006.htm>`_.
353353

354354
Non-comprehensive list of changes in this release

clang/test/C/C23/n3006.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,42 @@ auto normal_enum_bar = (enum E1){ BAR };
2525
auto underspecified_enum = (enum E2 { BAZ, QUX }){ BAZ }; // expected-error {{'enum E2' is defined as an underspecified object initializer}}
2626
auto underspecified_enum_redef = (enum E1 { ONE, TWO }){ ONE }; // expected-error {{redefinition of 'E1'}}
2727
auto underspecified_empty_enum = (enum E3 { }){ }; // expected-error {{'enum E3' is defined as an underspecified object initializer}} \
28-
expected-error {{use of empty enum}}
29-
30-
// Constexpr tests
31-
constexpr auto ce_struct = (struct S1){ 1, 2 };
32-
constexpr auto ce_union = (union U1){ .a = 12 };
33-
constexpr auto ce_enum = (enum E1){ FOO };
28+
expected-error {{use of empty enum}}
29+
void constexpr_test() {
30+
constexpr auto ce_struct = (struct S1){ 1, 2 };
31+
constexpr auto ce_union = (union U1){ .a = 12 };
32+
constexpr auto ce_enum = (enum E1){ FOO };
33+
}
3434

35-
int func() {
36-
struct S { int x, y; };
37-
constexpr int i = (struct T { int a, b; }){0, 1}.a;
35+
void trivial_test() {
36+
constexpr int i = i; // expected-error {{constexpr variable 'i' must be initialized by a constant expression}} \
37+
expected-note {{read of object outside its lifetime is not allowed in a constant expression}}
38+
auto j = j; // expected-error {{variable 'j' declared with deduced type 'auto' cannot appear in its own initializer}}
39+
}
3840

39-
struct T t = { 1, 2 };
41+
void double_definition_test() {
42+
const struct S { int x; } s; // expected-note {{previous definition is here}}
43+
constexpr struct S s = {0}; // expected-error {{redefinition of 's'}}
4044
}
4145

42-
void func2() {
43-
int x = (struct Foo { int x; }){ 0 }.x;
46+
void declaring_an_underspecified_defied_object_test() {
47+
struct S { int x, y; };
48+
constexpr int i = (struct T { int a, b; }){0, 1}.a; // expected-error {{'struct T' is defined as an underspecified object initializer}} \
49+
FIXME: `constexpr variable 'i' must be initialized by a constant expression` shoud appear
50+
51+
struct T t = { 1, 2 }; // TODO: Should this be diagnosed as an invalid declaration?
4452
}
4553

46-
void func3() {
47-
constexpr int x = (struct Foo { int x; }){ 0 }.x;
54+
void constexpr_complience_test() {
55+
int x = (struct Foo { int x; }){ 0 }.x; // expected-error {{'struct Foo' is defined as an underspecified object initializer}}
56+
constexpr int y = (struct Bar { int x; }){ 0 }.x; // expected-error {{'struct Bar' is defined as an underspecified object initializer}}
4857
}
4958

50-
void test() {
51-
constexpr typeof(struct s *) x = 0; // declares `s` which is not an ordinary identifier
52-
constexpr struct S { int a, b; } y = { 0 }; // declares `S`, `a`, and `b`, none of which are ordinary identifiers
53-
constexpr int a = 0, b = 0; // declares `a` and `b` as ordinary identifiers
54-
auto c = (struct T { int x, y; }){0, 0}; // declares `T`, `x`, and `y`, none of which are ordinary identifiers
55-
constexpr int (*fp)(struct X { int x; } val) = 0; // declares `X` and `x` which are not ordinary identifiers
59+
void special_test() {
60+
constexpr typeof(struct s *) x = 0; // FIXME: declares `s` which is not an ordinary identifier
61+
constexpr struct S { int a, b; } y = { 0 }; // FIXME: declares `S`, `a`, and `b`, none of which are ordinary identifiers
62+
constexpr int a = 0, b = 0;
63+
auto c = (struct T { int x, y; }){0, 0}; // expected-error {{'struct T' is defined as an underspecified object initializer}}
64+
constexpr int (*fp)(struct X { int x; } val) = 0; // expected-warning {{declaration of 'struct X' will not be visible outside of this function}} \
65+
FIXME: declares `X` and `x` which are not ordinary identifiers
5666
}

0 commit comments

Comments
 (0)