Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/languages/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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*\(/))
};
Expand Down
12 changes: 12 additions & 0 deletions test/markup/cpp/function-like-keywords.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@
<span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">f</span><span class="hljs-params">()</span> </span>= <span class="hljs-keyword">delete</span>(<span class="hljs-string">&quot;reason&quot;</span>);

<span class="hljs-keyword">static_assert</span>(<span class="hljs-literal">true</span>);

<span class="hljs-built_in">format</span>();

<span class="hljs-built_in">for_this</span>();

<span class="hljs-built_in">whilexyz</span>();

<span class="hljs-keyword">if</span> (<span class="hljs-built_in">ifsyz</span>()) {}

<span class="hljs-built_in">returnxyz</span>();

<span class="hljs-built_in">thisxyz</span>();
12 changes: 12 additions & 0 deletions test/markup/cpp/function-like-keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ for (;;) {}
void f() = delete("reason");

static_assert(true);

format();

for_this();

whilexyz();

if (ifsyz()) {}

returnxyz();

thisxyz();