Skip to content

Commit d07362f

Browse files
authored
Enable unguarded availability diagnostic on instantiated template functions (#91699)
Availability diagnostic in instantiated template functions was intentionally skipped in the original [commit](5cd5717) years ago with a FIXME note. I ran into this when working on diagnostics for HLSL. When I remove the skip, it seems to be working just fine outputting expected messages. So, unless I am missing something, I would keep it enabled and use it for checking availability in HLSL templates as well.
1 parent 8d2258f commit d07362f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,6 @@ void Sema::DiagnoseUnguardedAvailabilityViolations(Decl *D) {
987987
Stmt *Body = nullptr;
988988

989989
if (auto *FD = D->getAsFunction()) {
990-
// FIXME: We only examine the pattern decl for availability violations now,
991-
// but we should also examine instantiated templates.
992-
if (FD->isTemplateInstantiation())
993-
return;
994-
995990
Body = FD->getBody();
996991

997992
if (auto *CD = dyn_cast<CXXConstructorDecl>(FD))

clang/test/SemaObjC/unguarded-availability.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,28 @@ void justAtAvailable(void) {
177177

178178
#ifdef OBJCPP
179179

180-
int f(char) AVAILABLE_10_12;
180+
int f(char) AVAILABLE_10_12; // #f_char_def
181181
int f(int);
182182

183183
template <class T> int use_f() {
184-
// FIXME: We should warn here!
185-
return f(T());
184+
if (@available(macos 10.12, *)) {
185+
return f(T()); // no warning expected
186+
} else {
187+
// expected-warning@#f_call {{'f' is only available on macOS 10.12 or newer}}
188+
// expected-note@#f_char_inst {{in instantiation of function template specialization 'use_f<char>' requested here}}
189+
// expected-note@#f_char_def {{'f' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
190+
// expected-note@#f_call {{enclose 'f' in an @available check to silence this warning}}
191+
return f(T()); // #f_call
192+
}
186193
}
187194

188195
int a = use_f<int>();
189-
int b = use_f<char>();
196+
int b = use_f<char>(); // #f_char_inst
197+
198+
int use_f2() AVAILABLE_10_12 {
199+
int c = use_f<int>();
200+
int d = use_f<char>(); // no warning expected
201+
}
190202

191203
template <class> int use_at_available() {
192204
if (@available(macos 10.12, *))

0 commit comments

Comments
 (0)