Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 8e42f27

Browse files
committed
When determining the availability of an enum constant, also consider
the availability of the enumeration type itself. Fixes <rdar://problem/10996386>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152977 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 74b7b2b commit 8e42f27

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Diff for: lib/Sema/CodeCompleteConsumer.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,19 @@ PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
400400
}
401401
}
402402

403+
/// \brief Retrieve the effective availability of the given declaration.
404+
static AvailabilityResult getDeclAvailability(Decl *D) {
405+
AvailabilityResult AR = D->getAvailability();
406+
if (isa<EnumConstantDecl>(D))
407+
AR = std::max(AR, cast<Decl>(D->getDeclContext())->getAvailability());
408+
return AR;
409+
}
410+
403411
void CodeCompletionResult::computeCursorKindAndAvailability(bool Accessible) {
404412
switch (Kind) {
405-
case RK_Declaration:
413+
case RK_Declaration: {
406414
// Set the availability based on attributes.
407-
switch (Declaration->getAvailability()) {
415+
switch (getDeclAvailability(Declaration)) {
408416
case AR_Available:
409417
case AR_NotYetIntroduced:
410418
Availability = CXAvailability_Available;
@@ -436,6 +444,7 @@ void CodeCompletionResult::computeCursorKindAndAvailability(bool Accessible) {
436444
CursorKind = CXCursor_NotImplemented;
437445
}
438446
break;
447+
}
439448

440449
case RK_Macro:
441450
Availability = CXAvailability_Available;

Diff for: test/Index/complete-enums.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// Note: the run lines follow their respective tests, since line/column
22
// matter in this test.
33

4-
enum Color {
4+
enum __attribute__((deprecated)) Color {
55
Color_Red = 17,
66
Color_Green,
77
Color_Blue
88
};
99
int Greeby();
10-
void f(Color color) {
10+
void f(enum Color color) {
1111
switch (color) {
1212
case Red:
1313
}
1414
}
1515

1616
// RUN: c-index-test -code-completion-at=%s:11:1 %s | FileCheck -check-prefix=CHECK-CC1 %s
17-
// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Red}
17+
// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Red} (65) (deprecated)
1818

1919
// RUN: c-index-test -code-completion-at=%s:12:8 %s | FileCheck -check-prefix=CHECK-CC2 %s
20-
// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Blue} (7)
21-
// CHECK-CC2-NEXT: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Green} (7)
22-
// CHECK-CC2-NEXT: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Red} (7)
20+
// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Blue} (7) (deprecated)
21+
// CHECK-CC2-NEXT: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Green} (7) (deprecated)
22+
// CHECK-CC2-NEXT: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Red} (7) (deprecated)

0 commit comments

Comments
 (0)