Skip to content

SHOW_HEADERFILE doesn't work well for headers with no file extension #10010

Closed
@jwakely

Description

@jwakely

Describe the bug

With this config:

SHOW_HEADERFILE=YES
EXTENSION_MAPPING      = no_extension=C++ \
                         .h=C++

the description for every C++ class defined in a header file foo.h will show:

#include <foo.h>

This happens whether the classes have \headerfile in their comments or not. And if you use @headerfile foo it will show #include <foo> instead. Great.

But C++ classes defined in a file with no extension, e.g. bar, will not show their header file by default. You have to use \headerfile to get them to display the #include <bar> info. This is inconsistent.

The point of \headerfile is to be able to "correct" the header shown for SHOW_HEADERFILE, when the file that the class is actually defined is some implementation details like detail/foo.h and the public API says to include <bar> instead. So you use \headerfile bar to make the class display the right header.

But when the class is already defined in the same header that users should actually include, you usually don't need to specify \headerfile, you just let Doxygen infer it correctly and display #include <foo.h>. This doesn't work if the file has no extension, so you need to add an explicit \headerfile bar to every class in file bar. Why? Is it because a file with no extension is being treated as a source file, not a header file?

Expected behavior

A class defined in a file with no extension should infer its \headerfile to be the filename, and show that in the SHOW_HEADERFILE info.

If the problem is that an extension-less file like bar is assumed to be more like bar.cc than bar.h, could we maybe get a way to say that a given file is header-like not source-like? Maybe an extension (no pun intended) to EXTENSION_MAPPING so that we can say no_extension=C++hdr instead of no_extension=C++?

Or maybe something on the \file for bar that could say "treat this file like a header, and so every class defined in the file has an implied \headerfile bar. Maybe implementing #9334 would allow that, by giving a header-file or \headerfile in the \file comment block.

Screenshots

issue10007

This shows the docs for three structs side by side. S and S2 are both in a file called bar with this content:

/// @file bar
/// This is a header file called `<bar>` (with no extension).

/// A struct in file `<bar>`
struct S { };

/// @brief Another struct in file `<bar>`
/// @headerfile bar
struct S2 { };

And struct X is defined in file foo.h with this content:

/// @file foo.h
/// This is a header file called `<foo.h>`

/// A struct in file `<foo.h>`
struct X { };

(These files are in the zip file attached below).

Observe that X shows its headerfile as #include <foo.h> even though there is no explicit \headerfile command, but S does not show any header file info. S2 does show its header file info as #include <bar> but only because there's an explicit \headerfile for that class.

What I want is for S to show the info, without needing the explicit \headerfile bar naming the current file, because that seems redundant. Doxygen correctly infers the header file for the class in foo.h but not for the classes in bar.

To Reproduce

issue-10010.zip

Version

Same results with 1.9.5 and 1.9.6 (875558c) and 1.9.7 (48bb276)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions