Skip to content

Conversation

@Vipul-Cariappa
Copy link
Collaborator

@Vipul-Cariappa Vipul-Cariappa commented Nov 28, 2025

requires test:

import cppyy
from cppyy import gbl

cppyy.cppdef(
    r"""
enum What { NO, YES };

template <What E>
struct EE {
    What w = E;
};

template <What E>
What get() {
    return E;
}
"""
)

assert gbl.EE[gbl.What.NO]().w == 0
assert gbl.EE[gbl.What.YES]().w == 1

assert gbl.get[gbl.What.NO]() == 0
assert gbl.get[gbl.What.YES]() == 1

This was discovered while working on ROOT workshop slides.

Vipul-Cariappa added a commit to Vipul-Cariappa/cppyy-compiler-research that referenced this pull request Nov 28, 2025
@Vipul-Cariappa
Copy link
Collaborator Author

Added the test to compiler-research/cppyy#164

}

Cpp::TCppScope_t GetEnumFromCompleteName(const std::string &name) {
std::string delim = "::";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to do string parsing to do a simple-ish lookup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is required for now. There is already some string parsing through the Cpp::GetScopeFromCompleteName and Cppyy::GetScope, I wanted to just reuse them instead of introducing this new function. But that is not possible. All of the *GetScope* fail to resolve enum constants. If I fix that, then other tests fail, because that is the expected behaviour according to cppyy.

We should eventually be able to reduce string parsing, but not eliminate it entirely.
To reduce the string parsing, we will need to update https://github.com/compiler-research/CPyCppyy/blob/9d95a1954d0285f85087e40d638b48b40558b42d/src/TemplateProxy.cxx#L175-L176 not to construct a string, instead return std::vector<Cpp::TCppType_t>, or something similar. I believe all the necessary type information is already stored as QualType*, we unnecessarily convert QualType* to std::string, and back to QualType* again.
I will open an issue to track it.
But we cannot remove the string parsing completely because users can instantiate templates with string. Example: func["int", "double", "MyClass"](1, 2.0, gbl.MyClass(...))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good. Let's move forward!

Copy link
Collaborator

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

LGTM!

@Vipul-Cariappa Vipul-Cariappa merged commit 28999b3 into compiler-research:master Dec 1, 2025
34 checks passed
@Vipul-Cariappa Vipul-Cariappa deleted the dev/enum-template-type branch December 1, 2025 12:37
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.

2 participants