Skip to content

[metacling] Instantiate empty parameter packs#21292

Closed
hahnjo wants to merge 4 commits intoroot-project:masterfrom
hahnjo:tuple-variadic
Closed

[metacling] Instantiate empty parameter packs#21292
hahnjo wants to merge 4 commits intoroot-project:masterfrom
hahnjo:tuple-variadic

Conversation

@hahnjo
Copy link
Copy Markdown
Member

@hahnjo hahnjo commented Feb 16, 2026

This effectively reverts the change of commit 4b00923. It is needed for working conversion with variadic templates from cppyy.

TClassEdit::TSplitType will have an empty string for an empty template
parameter list.
This makes it possible to instantiate an empty RLazyDS.
This effectively reverts the change of commit 4b00923.
This was "fixed" by the previous commit enabling the default
instantiation of template parameter packs.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 16, 2026

Test Results

    19 files      19 suites   2d 16h 23m 0s ⏱️
 3 769 tests  3 337 ✅   0 💤   432 ❌
64 755 runs  63 178 ✅ 113 💤 1 464 ❌

For more details on these failures, see this check.

Results for commit 75f513d.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Member

@dpiparo dpiparo left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Copy Markdown
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

LGTM for the RDF part.

@hahnjo
Copy link
Copy Markdown
Member Author

hahnjo commented Feb 17, 2026

So this doesn't work on macOS, mostly because of std::variant related function templates where it actually fails to instantiate with the empty parameter pack. As a short-term workaround, it would be possible to only instantiate parameter packs when it's not the first parameter:

diff --git a/core/metacling/src/TClingMethodInfo.cxx b/core/metacling/src/TClingMethodInfo.cxx
index bb458163f70..692725d75c0 100644
--- a/core/metacling/src/TClingMethodInfo.cxx
+++ b/core/metacling/src/TClingMethodInfo.cxx
@@ -161,6 +161,9 @@ TClingCXXRecMethIter::InstantiateTemplateWithDefaults(const clang::RedeclarableT                                                                                                   
    llvm::SmallVector<TemplateArgument, 8> defaultTemplateArgs;
    for (const NamedDecl *templateParm: *templateParms) {
       if (templateParm->isTemplateParameterPack()) {
+         if (defaultTemplateArgs.size() == 0) {
+            return nullptr;
+         }
          defaultTemplateArgs.emplace_back(ArrayRef<TemplateArgument>{}); // empty pack.
       } else if (auto TTP = dyn_cast<TemplateTypeParmDecl>(templateParm)) {
          if (!TTP->hasDefaultArgument())

That would be get me what I need for the histograms, but potentially confusing why other member templates are not instantiated. Opinions?

@hahnjo hahnjo marked this pull request as draft February 17, 2026 15:37
@pcanal
Copy link
Copy Markdown
Member

pcanal commented Mar 17, 2026

So this doesn't work on macOS, mostly because of std::variant related function templates where it actually fails to instantiate with the empty parameter pack.

'What' is the mechanism that makes it fails? Is it invalid to do so? If it is invalid is there a (simple) way to inquire whether it is/will-be invalid?

@hahnjo
Copy link
Copy Markdown
Member Author

hahnjo commented Mar 18, 2026

So this doesn't work on macOS, mostly because of std::variant related function templates where it actually fails to instantiate with the empty parameter pack.

'What' is the mechanism that makes it fails? Is it invalid to do so?

Yes, a variant requires at least one type:

A program that instantiates the definition of std::variant with no template arguments is ill-formed.

(from https://en.cppreference.com/w/cpp/utility/variant.html)

If it is invalid is there a (simple) way to inquire whether it is/will-be invalid?

No.

@hahnjo
Copy link
Copy Markdown
Member Author

hahnjo commented Apr 8, 2026

I don't see a good solution for the problems with std::variant.

@hahnjo hahnjo closed this Apr 8, 2026
@hahnjo hahnjo deleted the tuple-variadic branch April 8, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants