[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 09:05:26 PDT 2024


================
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 %s -verify
+
+#if !__has_cpp_attribute(clang::diagnose_specializations)
+#  error
+#endif
+
+struct [[clang::diagnose_specializations]] S {}; // expected-warning {{'diagnose_specializations' attribute only applies to class templates}}
+
+template <class T, class U>
+struct [[clang::diagnose_specializations]] is_same {
----------------
ldionne wrote:

Would it make sense to allow passing a string (maybe optionally) to explain why the template shouldn't be specialized? Then from libc++ we would do:

```
#define _LIBCPP_NO_SPECIALIZATION [[_Clang::__diagnose_specializations__("Per <section> of the C++ Standard, users are not allowed to specialize class templates in namespace std")]]
```

https://github.com/llvm/llvm-project/pull/101469


More information about the cfe-commits mailing list