Skip to content

Commit c9e7e76

Browse files
committed
[domain availability] Improve diagnostic messages
Convert `err_new_feature_redeclaration` to a warning that is error by default.
1 parent e4e6bcb commit c9e7e76

File tree

4 files changed

+70
-70
lines changed

4 files changed

+70
-70
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,7 +4101,7 @@ def warn_unguarded_availability :
41014101
Warning<"%0 is only available %select{|in %4 environment }3on %1 %2 or newer">,
41024102
InGroup<UnguardedAvailability>, DefaultIgnore;
41034103
def err_unguarded_feature : Error<
4104-
"use of %0 requires feature '%1' to be %select{available|unavailable}2">;
4104+
"cannot use %0 because feature '%1' is %select{unavailable|available}2 in this context">;
41054105
def err_label_in_conditionally_guarded_feature : Error<
41064106
"labels cannot appear in regions conditionally guarded by features">;
41074107
def err_features_invalid_for_decl : Error<
@@ -4114,8 +4114,8 @@ def err_feature_invalid_for_decl : Error<
41144114
"feature attribute '%0(%1)' cannot be applied to this decl">;
41154115
def err_feature_merge_incompatible : Error<
41164116
"cannot merge incompatible feature attribute to this decl">;
4117-
def err_new_feature_redeclaration : Error<
4118-
"new feature attributes cannot be added to redeclarations">;
4117+
def warn_new_feature_redeclaration : Warning<
4118+
"new domain availability attributes cannot be added to redeclarations">, DefaultError;
41194119
def err_feature_invalid_added : Error<
41204120
"cannot add feature availability to this decl">;
41214121
def note_feature_incompatible0 : Note<

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4083,7 +4083,7 @@ void Sema::copyFeatureAvailabilityCheck(Decl *Dst, NamedDecl *Src,
40834083
if (!DstToAttr.empty())
40844084
Dst->setInvalidDecl();
40854085
for (auto &P : DstToAttr)
4086-
Diag(P.second->getLocation(), diag::err_new_feature_redeclaration)
4086+
Diag(P.second->getLocation(), diag::warn_new_feature_redeclaration)
40874087
<< P.second->getFeatureAttributeStr();
40884088
}
40894089
}

clang/test/Sema/feature-availability.c

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,30 @@ __attribute__((availability(domain:feature1, UNAVAIL), availability(domain:featu
6262

6363
__attribute__((availability(macosx,introduced=10), availability(domain:feature1, AVAIL))) void func19(void);
6464

65-
int *g12 = &g0; // expected-error {{use of 'g0' requires feature 'feature1' to be available}}
66-
int g7 = sizeof(g0); // expected-error {{use of 'g0' requires feature 'feature1' to be available}}
65+
int *g12 = &g0; // expected-error {{cannot use 'g0' because feature 'feature1' is unavailable in this context}}
66+
int g7 = sizeof(g0); // expected-error {{cannot use 'g0' because feature 'feature1' is unavailable in this context}}
6767
__attribute__((availability(domain:feature1, AVAIL))) int g6 = sizeof(g0);
68-
__attribute__((availability(domain:feature1, UNAVAIL))) int g8 = sizeof(g0); // expected-error {{use of 'g0' requires feature 'feature1' to be available}}
69-
__attribute__((availability(domain:feature2, AVAIL))) int g9 = sizeof(g0); // expected-error {{use of 'g0' requires feature 'feature1' to be available}}
70-
void (*fp0)(void) = func6; // expected-error {{use of 'func6' requires feature 'feature1' to be available}}
68+
__attribute__((availability(domain:feature1, UNAVAIL))) int g8 = sizeof(g0); // expected-error {{cannot use 'g0' because feature 'feature1' is unavailable in this context}}
69+
__attribute__((availability(domain:feature2, AVAIL))) int g9 = sizeof(g0); // expected-error {{cannot use 'g0' because feature 'feature1' is unavailable in this context}}
70+
void (*fp0)(void) = func6; // expected-error {{cannot use 'func6' because feature 'feature1' is unavailable in this context}}
7171
void (* __attribute__((availability(domain:feature1, AVAIL))) fp1)(void) = func6;
72-
void (* __attribute__((availability(domain:feature1, UNAVAIL))) fp2)(void) = func6; // expected-error {{use of 'func6' requires feature 'feature1' to be available}}
73-
void (* __attribute__((availability(domain:feature2, AVAIL))) fp3)(void) = func6; // expected-error {{use of 'func6' requires feature 'feature1' to be available}}
72+
void (* __attribute__((availability(domain:feature1, UNAVAIL))) fp2)(void) = func6; // expected-error {{cannot use 'func6' because feature 'feature1' is unavailable in this context}}
73+
void (* __attribute__((availability(domain:feature2, AVAIL))) fp3)(void) = func6; // expected-error {{cannot use 'func6' because feature 'feature1' is unavailable in this context}}
7474

7575
void func6(void);
7676
__attribute__((availability(domain:feature1, AVAIL))) void func6(void); // expected-note {{is incompatible with __attribute__((availability(domain:feature1, 0)))}}
7777
__attribute__((availability(domain:feature1, UNAVAIL))) void func6(void); // expected-error {{cannot merge incompatible feature attribute to this decl}} expected-note {{feature attribute __attribute__((availability(domain:feature1, 1)))}}
78-
__attribute__((availability(domain:feature1, AVAIL))) void func8(void); // expected-error {{new feature attributes cannot be added to redeclarations}}
78+
__attribute__((availability(domain:feature1, AVAIL))) void func8(void); // expected-error {{new domain availability attributes cannot be added to redeclarations}}
7979

8080
int g0;
8181
__attribute__((availability(domain:feature1, AVAIL))) int g0; // expected-note {{is incompatible with __attribute__((availability(domain:feature1, 0)))}}
8282
__attribute__((availability(domain:feature1, UNAVAIL))) int g0; // expected-error {{cannot merge incompatible feature attribute to this decl}} expected-note {{feature attribute __attribute__((availability(domain:feature1, 1)))}}
83-
__attribute__((availability(domain:feature1, AVAIL))) int g2;// expected-error {{new feature attributes cannot be added to redeclarations}}
83+
__attribute__((availability(domain:feature1, AVAIL))) int g2;// expected-error {{new domain availability attributes cannot be added to redeclarations}}
8484

8585
typedef int INT0 __attribute__((availability(domain:feature2, AVAIL)));
8686
typedef INT0 INT1 __attribute__((availability(domain:feature2, AVAIL)));
87-
typedef INT0 INT2 __attribute__((availability(domain:feature2, UNAVAIL))); // expected-error {{use of 'INT0' requires feature 'feature2' to be available}}
88-
typedef INT0 INT3 __attribute__((availability(domain:feature1, AVAIL))); // expected-error {{use of 'INT0' requires feature 'feature2' to be available}}
87+
typedef INT0 INT2 __attribute__((availability(domain:feature2, UNAVAIL))); // expected-error {{cannot use 'INT0' because feature 'feature2' is unavailable in this context}}
88+
typedef INT0 INT3 __attribute__((availability(domain:feature1, AVAIL))); // expected-error {{cannot use 'INT0' because feature 'feature2' is unavailable in this context}}
8989

9090
enum __attribute__((availability(domain:feature1, AVAIL))) E {
9191
EA,
@@ -101,84 +101,84 @@ struct __attribute__((availability(domain:feature1, AVAIL))) S1 {
101101
};
102102

103103
struct S2 {
104-
struct S0 s0; // expected-error {{use of 'S0' requires feature 'feature1' to be available}}
104+
struct S0 s0; // expected-error {{cannot use 'S0' because feature 'feature1' is unavailable in this context}}
105105
int i0 __attribute__((availability(domain:feature1, AVAIL))); // expected-error {{feature attributes cannot be applied to struct members}}
106106
};
107107

108-
struct S0 g10; // expected-error {{use of 'S0' requires feature 'feature1' to be available}}
108+
struct S0 g10; // expected-error {{cannot use 'S0' because feature 'feature1' is unavailable in this context}}
109109
__attribute__((availability(domain:feature1, AVAIL))) struct S0 g11;
110110

111111
void test0(void) {
112-
func12(); // expected-error {{use of 'func12' requires feature 'feature1' to be available}}
113-
func7(); // expected-error {{use of 'func7' requires feature 'feature1' to be unavailable}}
114-
func19(); // expected-error {{use of 'func19' requires feature 'feature1' to be available}}
112+
func12(); // expected-error {{cannot use 'func12' because feature 'feature1' is unavailable in this context}}
113+
func7(); // expected-error {{cannot use 'func7' because feature 'feature1' is available in this context}}}
114+
func19(); // expected-error {{cannot use 'func19' because feature 'feature1' is unavailable in this context}}
115115

116116
if (__builtin_available(domain:feature1, domain:feature2)) // expected-error {{cannot pass a domain argument along with other arguments}}
117117
;
118118

119119
if (__builtin_available(domain:feature1)) {
120120
func12();
121-
func7(); // expected-error {{use of 'func7' requires feature 'feature1' to be unavailable}}
122-
func13(); // expected-error {{use of 'func13' requires feature 'feature2' to be available}}
121+
func7(); // expected-error {{cannot use 'func7' because feature 'feature1' is available in this context}}}
122+
func13(); // expected-error {{cannot use 'func13' because feature 'feature2' is unavailable in this context}}
123123
if (__builtin_available(domain:feature2)) {
124124
func13();
125-
func9(); // expected-error {{use of 'func9' requires feature 'feature2' to be unavailable}}
125+
func9(); // expected-error {{cannot use 'func9' because feature 'feature2' is available in this context}}}
126126
func12();
127127
} else {
128-
func13(); // expected-error {{use of 'func13' requires feature 'feature2' to be available}}
128+
func13(); // expected-error {{cannot use 'func13' because feature 'feature2' is unavailable in this context}}
129129
func9();
130130
func12();
131131
}
132132
} else {
133-
func12(); // expected-error {{use of 'func12' requires feature 'feature1' to be available}}
133+
func12(); // expected-error {{cannot use 'func12' because feature 'feature1' is unavailable in this context}}
134134
func7();
135135
}
136136
}
137137

138138
__attribute__((availability(domain:feature1, AVAIL)))
139139
void test1(void) {
140140
func12();
141-
func7(); // expected-error {{use of 'func7' requires feature 'feature1' to be unavailable}}
141+
func7(); // expected-error {{cannot use 'func7' because feature 'feature1' is available in this context}}}
142142
}
143143

144144
__attribute__((availability(domain:feature1, UNAVAIL)))
145145
void test2(void) {
146-
func12(); // expected-error {{use of 'func12' requires feature 'feature1' to be available}}
146+
func12(); // expected-error {{cannot use 'func12' because feature 'feature1' is unavailable in this context}}
147147
func7();
148148
}
149149

150150
__attribute__((availability(domain:feature3, AVAIL)))
151151
void test3(void) {
152152
^ {
153-
func12(); // expected-error {{use of 'func12' requires feature 'feature1' to be available}}
154-
func7(); // expected-error {{use of 'func7' requires feature 'feature1' to be unavailable}}
153+
func12(); // expected-error {{cannot use 'func12' because feature 'feature1' is unavailable in this context}}
154+
func7(); // expected-error {{cannot use 'func7' because feature 'feature1' is available in this context}}}
155155
func20();
156156
}();
157157

158158
if (__builtin_available(domain:feature1)) {
159159
^{
160160
func12();
161-
func7(); // expected-error {{use of 'func7' requires feature 'feature1' to be unavailable}}
161+
func7(); // expected-error {{cannot use 'func7' because feature 'feature1' is available in this context}}}
162162
func20();
163163
if (__builtin_available(domain:feature2)) {
164164
func13();
165-
func9(); // expected-error {{use of 'func9' requires feature 'feature2' to be unavailable}}
165+
func9(); // expected-error {{cannot use 'func9' because feature 'feature2' is available in this context}}}
166166
} else {
167-
func13(); // expected-error {{use of 'func13' requires feature 'feature2' to be available}}
167+
func13(); // expected-error {{cannot use 'func13' because feature 'feature2' is unavailable in this context}}
168168
func9();
169169
}
170170
}();
171171
} else {
172172
^{
173-
func12(); // expected-error {{use of 'func12' requires feature 'feature1' to be available}}
173+
func12(); // expected-error {{cannot use 'func12' because feature 'feature1' is unavailable in this context}}
174174
func7();
175175
func20();
176176
}();
177177
}
178178
}
179179

180-
void test4(struct S0 *s0) { // expected-error {{use of 'S0' requires feature 'feature1' to be available}}
181-
g11.i0 = 0; // expected-error {{use of 'g11' requires feature 'feature1' to be available}} expected-error {{use of 'i0' requires feature 'feature1' to be available}}
180+
void test4(struct S0 *s0) { // expected-error {{cannot use 'S0' because feature 'feature1' is unavailable in this context}}
181+
g11.i0 = 0; // expected-error {{cannot use 'g11' because feature 'feature1' is unavailable in this context}} expected-error {{cannot use 'i0' because feature 'feature1' is unavailable in this context}}
182182
}
183183

184184
void test5(int c) {
@@ -203,44 +203,44 @@ void test6(void) {
203203
if (__builtin_available(domain:feature1)) {
204204
if (__builtin_available(domain:feature2)) {
205205
func15();
206-
func16(); // expected-error {{use of 'func16' requires feature 'feature2' to be unavailable}}
207-
func17(); // expected-error {{use of 'func17' requires feature 'feature1' to be unavailable}}
208-
func18(); // expected-error {{use of 'func18' requires feature 'feature1' to be unavailable}} expected-error {{use of 'func18' requires feature 'feature2' to be unavailable}}
206+
func16(); // expected-error {{cannot use 'func16' because feature 'feature2' is available in this context}}}
207+
func17(); // expected-error {{cannot use 'func17' because feature 'feature1' is available in this context}}}
208+
func18(); // expected-error {{cannot use 'func18' because feature 'feature1' is available in this context}}} expected-error {{cannot use 'func18' because feature 'feature2' is available in this context}}}
209209
} else {
210-
func15(); // expected-error {{use of 'func15' requires feature 'feature2' to be available}}
210+
func15(); // expected-error {{cannot use 'func15' because feature 'feature2' is unavailable in this context}}
211211
func16();
212-
func17(); // expected-error {{use of 'func17' requires feature 'feature1' to be unavailable}} expected-error {{use of 'func17' requires feature 'feature2' to be available}}
213-
func18(); // expected-error {{use of 'func18' requires feature 'feature1' to be unavailable}}
212+
func17(); // expected-error {{cannot use 'func17' because feature 'feature1' is available in this context}}} expected-error {{cannot use 'func17' because feature 'feature2' is unavailable in this context}}
213+
func18(); // expected-error {{cannot use 'func18' because feature 'feature1' is available in this context}}}
214214
}
215215
} else {
216216
if (__builtin_available(domain:feature2)) {
217-
func15(); // expected-error {{use of 'func15' requires feature 'feature1' to be available}}
218-
func16(); // expected-error {{use of 'func16' requires feature 'feature1' to be available}} expected-error {{use of 'func16' requires feature 'feature2' to be unavailable}}
217+
func15(); // expected-error {{cannot use 'func15' because feature 'feature1' is unavailable in this context}}
218+
func16(); // expected-error {{cannot use 'func16' because feature 'feature1' is unavailable in this context}} expected-error {{cannot use 'func16' because feature 'feature2' is available in this context}}}
219219
func17();
220-
func18(); // expected-error {{use of 'func18' requires feature 'feature2' to be unavailable}}
220+
func18(); // expected-error {{cannot use 'func18' because feature 'feature2' is available in this context}}}
221221
} else {
222-
func15(); // expected-error {{use of 'func15' requires feature 'feature1' to be available}} expected-error {{use of 'func15' requires feature 'feature2' to be available}}
223-
func16(); // expected-error {{use of 'func16' requires feature 'feature1' to be available}}
224-
func17(); // expected-error {{use of 'func17' requires feature 'feature2' to be available}}
222+
func15(); // expected-error {{cannot use 'func15' because feature 'feature1' is unavailable in this context}} expected-error {{cannot use 'func15' because feature 'feature2' is unavailable in this context}}
223+
func16(); // expected-error {{cannot use 'func16' because feature 'feature1' is unavailable in this context}}
224+
func17(); // expected-error {{cannot use 'func17' because feature 'feature2' is unavailable in this context}}
225225
func18();
226226
}
227227
}
228228
}
229229

230230
void test7(void) {
231-
enum E e; // expected-error {{use of 'E' requires feature 'feature1' to be available}}
232-
struct S0 s0; // expected-error {{use of 'S0' requires feature 'feature1' to be available}}
231+
enum E e; // expected-error {{cannot use 'E' because feature 'feature1' is unavailable in this context}}
232+
struct S0 s0; // expected-error {{cannot use 'S0' because feature 'feature1' is unavailable in this context}}
233233

234234
if (__builtin_available(domain:feature1)) {
235235
enum E e;
236236
e = EA;
237-
e = EB; // expected-error {{use of 'EB' requires feature 'feature2' to be available}}
237+
e = EB; // expected-error {{cannot use 'EB' because feature 'feature2' is unavailable in this context}}
238238
}
239239

240240
if (__builtin_available(domain:feature2)) {
241-
enum E e; // expected-error {{use of 'E' requires feature 'feature1' to be available}}
242-
e = EA; // expected-error {{use of 'EA' requires feature 'feature1' to be available}}
243-
e = EB; // expected-error {{use of 'EB' requires feature 'feature1' to be available}}
241+
enum E e; // expected-error {{cannot use 'E' because feature 'feature1' is unavailable in this context}}
242+
e = EA; // expected-error {{cannot use 'EA' because feature 'feature1' is unavailable in this context}}
243+
e = EB; // expected-error {{cannot use 'EB' because feature 'feature1' is unavailable in this context}}
244244
}
245245
}
246246

0 commit comments

Comments
 (0)