]> granicus.if.org Git - clang/commitdiff
Issue deprecated warning when typeof uses an
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 5 Oct 2010 23:24:00 +0000 (23:24 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 5 Oct 2010 23:24:00 +0000 (23:24 +0000)
expression of deprecated type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115713 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/Sema/typeof-use-deprecated.c [new file with mode: 0644]

index 542c31abfc48e6c860abcd85c050a490594a8599..1a084dad70e121f036f693c7cc34347d7bc72d39 100644 (file)
@@ -2211,7 +2211,13 @@ QualType Sema::BuildTypeofExprType(Expr *E) {
       return QualType();
     }
   }
-  
+  if (!E->isTypeDependent()) {
+    QualType T = E->getType();
+    if (const RecordType *EltTy = T->getAs<RecordType>())
+      DiagnoseUseOfDecl(EltTy->getDecl(), E->getExprLoc());
+    else if (const EnumType *Enum = T->getAs<EnumType>())
+      DiagnoseUseOfDecl(Enum->getDecl(), E->getExprLoc());
+  }
   return Context.getTypeOfExprType(E);
 }
 
diff --git a/test/Sema/typeof-use-deprecated.c b/test/Sema/typeof-use-deprecated.c
new file mode 100644 (file)
index 0000000..2e080ba
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+struct s { int a; } __attribute__((deprecated)) x;  // expected-warning {{'s' is deprecated}}
+
+typeof(x) y;  // expected-warning {{'s' is deprecated}}
+
+union un{ int a; } __attribute__((deprecated)) u;  // expected-warning {{'un' is deprecated}}
+
+typeof(     u) z; // expected-warning {{'un' is deprecated}}
+
+enum E{ one} __attribute__((deprecated))  e; // expected-warning {{'E' is deprecated}} 
+
+typeof( e) w; // expected-warning {{'E' is deprecated}}