You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This can be used to inform users when a template should not be
specialized. For example, this is the case for the standard type traits
(except for `common_type` and `common_reference`, which have more
complicated rules).
struct [[clang::no_specializations]] S {}; // expected-warning {{'no_specializations' attribute only applies to class templates, function templates, and variable templates}}
using alias [[clang::no_specializations]] = T; // expected-warning {{'no_specializations' attribute only applies to class templates, function templates, and variable templates}}
16
+
17
+
template <>
18
+
structis_same<int, char> {}; // expected-error {{'is_same' cannot be specialized}}
19
+
20
+
template <class>
21
+
structTemplate {};
22
+
23
+
template <classT>
24
+
structis_same<Template<T>, Template <T>> {}; // expected-error {{'is_same' cannot be specialized}}
struct [[clang::no_specializations("specializing type traits results in undefined behaviour")]] is_trivial { // expected-note {{marked 'no_specializations' here}}
41
+
staticconstexprbool value = __is_trivial(T);
42
+
};
43
+
44
+
template <>
45
+
structis_trivial<int> {}; // expected-error {{'is_trivial' cannot be specialized: specializing type traits results in undefined behaviour}}
46
+
47
+
template <classT>
48
+
[[clang::no_specializations("specializing type traits results in undefined behaviour")]] inlineconstexprbool is_trivial_v = __is_trivial(T); // expected-note {{marked 'no_specializations' here}}
49
+
50
+
template <>
51
+
inlineconstexprbool is_trivial_v<int> = false; // expected-error {{'is_trivial_v' cannot be specialized: specializing type traits results in undefined behaviour}}
52
+
53
+
template <classT>
54
+
structPartial {};
55
+
56
+
template <classT>
57
+
struct [[clang::no_specializations]] Partial<Template <T>> {}; // expected-warning {{'no_specializations' attribute only applies to class templates, function templates, and variable templates}}
0 commit comments