#12360·doxygen

Regression in 1.18: \ref cannot resolve file-scope static variables (m_fileScope is null on the \ref path)

Author: nocnokneoCreated Sep 21, 2026Updated Sep 21, 2026

Describe the bug

Since 1.18.0, \ref / @ref can no longer resolve a reference to a file-scope static variable, even when the reference appears in the very same file as the definition. Doxygen 1.17.0 resolves it fine.

This appears to be a side effect of e1bff0176b285f38434af6b9c303c53651bd8b4f ("Prevent wrong cross references between static functions defined in multiple files"), which is intentional in spirit but over-applies when the lookup has no file scope.

Expected behavior

@ref MY_STATIC_CONST resolves to the documented file-scope static, as it did in 1.17.0.

Minimal reproducer

a.h:

cpp
/// @brief A documented static constant.
static const int STATIC_CONST = 1;

/// @brief A documented non-static constant.
const int NONSTATIC_CONST = 1;

/// @brief A documented function.
void myFunction();

/// @brief ref to static: @ref STATIC_CONST here.
void caseA();

/// @brief ref to nonstatic: @ref NONSTATIC_CONST here.
void caseC();

/// @brief ref to function: @ref myFunction here.
void caseD();

Doxyfile:

PROJECT_NAME    = ref2
INPUT           = a.h
GENERATE_HTML   = NO
GENERATE_LATEX  = NO
EXTRACT_ALL     = YES
EXTRACT_STATIC  = YES
QUIET           = YES

Results:

  • 1.17.0 — no warnings; all three references resolve.
  • 1.18.0 — a.h:10: warning: unable to resolve reference to 'STATIC_CONST' for \ref command

Only the static case regresses; the non-static variable and the function still resolve. Adding an explicit file scope (@ref a.h::STATIC_CONST) does not help.

Analysis

e1bff01 added a filter in SymbolResolver::Private::getResolvedSymbolRec():

cpp
if (emd &&
    emd->isStatic() &&
    emd->getFileDef()!=m_fileScope)
{
  // skip lookup for static members that are not in the current file scope
  return true;
}

The \ref path never sets a file scope, so m_fileScope is nullptr and the condition is true for every static, not just those from other files:

  • resolveLink() (src/util.cpp) calls resolveRef(scName,lr,TRUE,resContext,&md,lang), leaving the currentFile parameter at its default nullptr.
  • getDefs() only propagates it when set: if (input.currentFile) resolver.setFileScope(input.currentFile);

So with no file-scope context the new check degrades from "skip statics from other files" to "skip all statics".

Suggested fix

Only apply the filter when a file scope is actually known, preserving 1.17 behaviour when it is not:

cpp
if (emd &&
    emd->isStatic() &&
    m_fileScope &&                       // only filter when the file scope is known
    emd->getFileDef()!=m_fileScope)

I am happy to open a PR with this change plus a regression test.

Version

1.18.0 (conda-forge doxygen-1.18.0), Linux x86_64. Confirmed working on 1.17.0 with an otherwise identical configuration.