Skip to content

[CPyCppyy] Work around non-instantiable std::span iterators in GCC 15#20891

Merged
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:issue-18837
Jan 17, 2026
Merged

[CPyCppyy] Work around non-instantiable std::span iterators in GCC 15#20891
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:issue-18837

Conversation

@guitargeek
Copy link
Copy Markdown
Contributor

@guitargeek guitargeek commented Jan 14, 2026

The libstdc++ (GCC >= 15) implements std::span::iterator using a private nested tag type, which makes the iterator non-instantiable by CallFunc-generated wrappers (the return type cannot be named without violating access rules).

To preserve correct Python iteration semantics, this commit suggests to replace begin()/end() for std::span to return a custom pointer-based iterator instead. This avoids relying on std::span::iterator while still providing a real C++ iterator object that CPyCppyy can also wrap and expose via __iter__/__next__.

A unit test is implemented based on the reproducers provided in #18837.

Closes #18837.

@guitargeek guitargeek self-assigned this Jan 14, 2026
@guitargeek guitargeek added bug in:Python Interface experiment Affects an experiment / reported by its software & computimng experts labels Jan 14, 2026
@guitargeek
Copy link
Copy Markdown
Contributor Author

@sponce To which releases would you need this packported?

@sponce
Copy link
Copy Markdown

sponce commented Jan 14, 2026

Ideally LCG108 version, so 6.36

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 15, 2026

Test Results

    22 files      22 suites   3d 18h 48m 15s ⏱️
 3 813 tests  3 813 ✅ 0 💤 0 ❌
76 715 runs  76 715 ✅ 0 💤 0 ❌

Results for commit 7b307b1.

♻️ This comment has been updated with latest results.

@guitargeek guitargeek force-pushed the issue-18837 branch 3 times, most recently from 1780879 to b5dac61 Compare January 15, 2026 09:50
@guitargeek
Copy link
Copy Markdown
Contributor Author

Requires #20895 to work also on Windows.

The libstdc++ (GCC >= 15) implements `std::span::iterator` using a
private nested tag type, which makes the iterator non-instantiable by
CallFunc-generated wrappers (the return type cannot be named without
violating access rules).

To preserve correct Python iteration semantics, this commit suggests to
replace `begin()`/`end()` for `std::span` to return a custom
pointer-based iterator instead. This avoids relying on
`std::span::iterator` while still providing a real C++ iterator object
that CPyCppyy can also wrap and expose via `__iter__`/`__next__`.

A unit test is implemented based on the reproducers provided in root-project#18837.

Closes root-project#18837.
@dpiparo
Copy link
Copy Markdown
Member

dpiparo commented Jan 16, 2026

Requires #20895 to work also on Windows.

This is now merged into master, right?

@guitargeek
Copy link
Copy Markdown
Contributor Author

Yes, correct! So for me this PR is good to go. But it should be only a temporary solution that is safe to backport. The sustainable fix for #18837 will be to fix TClingCallFunc.

@dpiparo dpiparo self-requested a review January 17, 2026 14:40
@guitargeek guitargeek merged commit 598e301 into root-project:master Jan 17, 2026
50 of 53 checks passed
@guitargeek guitargeek deleted the issue-18837 branch January 17, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug experiment Affects an experiment / reported by its software & computimng experts in:Python Interface priority:high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Calling std::span::begin() broken with gcc15

3 participants