diff options
author | Erich Keane <erich.keane@intel.com> | 2017-03-23 18:51:54 +0000 |
---|---|---|
committer | Erich Keane <erich.keane@intel.com> | 2017-03-23 18:51:54 +0000 |
commit | a32910da1ac5f7c3a2a97d1e5e2050cebe109ae7 (patch) | |
tree | 1fe265e3a57a7b15191170fe17e15218b8b382aa /clang/test | |
parent | 9ebefeb9b1ee22c3ad5036dad131cb960d709662 (diff) | |
download | bcm5719-llvm-a32910da1ac5f7c3a2a97d1e5e2050cebe109ae7.tar.gz bcm5719-llvm-a32910da1ac5f7c3a2a97d1e5e2050cebe109ae7.zip |
Correct class-template deprecation behavior-REDUX
Correct class-template deprecation behavior
Based on the comment in the test, and my reading of the standard, a deprecated warning should be issued in the following case:
template<typename T> [[deprecated]] class Foo{}; Foo<int> f;
This was not the case, because the ClassTemplateSpecializationDecl creation did not also copy the deprecated attribute.
Note: I did NOT audit the complete set of attributes to see WHICH ones should be copied, so instead I simply copy ONLY the deprecated attribute.
Previous DiffRev: https://reviews.llvm.org/D27486, was reverted.
This patch fixes the issues brought up here by the reverter: https://reviews.llvm.org/rL298410
Differential Revision: https://reviews.llvm.org/D31245
llvm-svn: 298634
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp | 37 | ||||
-rw-r--r-- | clang/test/Sema/attr-deprecated.c | 23 | ||||
-rw-r--r-- | clang/test/SemaCXX/attr-deprecated.cpp | 12 | ||||
-rw-r--r-- | clang/test/SemaCXX/template-multiple-attr-propagation.cpp | 29 | ||||
-rw-r--r-- | clang/test/SemaObjC/attr-deprecated.m | 4 | ||||
-rw-r--r-- | clang/test/SemaObjC/special-dep-unavail-warning.m | 4 | ||||
-rw-r--r-- | clang/test/SemaObjC/warn-deprecated-implementations.m | 4 |
7 files changed, 88 insertions, 25 deletions
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp index a27cea84db4..58c7c0cfac8 100644 --- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp @@ -23,7 +23,38 @@ template <> class [[deprecated]] X<int> {}; // expected-note {{'X<int>' has been X<char> x1; X<int> x2; // expected-warning {{'X<int>' is deprecated}} -template <typename T> class [[deprecated]] X2 {}; +template <typename T> class [[deprecated]] X2 {}; //expected-note {{'X2<char>' has been explicitly marked deprecated here}} template <> class X2<int> {}; -X2<char> x3; // FIXME: no warning! -X2<int> x4; +X2<char> x3; // expected-warning {{'X2<char>' is deprecated}} +X2<int> x4; // No warning, the specialization removes it. + +template <typename T> class [[deprecated]] X3; //expected-note {{'X3<char>' has been explicitly marked deprecated here}} +template <> class X3<int>; +X3<char> *x5; // expected-warning {{'X3<char>' is deprecated}} +X3<int> *x6; // No warning, the specialization removes it. + +template <typename T> struct A; +A<int> *p; +template <typename T> struct [[deprecated]] A;//expected-note {{'A<int>' has been explicitly marked deprecated here}} expected-note {{'A<float>' has been explicitly marked deprecated here}} +A<int> *q; // expected-warning {{'A<int>' is deprecated}} +A<float> *r; // expected-warning {{'A<float>' is deprecated}} + +template <typename T> struct B; +B<int> *p2; +template <typename T> struct [[deprecated]] B;//expected-note {{'B<int>' has been explicitly marked deprecated here}} expected-note {{'B<float>' has been explicitly marked deprecated here}} +B<int> *q2; // expected-warning {{'B<int>' is deprecated}} +B<float> *r2; // expected-warning {{'B<float>' is deprecated}} + +template <typename T> +T some_func(T t) { + struct [[deprecated]] FunS{}; // expected-note {{'FunS' has been explicitly marked deprecated here}} + FunS f;// expected-warning {{'FunS' is deprecated}} + +} + +template <typename T> +[[deprecated]]T some_func2(T t) { + struct FunS2{}; + FunS2 f;// No warning, entire function is deprecated, so usage here should be fine. + +} diff --git a/clang/test/Sema/attr-deprecated.c b/clang/test/Sema/attr-deprecated.c index 8566a0e9436..89c06860fb4 100644 --- a/clang/test/Sema/attr-deprecated.c +++ b/clang/test/Sema/attr-deprecated.c @@ -1,10 +1,12 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only +// RUN: %clang_cc1 %s -std=c89 -verify -fsyntax-only +// RUN: %clang_cc1 %s -std=c99 -verify -fsyntax-only int f() __attribute__((deprecated)); // expected-note 2 {{'f' has been explicitly marked deprecated here}} -void g() __attribute__((deprecated)); -void g(); // expected-note {{'g' has been explicitly marked deprecated here}} +void g() __attribute__((deprecated));// expected-note {{'g' has been explicitly marked deprecated here}} +void g(); -extern int var __attribute__((deprecated)); // expected-note {{'var' has been explicitly marked deprecated here}} +extern int var __attribute__((deprecated)); // expected-note 2 {{'var' has been explicitly marked deprecated here}} int a() { int (*ptr)() = f; // expected-warning {{'f' is deprecated}} @@ -17,13 +19,13 @@ int a() { } // test if attributes propagate to variables -extern int var; // expected-note {{'var' has been explicitly marked deprecated here}} +extern int var; int w() { return var; // expected-warning {{'var' is deprecated}} } -int old_fn() __attribute__ ((deprecated)); -int old_fn(); // expected-note {{'old_fn' has been explicitly marked deprecated here}} +int old_fn() __attribute__ ((deprecated));// expected-note {{'old_fn' has been explicitly marked deprecated here}} +int old_fn(); int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}} int old_fn() { @@ -44,8 +46,8 @@ void test1(struct foo *F) { typedef struct foo foo_dep __attribute__((deprecated)); // expected-note 12 {{'foo_dep' has been explicitly marked deprecated here}} foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}} -struct __attribute__((deprecated, - invalid_attribute)) bar_dep ; // expected-warning {{unknown attribute 'invalid_attribute' ignored}} expected-note 2 {{'bar_dep' has been explicitly marked deprecated here}} +struct __attribute__((deprecated, // expected-note 2 {{'bar_dep' has been explicitly marked deprecated here}} + invalid_attribute)) bar_dep ; // expected-warning {{unknown attribute 'invalid_attribute' ignored}} struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}} @@ -121,11 +123,12 @@ struct test22 { __attribute((deprecated)) foo_dep e, f; }; -typedef int test23_ty __attribute((deprecated)); +typedef int test23_ty __attribute((deprecated)); // Redefining a typedef is a C11 feature. #if __STDC_VERSION__ <= 199901L // expected-note@-3 {{'test23_ty' has been explicitly marked deprecated here}} #else -typedef int test23_ty; // expected-note {{'test23_ty' has been explicitly marked deprecated here}} +// expected-note@-5 {{'test23_ty' has been explicitly marked deprecated here}} +typedef int test23_ty; #endif test23_ty test23_v; // expected-warning {{'test23_ty' is deprecated}} diff --git a/clang/test/SemaCXX/attr-deprecated.cpp b/clang/test/SemaCXX/attr-deprecated.cpp index eab5a1c0ec0..1680c5c6760 100644 --- a/clang/test/SemaCXX/attr-deprecated.cpp +++ b/clang/test/SemaCXX/attr-deprecated.cpp @@ -56,14 +56,14 @@ void f(B* b, C *c) { } struct D { - virtual void f() __attribute__((deprecated)); - virtual void f(int) __attribute__((deprecated)); - virtual void f(int, int) __attribute__((deprecated)); + virtual void f() __attribute__((deprecated));// expected-note{{'f' has been explicitly marked deprecated here}} + virtual void f(int) __attribute__((deprecated));// expected-note{{'f' has been explicitly marked deprecated here}} + virtual void f(int, int) __attribute__((deprecated));// expected-note{{'f' has been explicitly marked deprecated here}} }; -void D::f() { } // expected-note{{'f' has been explicitly marked deprecated here}} -void D::f(int v) { } // expected-note{{'f' has been explicitly marked deprecated here}} -void D::f(int v1, int v2) { } // expected-note{{'f' has been explicitly marked deprecated here}} +void D::f() { } +void D::f(int v) { } +void D::f(int v1, int v2) { } void f(D* d) { d->f(); // expected-warning{{'f' is deprecated}} diff --git a/clang/test/SemaCXX/template-multiple-attr-propagation.cpp b/clang/test/SemaCXX/template-multiple-attr-propagation.cpp new file mode 100644 index 00000000000..8e7f4570bad --- /dev/null +++ b/clang/test/SemaCXX/template-multiple-attr-propagation.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 %s -Wthread-safety-analysis -verify -fexceptions +// expected-no-diagnostics + +class Mutex { +public: + void Lock() __attribute__((exclusive_lock_function())); + void Unlock() __attribute__((unlock_function())); +}; + +class A { +public: + Mutex mu1, mu2; + + void foo() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) {} + + template <class T> + void bar() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) { + foo(); + } +}; + +void f() { + A a; + a.mu1.Lock(); + a.mu2.Lock(); + a.bar<int>(); + a.mu2.Unlock(); + a.mu1.Unlock(); +} diff --git a/clang/test/SemaObjC/attr-deprecated.m b/clang/test/SemaObjC/attr-deprecated.m index 8a949f96e8b..b0613851dda 100644 --- a/clang/test/SemaObjC/attr-deprecated.m +++ b/clang/test/SemaObjC/attr-deprecated.m @@ -83,8 +83,8 @@ int t5() { } -__attribute ((deprecated)) -@interface DEPRECATED { // expected-note 2 {{'DEPRECATED' has been explicitly marked deprecated here}} +__attribute ((deprecated)) // expected-note 2 {{'DEPRECATED' has been explicitly marked deprecated here}} +@interface DEPRECATED { @public int ivar; DEPRECATED *ivar2; // no warning. } diff --git a/clang/test/SemaObjC/special-dep-unavail-warning.m b/clang/test/SemaObjC/special-dep-unavail-warning.m index 9e16b331c23..b667c3c51c9 100644 --- a/clang/test/SemaObjC/special-dep-unavail-warning.m +++ b/clang/test/SemaObjC/special-dep-unavail-warning.m @@ -44,8 +44,8 @@ void test(C *c) { } // rdar://10268422 -__attribute ((deprecated)) -@interface DEPRECATED // expected-note {{'DEPRECATED' has been explicitly marked deprecated here}} +__attribute ((deprecated)) // expected-note {{'DEPRECATED' has been explicitly marked deprecated here}} +@interface DEPRECATED +(id)new; @end diff --git a/clang/test/SemaObjC/warn-deprecated-implementations.m b/clang/test/SemaObjC/warn-deprecated-implementations.m index f5a010da3fa..0c341165b0f 100644 --- a/clang/test/SemaObjC/warn-deprecated-implementations.m +++ b/clang/test/SemaObjC/warn-deprecated-implementations.m @@ -28,8 +28,8 @@ - (void) G {} // No warning, implementing its own deprecated method @end -__attribute__((deprecated)) -@interface CL // expected-note 2 {{class declared here}} // expected-note 2 {{'CL' has been explicitly marked deprecated here}} +__attribute__((deprecated)) // expected-note 2 {{'CL' has been explicitly marked deprecated here}} +@interface CL // expected-note 2 {{class declared here}} @end @implementation CL // expected-warning {{Implementing deprecated class}} |