Qualified specialization of a variable template is dropped: "documented symbol ... was not declared or defined"
Describe the bug
A specialization of a variable template written with a qualified name at global scope — the
std::ranges::enable_view / enable_borrowed_range idiom — never becomes a member of its namespace.
Depending on whether the variable template itself is part of the input, one of two things happens:
The variable template is outside the input (the normal case for a standard-library trait): the specialization is discarded together with its documentation, and doxygen warns
minimal.h:9: warning: documented symbol 'constexpr bool std::ranges::enable_view< MyView< T > >' was not declared or defined.After the run, xml/ holds only structMyView.xml; there is no memberdef for the specialization
anywhere and the documentation is lost. It survives only as text in the source listing of
minimal_8h.xml.
The variable template is part of the input: no warning, but still no memberdef of its own. The
documentation is merged into the primary template's memberdef, whose <definition> is
overwritten with the specialization's signature while it keeps the primary's initializer, so one
entry ends up describing both (known_primary.h in the attachment):
<definition>bool ns::trait< MyType< T > ></definition>
<initializer>= false</initializer>
<para>A variable template that <emphasis>is</emphasis> part of the input. </para>
<para>Qualified specialization of a variable template doxygen knows about. </para>Writing the very same specialization inside a namespace std::ranges { } block works perfectly: it
becomes a proper memberdef of namespacestd_1_1ranges.xml, with its templateparamlist,
initializer and description, and there is no warning. So the two spellings of one declaration give
very different results.
Declaring the namespace is not a workaround either — adding namespace std::ranges {} to the input
changes nothing (namespace_declared.h in the attachment). Both full (template<>) and partial
(template<class T>) specializations are affected.
To Reproduce
Attached: doxygen-variable-template-specialization.tar.gz — four headers plus a doxygen -s -u
config whose only non-default settings are
QUIET = YES, GENERATE_HTML = NO, GENERATE_LATEX = NO, GENERATE_XML = YES,
EXTRACT_ALL = YES, RECURSIVE = NO, INPUT = minimal.hminimal.h:
/// A view type of our own.
template<class T>
struct MyView {};
/// Opt MyView into the ranges machinery.
/// `std::ranges::enable_view` is not part of the input, so this specialization
/// can only be spelled with a qualified name.
template<class T>
constexpr bool std::ranges::enable_view<MyView<T>> = true;$ doxygen Doxyfile
minimal.h:9: warning: documented symbol 'constexpr bool std::ranges::enable_view< MyView< T > >' was not declared or defined.
$ ls xml
Doxyfile.xml index.xml minimal_8h.xml structMyView.xmlThe other three headers isolate the comparison; point INPUT at them one at a time or all at once,
they do not interfere. Documented members produced per file:
| input | memberdef produced |
|---|---|
minimal.h (qualified, template outside the input) |
none, plus the warning |
namespace_declared.h (same, with namespace std::ranges {} added) |
none, plus the warning |
reopened_namespace.h (written inside namespace std::ranges { }) |
std::ranges::enable_view< MyView< T > > |
known_primary.h (qualified, template inside the input) |
only ns::trait, with the two merged as shown above |
Expected behavior
The qualified spelling should document the specialization in its namespace, exactly like the reopened-namespace spelling does, and the primary template should keep its own entry.
The cause is in addVariable() (src/doxygen.cpp): a variable whose name is qualified is skipped
outright, on the assumption that it is the out-of-class definition of a static data member and will be
picked up from the class that declares it. That assumption does not hold for a specialization of a
variable template living in a namespace, which has no choice but to spell out its scope.
I have a patch and a test case and will open a PR right after this issue.
Version
doxygen --version:1.19.0 (cf3e37e3832bf6381d871cf7248c23307e9c81b4), built from current master- also reproduced with the distribution package
1.18.0(CachyOSdoxygen 1.18.0-1.1) - Platform: CachyOS (Arch-based, rolling), Linux 7.2.2 x86_64
Additional context
This came up in a library whose Span derives from std::span. The derived type is a distinct type,
so the std::ranges opt-ins do not carry over and have to be restated:
template<class T, size_t N> constexpr bool std::ranges::enable_view<fe::Span<T, N>> = true;
template<class T, size_t N> constexpr bool std::ranges::enable_borrowed_range<fe::Span<T, N>> = true;With WARN_AS_ERROR = YES these two lines fail the documentation build, and since the documentation
is dropped anyway there is nothing to be gained by keeping them visible to doxygen — they are
currently wrapped in #ifndef DOXYGEN.
Related but distinct, and already fixed: #12356 (spurious "Incomplete input: scope for class
std::hash< Foo > not found!"). That one is about class templates, goes through
resolveClassNestingRelations(), and there the output was already correct and only the diagnostic was
wrong. Here the documentation itself is missing.
Source: doxygen/doxygen