cppyy icon indicating copy to clipboard operation
cppyy copied to clipboard

Type aliases for arrays are not recognized

Open matthew-limbinar opened this issue 1 year ago • 1 comments

Brilliant piece of work here! It has impressed me many times already.

Here is one little snafu that I experienced with v3.1.2:

import cppyy
cppyy.cppdef("using IntArray = int[5];") # or "typedef int IntArray[5];"
X = cppyy.gbl.IntArray

which yields:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: <namespace cppyy.gbl at 0x2d8e890> has no attribute 'IntArray'. Full details:
  type object '' has no attribute 'IntArray'
  'IntArray' is not a known C++ class
  'IntArray' is not a known C++ template
  'IntArray' is not a known C++ enum

Similarly, I can do this:

cppyy.cppdef("""
  struct Holder { 
    using IntArray = int[7]; 
    IntArray a;
  };
""")

x = Holder() # Ok!
print(len(x.a)) # Prints "7"

y = Holder.IntArray() # ERROR! (as above)

Workaround: use std::array<int, 5> instead.

Thanks again for the quality project!

matthew-limbinar avatar Sep 30 '24 20:09 matthew-limbinar

Yes, Cling does not expose using in classes. It's on my wish list.

wlav avatar Sep 30 '24 22:09 wlav