Skip to content

Commit 143ec50

Browse files
committed
[Sema] Fix a bug where clang doesn't detect uses of unavailable decls
in C++ base or member initializers Differential Revision: https://reviews.llvm.org/D127442
1 parent ea0cd51 commit 143ec50

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Sema/SemaAvailability.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,11 @@ void Sema::DiagnoseUnguardedAvailabilityViolations(Decl *D) {
898898
return;
899899

900900
Body = FD->getBody();
901+
902+
if (auto *CD = dyn_cast<CXXConstructorDecl>(FD))
903+
for (const CXXCtorInitializer *CI : CD->inits())
904+
DiagnoseUnguardedAvailability(*this, D).IssueDiagnostics(CI->getInit());
905+
901906
} else if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
902907
Body = MD->getBody();
903908
else if (auto *BD = dyn_cast<BlockDecl>(D))
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9.0 -std=c++11 -fsyntax-only -verify %s
2+
3+
__attribute__((availability(macos, introduced = 10.0))) int init10();
4+
__attribute__((availability(macos, introduced = 11.0))) int init11(); // expected-note 2 {{'init11' has been marked as being introduced in macOS 11.0}}
5+
6+
struct B0 {
7+
B0(int);
8+
};
9+
10+
struct B1 {
11+
B1(int);
12+
};
13+
14+
struct S : B0, B1 {
15+
S() : B0(init10()),
16+
B1(init11()), // expected-warning {{'init11' is only available on macOS 11.0}} expected-note {{enclose 'init11'}}
17+
i0(init10()),
18+
i1(init11()) // expected-warning {{'init11' is only available on macOS 11.0}} expected-note {{enclose 'init11'}}
19+
{}
20+
int i0, i1;
21+
};

0 commit comments

Comments
 (0)