Skip to content

Commit 670fa2b

Browse files
Xazax-hunGabor Horvath
andauthored
Fix spurious non-strict availability warning (#94377)
The availability attributes are stored on the function declarations. The code was looking for them in the function template declarations. This resulted in spuriously diagnosing (non-strict) availablity issues in contexts that are not available. Co-authored-by: Gabor Horvath <[email protected]>
1 parent d231b50 commit 670fa2b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

clang/include/clang/Sema/Initialization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class alignas(8) InitializedEntity {
212212
struct C Capture;
213213
};
214214

215-
InitializedEntity() {};
215+
InitializedEntity() {}
216216

217217
/// Create the initialization entity for a variable.
218218
InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable)

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "clang/AST/Attr.h"
1414
#include "clang/AST/Decl.h"
15+
#include "clang/AST/DeclTemplate.h"
1516
#include "clang/AST/RecursiveASTVisitor.h"
1617
#include "clang/Basic/DiagnosticSema.h"
1718
#include "clang/Basic/IdentifierTable.h"
@@ -46,6 +47,10 @@ static const AvailabilityAttr *getAttrForPlatform(ASTContext &Context,
4647
// Check each AvailabilityAttr to find the one for this platform.
4748
// For multiple attributes with the same platform try to find one for this
4849
// environment.
50+
// The attribute is always on the FunctionDecl, not on the
51+
// FunctionTemplateDecl.
52+
if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
53+
D = FTD->getTemplatedDecl();
4954
for (const auto *A : D->attrs()) {
5055
if (const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
5156
// FIXME: this is copied from CheckAvailability. We should try to
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 "-triple" "arm64-apple-macosx10.15" -fsyntax-only -verify %s
2+
3+
__attribute__((availability(macos,introduced=11)))
4+
inline bool try_acquire() {
5+
return true;
6+
}
7+
8+
template <class T>
9+
__attribute__((availability(macos,introduced=11)))
10+
bool try_acquire_for(T duration) { // expected-note{{'try_acquire_for<int>' has been marked as being introduced in macOS 11 here, but the deployment target is macOS 10.15}}
11+
return try_acquire();
12+
}
13+
14+
int main() {
15+
try_acquire_for(1); // expected-warning{{'try_acquire_for<int>' is only available on macOS 11 or newer}}
16+
// expected-note@-1{{enclose 'try_acquire_for<int>' in a __builtin_available check to silence this warning}}
17+
}

0 commit comments

Comments
 (0)