From 514eaf9637552f94666992849d3647e25743c113 Mon Sep 17 00:00:00 2001
From: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com>
Date: Thu, 21 May 2026 18:29:43 +0530
Subject: [PATCH 1/2] Fix C++ function highlighting for keyword prefixes
---
src/languages/cpp.js | 6 +++++-
test/markup/cpp/function-like-keywords.expect.txt | 12 ++++++++++++
test/markup/cpp/function-like-keywords.txt | 12 ++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/languages/cpp.js b/src/languages/cpp.js
index 1b3e337784..49f7a42de0 100644
--- a/src/languages/cpp.js
+++ b/src/languages/cpp.js
@@ -417,6 +417,10 @@ export default function(hljs) {
_type_hints: TYPE_HINTS
};
+ const RESERVED_KEYWORD_RE = regex.either(
+ ...RESERVED_KEYWORDS.map(keyword => keyword.replace(/\|\d+$/, ''))
+ );
+
const FUNCTION_DISPATCH = {
className: 'function.dispatch',
relevance: 0,
@@ -425,7 +429,7 @@ export default function(hljs) {
_hint: FUNCTION_HINTS },
begin: regex.concat(
/\b/,
- `(?!${RESERVED_KEYWORDS.join('|')})`,
+ `(?!${RESERVED_KEYWORD_RE}\\b)`,
hljs.IDENT_RE,
regex.lookahead(/(<[^<>]+>|)\s*\(/))
};
diff --git a/test/markup/cpp/function-like-keywords.expect.txt b/test/markup/cpp/function-like-keywords.expect.txt
index 2f6e266e58..c3db088541 100644
--- a/test/markup/cpp/function-like-keywords.expect.txt
+++ b/test/markup/cpp/function-like-keywords.expect.txt
@@ -10,3 +10,15 @@
void f() = delete("reason");
static_assert(true);
+
+format();
+
+for_this();
+
+whilexyz();
+
+if (ifsyz()) {}
+
+returnxyz();
+
+thisxyz();
diff --git a/test/markup/cpp/function-like-keywords.txt b/test/markup/cpp/function-like-keywords.txt
index 608611fa8d..7ec3ee2e39 100644
--- a/test/markup/cpp/function-like-keywords.txt
+++ b/test/markup/cpp/function-like-keywords.txt
@@ -10,3 +10,15 @@ for (;;) {}
void f() = delete("reason");
static_assert(true);
+
+format();
+
+for_this();
+
+whilexyz();
+
+if (ifsyz()) {}
+
+returnxyz();
+
+thisxyz();
From d0635297bc5d8bd9632c4936b3751a4959b58096 Mon Sep 17 00:00:00 2001
From: Deepak kudi
Date: Sun, 24 May 2026 21:56:51 +0530
Subject: [PATCH 2/2] docs: add C++ keyword prefix changelog
---
CHANGES.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/CHANGES.md b/CHANGES.md
index b1413c29a5..c2788a984b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -26,6 +26,7 @@ Core Grammars:
- enh(json) add json5 support [Kerry Shetline][]
- fix(css) `unicode-range` parsing, issue #4253 [Kerry Shetline][]
- fix(csharp) Support digit separators [te-ing][]
+- fix(cpp) allow function names that start with reserved keyword prefixes [Puneet Dixit][]
Documentation:
@@ -55,6 +56,7 @@ CONTRIBUTORS
[te-ing]: https://github.com/te-ing
[Anthony Martin]: https://github.com/anthony-c-martin
[NriotHrreion]: https://github.com/NriotHrreion
+[Puneet Dixit]: https://github.com/puneetdixit200
## Version 11.11.1