Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cpp) exclude keywords from function calls #4217

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

Eisenwave
Copy link
Contributor

@Eisenwave Eisenwave commented Feb 28, 2025

Related to #4214.

The highlighter for C++ behaves treats keywords followed by parentheses as function calls (with some exceptions), and this is harmful:

// highlighted as a function call, but is grammatically a declaration
static_assert("");

// providing a reason for deletion should not be a function call!
void awoo() = delete("reason");

// highlighted as a function call, but that is slightly forgivable
// because it's called "function-style cast"
int(0);
// ... but then why is a function-style cast with braces not a function call?!
int { 0 };
// ... and why is this other cast not a function call?!
(int) x;

In general, it is wrong to highlight keywords followed by parentheses as function calls. This is always wrong, not just in specific cases like for() or if().

Changes

Exclude all keywords followed by parentheses from being classified as function.dispatch = built_in.

Checklist

  • Added markup tests
  • Updated the changelog at CHANGES.md

Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

7 files changed

Total change +16 B

View Changes
file base pr diff
es/core.min.js 8.19 KB 8.19 KB +2 B
es/highlight.min.js 8.19 KB 8.19 KB +2 B
es/languages/arduino.min.js 4.62 KB 4.63 KB +7 B
es/languages/cpp.min.js 2.6 KB 2.6 KB -1 B
highlight.min.js 8.23 KB 8.23 KB +2 B
languages/arduino.min.js 4.63 KB 4.63 KB +7 B
languages/cpp.min.js 2.61 KB 2.61 KB -3 B

@Eisenwave Eisenwave force-pushed the keywords-not-functions branch from eb0ed2e to 9fde86d Compare March 5, 2025 08:18
Copy link

github-actions bot commented Mar 5, 2025

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change -14 B

View Changes
file base pr diff
es/core.min.js 8.19 KB 8.19 KB +1 B
es/highlight.min.js 8.19 KB 8.19 KB +1 B
es/languages/cpp.min.js 2.6 KB 2.6 KB -8 B
highlight.min.js 8.23 KB 8.23 KB +1 B
languages/cpp.min.js 2.61 KB 2.6 KB -9 B

@Eisenwave Eisenwave requested a review from joshgoebel March 5, 2025 08:20
@joshgoebel joshgoebel force-pushed the keywords-not-functions branch from 9fde86d to 99ea9b8 Compare March 6, 2025 03:00
Copy link

github-actions bot commented Mar 6, 2025

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

2 files changed

Total change -17 B

View Changes
file base pr diff
es/languages/cpp.min.js 2.6 KB 2.6 KB -8 B
languages/cpp.min.js 2.61 KB 2.6 KB -9 B

@joshgoebel joshgoebel merged commit 224d7fe into highlightjs:main Mar 7, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants