Spurious "Incomplete input: scope for class `std::hash< Foo >` not found!" for a template specialization
doxygen-scope-for-class-not-found.tar.gz
Describe the bug
Specializing a class template that is not itself part of the input — the std::hash / std::formatter /
std::tuple_size idiom — warns when it is written with a qualified name at global scope:
minimal.h:7: warning: Incomplete input: scope for class std::hash< Foo > not found! Try enabling BUILTIN_STL_SUPPORT.The warning is spurious in two ways:
Doxygen documents the specialization completely and correctly in spite of it. It builds the
stdscope artificially (buildScopeFromQualifiedName) and attaches the class to it, and the output is what one would want.The exact same declaration written by reopening the namespace
namespace std { template<> struct hash<Bar> { ... }; }produces no warning and byte-identical XML, apart from the
<location>of thestdnamespace itself ([generated]vs. the line of the reopening block). So the two spellings of one declaration are treated differently, although nothing about the input is more or less complete in either case.
The input is not, in any actionable sense, incomplete: a specialization can only be written for a template that has been declared before, so the primary template — and with it the namespace — lives outside the input by construction. There is nothing the user can add to make the warning go away.
With WARN_AS_ERROR = YES this fails the documentation build outright, and the available workarounds
are both unattractive:
BUILTIN_STL_SUPPORT = YESsilences it, but pulls the STL into the class hierarchy and the inheritance/collaboration diagrams, which is a large and unrelated change to the generated docs (in our casefe::Spanderives fromstd::span, so the effect is very visible).- Hiding the declarations from doxygen with
#ifndef DOXYGEN, which is what we ended up doing in half a dozen headers.
To Reproduce
Attached: doxygen-scope-for-class-not-found.tar.gz (sources + doxygen -s -u config).
minimal.h:
/// A class of our own.
struct Foo {};
/// Specialize a standard-library template for it.
/// This is the *only* way to spell it without reopening `namespace std`.
template<>
struct std::hash<Foo> {
size_t operator()(const Foo&) const noexcept { return 0; }
};Doxyfile is the default configuration with only
QUIET = YES
GENERATE_HTML = NO
GENERATE_LATEX = NO
GENERATE_XML = YES
EXTRACT_ALL = YES
RECURSIVE = NO
INPUT = minimal.hchanged. Then:
$ doxygen Doxyfile
minimal.h:7: warning: Incomplete input: scope for class std::hash< Foo > not found! Try enabling BUILTIN_STL_SUPPORT.The tarball also contains two files to be run on their own (change INPUT in the Doxyfile):
counterexample.h— the same entity declared insidenamespace std { ... }: no warning, identical output. Note that putting it into the same run asminimal.hmakes the warning disappear, because itsnamespace std {block creates the scope — so the two files must not be given to doxygen together.still_warns.h—class N::C {};andclass Outer::Inner {};withN/Outernowhere in the input. This is what the warning is genuinely for, and it should keep firing here.
Expected behavior
No warning for minimal.h. The documentation doxygen generates for it is already correct; only the
diagnostic is wrong.
A one-line fix that keeps the warning for the cases it was written for: in
resolveClassNestingRelations() (src/doxygen.cpp), skip the warning when the compound whose scope
could not be found is a template specialization, since that implies the primary template — and hence
the scope — is external by definition:
cd->setOuterScope(d);
- warn(cd->getDefFileName(),cd->getDefLine(),
- "Incomplete input: scope for class {} not found!{}",name,
- name.startsWith("std::") ? " Try enabling BUILTIN_STL_SUPPORT." : ""
- );
+ // A specialization can only be written for a template that has been declared before, so a missing
+ // scope means that declaration is outside the input - e.g. `template<> struct std::hash<MyClass>`.
+ if (cd->localName().find('<')==DString::npos)
+ {
+ warn(cd->getDefFileName(),cd->getDefLine(),
+ "Incomplete input: scope for class {} not found!{}",name,
+ name.startsWith("std::") ? " Try enabling BUILTIN_STL_SUPPORT." : ""
+ );
+ }(localName() goes through the bracket-aware stripScope, so std::hash< Foo > yields hash< Foo >
and the :: inside template arguments does not confuse it.)
With that patch: minimal.h is warning-free and its XML is unchanged, still_warns.h still reports
both classes, and the whole testing/ suite passes (124/124, run sequentially). I am happy to open a
PR with the patch plus a regression test along the lines of testing/124_specialize_external_template.cpp
if you consider this the right direction.
Version
doxygen --version:1.18.0(CachyOS packagedoxygen 1.18.0-1.1)- also reproduced with
1.19.0 (91cebc6439b55995b0692ac055c55578988d8b54), built from current master - Platform: CachyOS (Arch-based, rolling), Linux 7.2.2 x86_64
Additional context
Related: #11538, which led to 4bb67ed14 rewording this message from "Internal inconsistency" to
"Incomplete input" and adding the BUILTIN_STL_SUPPORT hint. I think the underlying report there is
this same case, and the hint is not really a fix for it — BUILTIN_STL_SUPPORT changes the generated
documentation substantially for anything that touches the STL.
Source: doxygen/doxygen