File tree Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -1874,9 +1874,11 @@ ExprResult Sema::CreateGenericSelectionExpr(
1874
1874
1875
1875
if (D != 0) {
1876
1876
Diag(Types[i]->getTypeLoc().getBeginLoc(), D)
1877
- << Types[i]->getTypeLoc().getSourceRange()
1878
- << Types[i]->getType();
1879
- TypeErrorFound = true;
1877
+ << Types[i]->getTypeLoc().getSourceRange() << Types[i]->getType();
1878
+ if (getDiagnostics().getDiagnosticLevel(
1879
+ D, Types[i]->getTypeLoc().getBeginLoc()) >=
1880
+ DiagnosticsEngine::Error)
1881
+ TypeErrorFound = true;
1880
1882
}
1881
1883
1882
1884
// C11 6.5.1.1p2 "No two generic associations in the same generic
Original file line number Diff line number Diff line change 1
- // RUN: %clang_cc1 -verify -std=c2y -pedantic %s
2
- // RUN: %clang_cc1 -verify=pre-c2y -std=c2y -Wpre-c2y-compat %s
3
- // RUN: %clang_cc1 -verify=ext -std=c23 -pedantic %s
4
- // expected-no-diagnostics
1
+ // RUN: %clang_cc1 -verify -std=c2y -pedantic -Wno-unused %s
2
+ // RUN: %clang_cc1 -verify=expected,pre-c2y -std=c2y -Wpre-c2y-compat -Wno-unused %s
3
+ // RUN: %clang_cc1 -verify=expected,ext -std=c23 -pedantic -Wno-unused %s
5
4
6
5
/* WG14 N3409: Clang 21
7
6
* Slay Some Earthly Demons X
@@ -34,3 +33,25 @@ void foo() {
34
33
// C23 and earlier.
35
34
return x ; // ext-warning {{void function 'foo' should not return void expression}}
36
35
}
36
+
37
+
38
+ // Ensure we behave correctly with incomplete types. See GH141549.
39
+ static_assert (
40
+ _Generic(
41
+ void , /* ext-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
42
+ pre-c2y-warning {{passing a type argument as the first operand to '_Generic' is incompatible with C standards before C2y}}
43
+ */
44
+ void : 1 ,
45
+ default : 0
46
+ )
47
+ );
48
+
49
+ static_assert (
50
+ _Generic( // expected-error {{static assertion failed}}
51
+ 12 ,
52
+ void : 1 , /* ext-warning {{incomplete type 'void' in a '_Generic' association is a C2y extension}}
53
+ pre-c2y-warning {{use of incomplete type 'void' in a '_Generic' association is incompatible with C standards before C2y}}
54
+ */
55
+ default : 0
56
+ )
57
+ );
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ void func(struct S s) {
81
81
// is an elaborated type specifier followed by the association's value and
82
82
// it should work the same as in C.
83
83
(void )_Generic (s, struct S : 1 );
84
- (void )_Generic (s, struct T : 1 );
84
+ (void )_Generic (s, struct T : 1 ); // expected-error {{controlling expression type 'struct S' not compatible with any generic association type}}
85
85
86
86
// The rest of these cases test that we still produce a reasonable diagnostic
87
87
// when referencing an unknown type or trying to define a type in other ways.
You can’t perform that action at this time.
0 commit comments