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

enh(cpp) add C++26 keywords, #embed, and compiler-builtin types #4218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Eisenwave
Copy link
Contributor

@Eisenwave Eisenwave commented Feb 28, 2025

Related to #4214.

Changes

  • (C++26) treat #embed as a known preprocessor directive
  • (C++26) add contract_assert, pre, and post keywords
  • (Clang) add _Atomic and _BitInt keywords

As for the last change, Clang supports _Atomic and _BitInt keywords in C++ mode as well, with the same semantics as in C. I am also working on a proposal that introduces bit-precise integers to C++, and either through standardization or common practice, at least _BitInt is expected to become a common non-standard keyword.

Checklist

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

The test expectations depend on decisions made in #4217, so I haven't written tests yet.

Copy link

Build Size Report

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

7 files changed

Total change +109 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.65 KB +27 B
es/languages/cpp.min.js 2.6 KB 2.63 KB +24 B
highlight.min.js 8.23 KB 8.23 KB +3 B
languages/arduino.min.js 4.63 KB 4.65 KB +27 B
languages/cpp.min.js 2.61 KB 2.63 KB +24 B

@joshgoebel
Copy link
Member

Looks good.

Need rebase and and entry added to changelog. Thanks.

Copy link

github-actions bot commented Mar 7, 2025

Build Size Report

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

7 files changed

Total change +114 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.65 KB +28 B
es/languages/cpp.min.js 2.6 KB 2.62 KB +27 B
highlight.min.js 8.23 KB 8.23 KB +1 B
languages/arduino.min.js 4.63 KB 4.65 KB +27 B
languages/cpp.min.js 2.6 KB 2.63 KB +27 B

@Eisenwave
Copy link
Contributor Author

Eisenwave commented Mar 7, 2025

@joshgoebel Could you help me out with this one? I'm kinda clueless as to how I can make the following test cases work, which are currently failing:

void throwing(int x) noexcept(false);
void contracts(int x) pre(x > 10) post(r : r != 0);

highlight.js treats noexcept pre, and post as function titles and the content in parentheses as parameters.

I think the way to fix it is to simply exclude keywords from being function titles, but doing so breaks highlighting for the function completely.

Or perhaps after seeing the closing parenthesis that ends the parameter list, anything up to {, =, or ; should be in a "post-parameters" mode, so we still match it as a function overall no matter what's inside of there.

@joshgoebel
Copy link
Member

joshgoebel commented Mar 9, 2025

Could you help me out with this one?

Maybe it's because this implementation is trying to hard to think like a full parser. Use of function is deprecated now - we no longer try and figure out what a function is (from start to finish, or even the function definition)... we only care about the components, types, title.function, params, etc... if you simplify along those lines, does that help? And also title.function.invoke if we can detect the difference between definition and invokation.

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.

3 participants