WIP: libcpp and cp: ✨ __builtin_std_embed and #depend implementation, alongside libstdc++-v3 <embed> and version.h header improvements #181

Draft
ThePhD wants to merge 1 commit from ThePhD/gcc-TEST:feature/cxx/std_embed into trunk
Member

This is a Work-In-Progress Pull Request that implements P1040, that is mostly here to ensure that I keep track of everything that is going on.

  • p1040 is accepted by ISO/IEC JTC1 SC22 WG21 Programming Languages, C++
    • Accepted in EWG
    • Accepted in LEWG
  • Implement __builtin_std_embed for the C++ Frontend only
  • Add checking for all argument types
  • Move string_constant and other non-middle-end code to the general frontend for use with all frontends, where appropriate.
  • Implement creation of non-string static constexpr const T[] invisible arrays
    • Make sure they do not produce unused result warnings.
  • wchar_t path name handling for __builtin_std_embed (not implemented; must translate from wide literal encoding using wcset_converter that comes from preprocessor -- how do we access cpp_reader * in the frontend there?)
  • Tests, tests, tests
This is a Work-In-Progress Pull Request that implements P1040, that is mostly here to ensure that I keep track of everything that is going on. - [ ] p1040 is accepted by ISO/IEC JTC1 SC22 WG21 Programming Languages, C++ - [x] Accepted in EWG - [ ] Accepted in LEWG - [x] Implement `__builtin_std_embed` for the C++ Frontend only - [x] Add checking for all argument types - [x] Move `string_constant` and other non-middle-end code to the general frontend for use with all frontends, where appropriate. - [x] Implement creation of non-string `static constexpr const T[]` invisible arrays - [x] Make sure they do not produce unused result warnings. - [x] `wchar_t` path name handling for `__builtin_std_embed` (not implemented; must translate from wide literal encoding using `wcset_converter` that comes from preprocessor -- how do we access `cpp_reader *` in the frontend there?) - [x] Tests, tests, tests
Member

Hi @ThePhD. This bot helps send your PR as a patch series to the mailing list.

Next steps

  1. Write a clear PR description. It will be used as the cover letter.
  2. To CC extra people, add lines like this at the end of the PR description: CC: Reviewer1 <revi.ewer@example.com>, Reviewer2 <an.other@example.com>.
  3. To preview the emails, comment with /preview.
  4. When ready, request review in the Reviewers section. Or, if you just want to send the series, comment with /submit.
  5. Use the cover-letter links below to follow replies.
  6. For a new patch series, push your changes, update the PR description with a Changes since vX section, and comment with /submit again.

See Submitting Patches and UsingForge.

Consider joining the gcc and gcc-patches mailing lists..
For real time communication, check the gcc irc channels.

Or join #overseers on Libera Chat, particularly if this automation is not working (stay online to get replies, IRC does not save messages if people are not online).

<!-- pr-welcome --> Hi @ThePhD. This bot helps send your PR as a patch series to the mailing list. ## Next steps 1. Write a clear PR description. It will be used as the cover letter. 2. To CC extra people, add lines like this **at the end** of the PR description: `CC: Reviewer1 <revi.ewer@example.com>, Reviewer2 <an.other@example.com>`. 3. To preview the emails, comment with `/preview`. 4. When ready, request review in the Reviewers section. Or, if you just want to send the series, comment with `/submit`. 5. Use the cover-letter links below to follow replies. 6. For a new patch series, push your changes, update the PR description with a `Changes since vX` section, and comment with `/submit` again. See [Submitting Patches](https://gcc.gnu.org/contribute.html#patches) and [UsingForge](https://gcc.gnu.org/wiki/UsingForge). Consider joining the [gcc and gcc-patches mailing lists.](https://gcc.gnu.org/lists.html). For real time communication, check the [gcc irc channels](https://gcc.gnu.org/wiki/GCConIRC). Or join [`#overseers`](https://web.libera.chat/#overseers) on Libera Chat, particularly if this automation is not working (stay online to get replies, IRC does not save messages if people are not online).
ThePhD changed title from libcpp and cp: ✨ __builtin_std_embed and #depend implementation, alongside libstdc++-v3 <embed> and version.h header improvements to WIP: libcpp and cp: ✨ __builtin_std_embed and #depend implementation, alongside libstdc++-v3 <embed> and version.h header improvements 2026-06-20 18:02:52 +00:00
ThePhD force-pushed feature/cxx/std_embed from bc3091058d
Some checks failed
/ format-checks (pull_request) Failing after 1m35s
to e8fcf02ad1
Some checks failed
/ format-checks (pull_request) Failing after 1m32s
2026-06-21 23:02:13 +00:00
Compare
ThePhD force-pushed feature/cxx/std_embed from e8fcf02ad1
Some checks failed
/ format-checks (pull_request) Failing after 1m32s
to 08293254c2
Some checks failed
/ format-checks (pull_request) Has been cancelled
2026-06-22 02:32:20 +00:00
Compare
ThePhD force-pushed feature/cxx/std_embed from 08293254c2
Some checks failed
/ format-checks (pull_request) Has been cancelled
to 7c61609724
Some checks failed
/ format-checks (pull_request) Failing after 1m36s
2026-06-22 02:32:35 +00:00
Compare
Owner

Why is there an emoji style '✨' in the commit subject? If you mean an asterisk (star), please use that.

Why is there an emoji style '✨' in the commit subject? If you mean an asterisk (star), please use that.
ThePhD force-pushed feature/cxx/std_embed from 7c61609724
Some checks failed
/ format-checks (pull_request) Failing after 1m36s
to 6d2d1960e2
Some checks failed
/ format-checks (pull_request) Has been cancelled
2026-06-23 01:06:03 +00:00
Compare
ThePhD force-pushed feature/cxx/std_embed from 6d2d1960e2
Some checks failed
/ format-checks (pull_request) Has been cancelled
to ddfb97a1e0
Some checks failed
/ format-checks (pull_request) Failing after 1m33s
2026-06-23 01:06:54 +00:00
Compare
Owner

Just some random comments.

I think the actual file reading should be done on the libcpp side, libcpp already has infrastructure to handle #embed, cache files that can be cached etc. and it would be nice if as much of that code is reused and files can be cached between #embed and __builtin_std_embed, so let the FE figure out the name of the file (using libcpp charset APIs to put it into the right character set) and then ask libcpp to check against #depend and load the file and return the preprocessor buffer containing it.

The code should be able to handle even > 2GiB std::embed calls, which it currently does no, both STRING_CST and RAW_DATA_CST have the 2GiB limitation. But for the latter one can just use several of those, so say for 6GiB minus epsilon use a CONSTRUCTOR with 3 RAW_DATA_CSTs in it, each covering roughly 2GiB.

Wc++29-extensions addition will conflict with https://gcc.gnu.org/pipermail/gcc-patches/2026-June/720168.html

In cxx_eval_builtin_function_call, if only one FE builtin uses arg_locs, perhaps it should be computed just when handling that builtin and not all the other ones.

And some coding style nits:

Some newly added functions don't have a function comment.

if/else/while/for body with a single statement in it shouldn't use {}s around that single statement.

We don't normally use something like
internal_error ("incorrect number of %<__builtin_std_embed%> arguments");
Instead just gcc_assert (the_condition).

Lines shouldn't end with = and with initializer on next line, instead the = should be moved before the initializer.
Similarly e.g. for colon.

Instead of %llu and (unsigned long long int) casts when printing HOST_WIDE_INT using a gcc diagnostic function
one should use %wu and no cast.

I don't think we use -> tree on lambdas normally.

Some calls don't have a space between function name and (.

const char * first_rslash = strrchr (lookup_from, '\\'); there should be no space after *. Also wonder about the '/' searches, should that be always / and not HAVE_DOS_BASED_FILE_SYSTEM dependent?

%<'wchar_t%>

There is a spurious character before wchar_t.

I think constant_byte_string etc. should stay where they are.

The ^L character removals are undesirable.

@jason @marek

Just some random comments. I think the actual file reading should be done on the libcpp side, libcpp already has infrastructure to handle #embed, cache files that can be cached etc. and it would be nice if as much of that code is reused and files can be cached between #embed and __builtin_std_embed, so let the FE figure out the name of the file (using libcpp charset APIs to put it into the right character set) and then ask libcpp to check against #depend and load the file and return the preprocessor buffer containing it. The code should be able to handle even > 2GiB std::embed calls, which it currently does no, both STRING_CST and RAW_DATA_CST have the 2GiB limitation. But for the latter one can just use several of those, so say for 6GiB minus epsilon use a CONSTRUCTOR with 3 RAW_DATA_CSTs in it, each covering roughly 2GiB. Wc++29-extensions addition will conflict with https://gcc.gnu.org/pipermail/gcc-patches/2026-June/720168.html In cxx_eval_builtin_function_call, if only one FE builtin uses arg_locs, perhaps it should be computed just when handling that builtin and not all the other ones. And some coding style nits: Some newly added functions don't have a function comment. if/else/while/for body with a single statement in it shouldn't use {}s around that single statement. We don't normally use something like `internal_error ("incorrect number of %<__builtin_std_embed%> arguments");` Instead just gcc_assert (the_condition). Lines shouldn't end with = and with initializer on next line, instead the = should be moved before the initializer. Similarly e.g. for colon. Instead of %llu and (unsigned long long int) casts when printing HOST_WIDE_INT using a gcc diagnostic function one should use %wu and no cast. I don't think we use -> tree on lambdas normally. Some calls don't have a space between function name and (. `const char * first_rslash = strrchr (lookup_from, '\\');` there should be no space after *. Also wonder about the '/' searches, should that be always / and not HAVE_DOS_BASED_FILE_SYSTEM dependent? ``` %<'wchar_t%> ``` There is a spurious character before wchar_t. I think constant_byte_string etc. should stay where they are. The ^L character removals are undesirable. @jason @marek
Author
Member

Thanks @rearnsha and @jakub for the comments -- it will be a bit before I return to this PR, since I do have to wait for LEWG to approve the last changes they made. But after that I will be back to address all the comments; please don't take my silence as non-interest, there's just a lot to do!

Thanks @rearnsha and @jakub for the comments -- it will be a bit before I return to this PR, since I do have to wait for LEWG to approve the last changes they made. But after that I will be back to address all the comments; please don't take my silence as non-interest, there's just a lot to do!
ThePhD force-pushed feature/cxx/std_embed from ddfb97a1e0
Some checks failed
/ format-checks (pull_request) Failing after 1m33s
to a9eda9452c
Some checks failed
/ format-checks (pull_request) Failing after 1m36s
2026-07-11 06:47:11 +00:00
Compare
ThePhD force-pushed feature/cxx/std_embed from a9eda9452c
Some checks failed
/ format-checks (pull_request) Failing after 1m36s
to 32705f3553
Some checks failed
/ format-checks (pull_request) Failing after 1m38s
2026-07-16 19:12:15 +00:00
Compare
ThePhD force-pushed feature/cxx/std_embed from 32705f3553
Some checks failed
/ format-checks (pull_request) Failing after 1m38s
to 41699485ca
Some checks failed
/ format-checks (pull_request) Failing after 1m38s
2026-07-17 21:22:58 +00:00
Compare
ThePhD force-pushed feature/cxx/std_embed from 41699485ca
Some checks failed
/ format-checks (pull_request) Failing after 1m38s
to 637ecc0448
Some checks failed
/ format-checks (pull_request) Failing after 1m31s
2026-07-20 21:37:58 +00:00
Compare
Some checks failed
/ format-checks (pull_request) Failing after 1m31s
This pull request has changes conflicting with the target branch.
  • gcc/cp/decl.cc
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u feature/cxx/std_embed:ThePhD-feature/cxx/std_embed
git switch ThePhD-feature/cxx/std_embed

Merge

Merge the changes and update on Forgejo.
git switch trunk
git merge --no-ff ThePhD-feature/cxx/std_embed
git switch ThePhD-feature/cxx/std_embed
git rebase trunk
git switch trunk
git merge --ff-only ThePhD-feature/cxx/std_embed
git switch ThePhD-feature/cxx/std_embed
git rebase trunk
git switch trunk
git merge --no-ff ThePhD-feature/cxx/std_embed
git switch trunk
git merge --squash ThePhD-feature/cxx/std_embed
git switch trunk
git merge --ff-only ThePhD-feature/cxx/std_embed
git switch trunk
git merge ThePhD-feature/cxx/std_embed
git push origin trunk
Sign in to join this conversation.
No reviewers
No milestone
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gcc/gcc!181
No description provided.