Skip to content

[metacling] Handle autotypes in collect_type_info#19133

Draft
aaronj0 wants to merge 1 commit into
root-project:masterfrom
aaronj0:fix-autotypes-cf
Draft

[metacling] Handle autotypes in collect_type_info#19133
aaronj0 wants to merge 1 commit into
root-project:masterfrom
aaronj0:fix-autotypes-cf

Conversation

@aaronj0
Copy link
Copy Markdown
Contributor

@aaronj0 aaronj0 commented Jun 23, 2025

In CallFunc, we canonicalise types before collecting their typeinfo and names. However, if we have an alias to a template type which uses a private struct, this causes us to lose the sugar that makes the type accessible since the struct is private.

template<class T>
class Container {};

class Foo {
private:
   struct Tag;
public:
   using iterator = Container<Tag>;

   auto begin() {
       return iterator{};
   }
};

calling begin on an instance of Foo gives us:

extern "C" void __cf_12(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
   // CallFunc does:
   // new (ret) (Container<Foo::Tag>) (((Foo*)obj)->begin());

   // What should be used:
      new (ret) (Foo::iterator) (((Foo*)obj)->begin());
      return;
   }
   else {
      (void)(((Foo*)obj)->begin());
      return;
   }
}

This PR should fix #18837 (will add tests)

Canonicalizing a type that is an alias to a template type which uses a private struct loses the sugar that makes the type accesible.

```
template<class T>
class Container {};

class Foo {
private:
   struct Tag;
public:
   using iterator = Container<Tag>;

   auto begin() {
       return iterator{};
   }
};
```

calling `begin` on an instance of `Foo` gives us:

```
extern "C" void __cf_12(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
   // CallFunc does:
   // new (ret) (Container<Foo::Tag>) (((Foo*)obj)->begin());

   // What should be used:
      new (ret) (Foo::iterator) (((Foo*)obj)->begin());
      return;
   }
   else {
      (void)(((Foo*)obj)->begin());
      return;
   }
}
```
@aaronj0 aaronj0 requested a review from guitargeek June 23, 2025 09:41
@aaronj0 aaronj0 self-assigned this Jun 23, 2025
@aaronj0 aaronj0 requested review from dpiparo and pcanal as code owners June 23, 2025 09:41
@aaronj0 aaronj0 marked this pull request as draft June 23, 2025 09:41
@github-actions
Copy link
Copy Markdown

Test Results

    20 files      20 suites   3d 22h 11m 5s ⏱️
 3 042 tests  3 041 ✅ 0 💤 1 ❌
59 056 runs  59 054 ✅ 0 💤 2 ❌

For more details on these failures, see this check.

Results for commit 1397502.

Copy link
Copy Markdown
Member

@pcanal pcanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test? Thanks.

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.

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

2 participants