[clang] [clang] Diagnose use of deprecated template alias (PR #97619)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 04:20:33 PDT 2024
================
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+//
+// This test checks that a deprecated attribute on an alias
+// template triggers a warning diagnostic when it is used.
+
+template <typename T>
+struct NoAttr {
+ void foo() {}
+};
+
+// expected-note at +2 5{{'UsingWithAttr' has been explicitly marked deprecated here}}
+template <typename T>
+using UsingWithAttr __attribute__((deprecated)) = NoAttr<T>;
+
+// expected-note at +1 {{'UsingInstWithAttr' has been explicitly marked deprecated here}}
+using UsingInstWithAttr __attribute__((deprecated)) = NoAttr<int>;
+
+// expected-note at +1 {{'TDWithAttr' has been explicitly marked deprecated here}}
+typedef NoAttr<int> TDWithAttr __attribute__((deprecated));
+
+// expected-warning at +1 {{'UsingWithAttr' is deprecated}}
+typedef UsingWithAttr<int> TDUsingWithAttr;
+
+typedef NoAttr<int> TDNoAttr;
+
+// expected-note at +1 {{'UsingTDWithAttr' has been explicitly marked deprecated here}}
+using UsingTDWithAttr __attribute__((deprecated)) = TDNoAttr;
+
+struct S {
+ NoAttr<float> f1;
+ // expected-warning at +1 {{'UsingWithAttr' is deprecated}}
+ UsingWithAttr<float> f2;
+};
+
+// expected-warning at +1 {{'UsingWithAttr' is deprecated}}
+void foo(NoAttr<short> s1, UsingWithAttr<short> s2) {
+}
+
+// expected-note at +2 {{'UsingWithCPPAttr' has been explicitly marked deprecated here}}
+template <typename T>
+using UsingWithCPPAttr [[deprecated]] = NoAttr<T>;
+
+// expected-note at +1 {{'UsingInstWithCPPAttr' has been explicitly marked deprecated here}}
+using UsingInstWithCPPAttr [[deprecated("Do not use this")]] = NoAttr<int>;
+
+void bar() {
+ NoAttr<int> obj; // Okay
+
+ // expected-warning at +2 {{'UsingWithAttr' is deprecated}}
+ // expected-note at +1 {{in instantiation of template type alias 'UsingWithAttr' requested here}}
+ UsingWithAttr<int> objUsingWA;
+
+ // expected-warning at +2 {{'UsingWithAttr' is deprecated}}
+ // expected-note at +1 {{in instantiation of template type alias 'UsingWithAttr' requested here}}
+ UsingWithAttr<int>().foo();
+
+ // expected-warning at +1 {{'UsingInstWithAttr' is deprecated}}
+ UsingInstWithAttr objUIWA;
+
+ // expected-warning at +1 {{'TDWithAttr' is deprecated}}
+ TDWithAttr objTDWA;
+
+ // expected-warning at +1 {{'UsingTDWithAttr' is deprecated}}
+ UsingTDWithAttr objUTDWA;
+
+ // expected-warning at +2 {{'UsingWithCPPAttr' is deprecated}}
+ // expected-note at +1 {{in instantiation of template type alias 'UsingWithCPPAttr' requested here}}
+ UsingWithCPPAttr<int> objUsingWCPPA;
+
+ // expected-warning at +1 {{'UsingInstWithCPPAttr' is deprecated: Do not use this}}
+ UsingInstWithCPPAttr objUICPPWA;
----------------
AaronBallman wrote:
Some more test cases I'd like to see:
```
NoAttr<UsingWithAttr<int>> s; // diag
using Foo [[deprecated]] = int;
using X = UsingWithAttr<Foo>; // two diagnostics, one for Foo and one for UsingWithAttr
```
https://github.com/llvm/llvm-project/pull/97619
More information about the cfe-commits
mailing list