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] 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();