From be256e47ff52a24fe4a2c63a210d1aa1bbdd7ca4 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Wed, 7 Jan 2026 15:36:21 -0800 Subject: [PATCH] [clang-doc] Don't serialize non-existant locations in HTML The function template didn't check to see if a `Location` existed before emitting the definition location line. --- clang-tools-extra/clang-doc/assets/function-template.mustache | 4 +++- clang-tools-extra/test/clang-doc/json/class.cpp | 1 - clang-tools-extra/test/clang-doc/templates.cpp | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache b/clang-tools-extra/clang-doc/assets/function-template.mustache index 1e81f34196137..354e26b7b05b0 100644 --- a/clang-tools-extra/clang-doc/assets/function-template.mustache +++ b/clang-tools-extra/clang-doc/assets/function-template.mustache @@ -17,5 +17,7 @@ {{>Comments}} {{/Description}} -

Defined at line {{Location.LineNumber}} of file {{Location.Filename}}

+ {{#Location}} +

Defined at line {{LineNumber}} of file {{Filename}}

+ {{/Location}} diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index 5c63aa5ec45ef..c4f0b2166a3f8 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -335,7 +335,6 @@ struct MyClass { // HTML-NEXT:
// HTML-NEXT:
// HTML-NEXT:
int protectedMethod ()
-// HTML-NEXT:

Defined at line of file

// HTML-NEXT:
// HTML-NEXT:
// HTML-NEXT: diff --git a/clang-tools-extra/test/clang-doc/templates.cpp b/clang-tools-extra/test/clang-doc/templates.cpp index c9f1370a19e6e..27fff6ed5a09d 100644 --- a/clang-tools-extra/test/clang-doc/templates.cpp +++ b/clang-tools-extra/test/clang-doc/templates.cpp @@ -79,8 +79,6 @@ void ParamPackFunction(T... args); // HTML:
template <class... T>
// HTML-NEXT:
void ParamPackFunction (T... args)
-// COM: FIXME: Omit defined line if not defined, or emit declaration line. -// HTML-NEXT:

Defined at line of file

// HTML-NEXT: template