summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp7
-rw-r--r--clang/test/SemaCXX/no_destroy.cpp6
2 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 27eb533360c..d72b8fbb1aa 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5918,17 +5918,16 @@ static void handleOpenCLAccessAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
}
static void handleDestroyAttr(Sema &S, Decl *D, const ParsedAttr &A) {
- if (!isa<VarDecl>(D) || !cast<VarDecl>(D)->hasGlobalStorage()) {
+ if (!cast<VarDecl>(D)->hasGlobalStorage()) {
S.Diag(D->getLocation(), diag::err_destroy_attr_on_non_static_var)
<< (A.getKind() == ParsedAttr::AT_AlwaysDestroy);
return;
}
- if (A.getKind() == ParsedAttr::AT_AlwaysDestroy) {
+ if (A.getKind() == ParsedAttr::AT_AlwaysDestroy)
handleSimpleAttributeWithExclusions<AlwaysDestroyAttr, NoDestroyAttr>(S, D, A);
- } else {
+ else
handleSimpleAttributeWithExclusions<NoDestroyAttr, AlwaysDestroyAttr>(S, D, A);
- }
}
//===----------------------------------------------------------------------===//
diff --git a/clang/test/SemaCXX/no_destroy.cpp b/clang/test/SemaCXX/no_destroy.cpp
index bdb8077cb58..7afbf999825 100644
--- a/clang/test/SemaCXX/no_destroy.cpp
+++ b/clang/test/SemaCXX/no_destroy.cpp
@@ -38,3 +38,9 @@ int main() {
[[clang::always_destroy]] [[clang::no_destroy]] int p; // expected-error{{'no_destroy' and 'always_destroy' attributes are not compatible}} // expected-note{{here}}
[[clang::no_destroy]] [[clang::always_destroy]] int p2; // expected-error{{'always_destroy' and 'no_destroy' attributes are not compatible}} // expected-note{{here}}
+
+[[clang::always_destroy]] void f() {} // expected-warning{{'always_destroy' attribute only applies to variables}}
+struct [[clang::no_destroy]] DoesntApply {}; // expected-warning{{'no_destroy' attribute only applies to variables}}
+
+[[clang::no_destroy(0)]] int no_args; // expected-error{{'no_destroy' attribute takes no arguments}}
+[[clang::always_destroy(0)]] int no_args2; // expected-error{{'always_destroy' attribute takes no arguments}}
OpenPOWER on IntegriCloud