C++ Logo

std-proposals

Advanced search

[std-proposals] Defect report: not possible to declare-but-not-define a full specialization of a variable template

From: Avi Kivity <avi_at_[hidden]>
Date: Mon, 13 Jan 2025 20:07:03 +0200
It's possible to declare-but-not-define a full specialization of a
function or variable template:

template <typename T> void function_template();
extern template void function_template<int>(); // Some other TU must
define, but any TU can reference

template <typename T> class class_template;
template <> class class_template<int>; // Incomplete type, but can
still be used

However, it's not possible [1] to declare-but-not-define a variable
template full specialization.

template <typename T> extern int variable_template;
template <> extern int variable_template<int>; // rejected

Such a declaration-but-not-definition would allow the initializer for
the variable template to be hidden from its users, for the purpose of
reducing compile-time dependencies.

I wasn't able to fully determine if the defect is in the Standard, in
existing implementations, or in the user interpreting the Standard and
existing implementations.

Received on 2025-01-13 18:07:06