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