[clang] Enable unguarded availability diagnostic on instantiated template functions (PR #91699)

Helena Kotas via cfe-commits cfe-commits at lists.llvm.org
Fri May 10 11:11:21 PDT 2024


================
@@ -177,16 +177,19 @@ 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());
+  // 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
----------------
hekota wrote:

It is referenced in the expected-note above making sure the note is emitted for the correct line where the instantiation happens:

```
// expected-note@#f_char_inst {{in instantiation of function template specialization 'use_f<char>' requested here}}
```

https://github.com/llvm/llvm-project/pull/91699


More information about the cfe-commits mailing list