r237396 - Tweak availability checking to look through typedef declarations.
Ted Kremenek
kremenek at apple.com
Thu May 14 15:07:25 PDT 2015
Author: kremenek
Date: Thu May 14 17:07:25 2015
New Revision: 237396
URL: http://llvm.org/viewvc/llvm-project?rev=237396&view=rev
Log:
Tweak availability checking to look through typedef declarations.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/attr-availability.m
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=237396&r1=237395&r2=237396&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 14 17:07:25 2015
@@ -104,13 +104,29 @@ DiagnoseAvailabilityOfDecl(Sema &S, Name
bool ObjCPropertyAccess) {
// See if this declaration is unavailable or deprecated.
std::string Message;
+ AvailabilityResult Result = D->getAvailability(&Message);
+
+ // For typedefs, if the typedef declaration appears available look
+ // to the underlying type to see if it is more restrictive.
+ while (const TypedefNameDecl *TD = TD = dyn_cast<TypedefNameDecl>(D)) {
+ if (Result == AR_Available) {
+ if (const TagType *TT = TD->getUnderlyingType()->getAs<TagType>()) {
+ D = TT->getDecl();
+ Result = D->getAvailability(&Message);
+ continue;
+ }
+ }
+ break;
+ }
// Forward class declarations get their attributes from their definition.
if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) {
- if (IDecl->getDefinition())
+ if (IDecl->getDefinition()) {
D = IDecl->getDefinition();
+ Result = D->getAvailability(&Message);
+ }
}
- AvailabilityResult Result = D->getAvailability(&Message);
+
if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D))
if (Result == AR_Available) {
const DeclContext *DC = ECD->getDeclContext();
Modified: cfe/trunk/test/SemaObjC/attr-availability.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-availability.m?rev=237396&r1=237395&r2=237396&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-availability.m (original)
+++ cfe/trunk/test/SemaObjC/attr-availability.m Thu May 14 17:07:25 2015
@@ -190,3 +190,19 @@ void partialinter1(PartialI2* p) {
void partialinter2(PartialI2* p) { // no warning
}
+
+
+// Test that both the use of the 'typedef' and the enum constant
+// produces an error. rdar://problem/20903588
+#define UNAVAILABLE __attribute__((unavailable("not available")))
+
+typedef enum MyEnum : int MyEnum;
+enum MyEnum : int { // expected-note {{'MyEnum' has been explicitly marked unavailable here}}
+ MyEnum_Blah UNAVAILABLE, // expected-note {{'MyEnum_Blah' has been explicitly marked unavailable here}}
+} UNAVAILABLE;
+
+void use_myEnum() {
+ // expected-error at +2 {{'MyEnum' is unavailable: not available}}
+ // expected-error at +1 {{MyEnum_Blah' is unavailable: not available}}
+ MyEnum e = MyEnum_Blah;
+}
More information about the cfe-commits
mailing list