forked from sphinx-doc/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
C++ User Defined Literals not supported
The code as below
namespace units::si {
inline constexpr auto planck_constant = 6.62607015e-34q_J * 1q_s;
}causes the following error:
WARNING: Invalid definition: Expected end of definition. [error at 58]
constexpr auto units::si::planck_constant = 6.62607015e-34q_J * 1q_s
----------------------------------------------------------^
According to https://github.com/sphinx-doc/sphinx/blob/3.x/sphinx/domains/cpp.py#L4770 Sphinx seems to not have features for UDLs. Could you please add those?
Observed failure and reproduction steps
-
Minimal repro in a .rst file:
.. cpp:namespace:: units::si .. cpp:var:: inline constexpr auto planck_constant = 6.62607015e-34q_J * 1q_s
-
Build with warnings as errors:
sphinx-build -b html . _build -W -
Expected current behavior: warning shown above. This is due to the C++ domain parser accepting the floating literal
6.62607015e-34but not the adjacent UDL suffixq_J, leaving trailing text and triggering "Expected end of definition".
Proposed resolution (summary)
- Extend the C++ domain literal parsing to accept an optional user-defined literal suffix (identifier:
[A-Za-z_][A-Za-z0-9_]*) immediately following numeric literals, alongside existing builtin suffixes (u/U/l/L/f/F). Builtin suffixes and UDLs should not be combined on the same literal. - Add tests covering positive and negative cases for numeric UDLs.
This issue tracks adding numeric UDL support so that the example above parses without warnings.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels