Author: Helena Kotas Date: 2024-05-24T10:43:24-07:00 New Revision: d07362f7a9fc06e2445f5c4bc62c10a339bf68a5
URL: https://github.com/llvm/llvm-project/commit/d07362f7a9fc06e2445f5c4bc62c10a339bf68a5 DIFF: https://github.com/llvm/llvm-project/commit/d07362f7a9fc06e2445f5c4bc62c10a339bf68a5.diff LOG: Enable unguarded availability diagnostic on instantiated template functions (#91699) Availability diagnostic in instantiated template functions was intentionally skipped in the original [commit](https://github.com/llvm/llvm-project/commit/5cd57177a51abc7b0bfe18f70566572dbccab9a0) 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. Added: Modified: clang/lib/Sema/SemaAvailability.cpp clang/test/SemaObjC/unguarded-availability.m Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp index 663b6f35b869d..22f5a2f663477 100644 --- a/clang/lib/Sema/SemaAvailability.cpp +++ b/clang/lib/Sema/SemaAvailability.cpp @@ -987,11 +987,6 @@ void Sema::DiagnoseUnguardedAvailabilityViolations(Decl *D) { Stmt *Body = nullptr; if (auto *FD = D->getAsFunction()) { - // FIXME: We only examine the pattern decl for availability violations now, - // but we should also examine instantiated templates. - if (FD->isTemplateInstantiation()) - return; - Body = FD->getBody(); if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) diff --git a/clang/test/SemaObjC/unguarded-availability.m b/clang/test/SemaObjC/unguarded-availability.m index d0e23eabcb598..ecd91990174ae 100644 --- a/clang/test/SemaObjC/unguarded-availability.m +++ b/clang/test/SemaObjC/unguarded-availability.m @@ -177,16 +177,28 @@ void justAtAvailable(void) { #ifdef OBJCPP -int f(char) AVAILABLE_10_12; +int f(char) AVAILABLE_10_12; // #f_char_def int f(int); template <class T> int use_f() { - // FIXME: We should warn here! - return f(T()); + if (@available(macos 10.12, *)) { + return f(T()); // no warning expected + } else { + // expected-warning@#f_call {{'f' is only available on macOS 10.12 or newer}} + // expected-note@#f_char_inst {{in instantiation of function template specialization 'use_f<char>' requested here}} + // 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}} + // expected-note@#f_call {{enclose 'f' in an @available check to silence this warning}} + return f(T()); // #f_call + } } int a = use_f<int>(); -int b = use_f<char>(); +int b = use_f<char>(); // #f_char_inst + +int use_f2() AVAILABLE_10_12 { + int c = use_f<int>(); + int d = use_f<char>(); // no warning expected +} template <class> int use_at_available() { if (@available(macos 10.12, *)) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits