From 2b1d51bcf891f8887759aebb4b9e78dee8542e6d Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 5 Oct 2010 23:24:00 +0000 Subject: [PATCH] Issue deprecated warning when typeof uses an 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 | 8 +++++++- test/Sema/typeof-use-deprecated.c | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/Sema/typeof-use-deprecated.c diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 542c31abfc..1a084dad70 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -2211,7 +2211,13 @@ QualType Sema::BuildTypeofExprType(Expr *E) { return QualType(); } } - + if (!E->isTypeDependent()) { + QualType T = E->getType(); + if (const RecordType *EltTy = T->getAs()) + DiagnoseUseOfDecl(EltTy->getDecl(), E->getExprLoc()); + else if (const EnumType *Enum = T->getAs()) + 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 index 0000000000..2e080bae1f --- /dev/null +++ b/test/Sema/typeof-use-deprecated.c @@ -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}} -- 2.40.0