Mark templates users shouldn't specialize with no_specializations attributes by localspook · Pull Request #5536 · microsoft/STL (original) (raw)

This PR marks templates users shouldn't specialize with [[msvc::no_specializations]] or [[clang::no_specializations]], depending on the compiler.

Resolves #5179.

All citations in this PR description are to WG21-N5014.

Class Templates

[namespace.std]/2 allows class template specializations by default. Exceptions:

Specializations forbidden By paragraph
initializer_list [initializer.list.syn]/2
compare_three_way_result [cmp.result]/1
allocator_traits [allocator.traits.general]/1
coroutine_handle [coroutine.handle.general]/2
is_execution_policy [execpol.type]/3
basic_format_arg [format.arg]/2
basic_format_context [format.context]/2
basic_format_parse_context [format.parse.ctx]/2
is_clock [time.traits.is.clock]/2
generator [coro.generator.class]/4
range_adaptor_closure [range.adaptor.object]/5
variant [variant.variant.general]/4
tuple [tuple.tuple.general]/1
unary_function WG21-N4140 [depr.base]/1
binary_function WG21-N4140 [depr.base]/1

Variable Templates

[namespace.std]/3 forbids variable template specializations by default.

Specializations allowed By paragraph
format_kind [format.range.fmtkind]/3
disable_sized_sentinel_for [iterator.concept.sizedsentinel]/3
enable_borrowed_range [range.range]/6
disable_sized_range [range.sized]/3
enable_view [range.view]/7
enable_nonlocking_formatter_optimization [format.formatter.locking]/1
e_v [math.constants]/2
log2e_v [math.constants]/2
log10e_v [math.constants]/2
pi_v [math.constants]/2
inv_pi_v [math.constants]/2
inv_sqrtpi_v [math.constants]/2
ln2_v [math.constants]/2
ln10_v [math.constants]/2
sqrt2_v [math.constants]/2
sqrt3_v [math.constants]/2
inv_sqrt3_v [math.constants]/2
egamma_v [math.constants]/2
phi_v [math.constants]/2

Type Traits

[meta.rqmts]/4 forbids specializing any template in <type_traits> by default.

Specializations allowed By paragraph
common_type [meta.trans.other]/5
basic_common_reference [meta.trans.other]/7

Function Templates

Specializing function templates is forbidden, but, following the decision made in #24, this PR doesn't touch any of them (except for is_pointer_interconvertible_with_class and is_corresponding_member in <type_traits>, as specializing those has always been forbidden).

Notes

Relevant: llvm/llvm-project#118167 implemented this warning in libc++.