Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Report error on extern cppclass with member and method has the same name #6554

Open
user202729 opened this issue Dec 9, 2024 · 0 comments

Comments

@user202729
Copy link

user202729 commented Dec 9, 2024

Is your feature request related to a problem? Please describe.

The following code ought to provide an error (it's illegal for a C++ class to have a member and a method with the same name), but doesn't.

# distutils: language = c++
# distutils: extra_compile_args = -std=c++11
cdef extern from *:
    """
    struct A {
    public:
        int a(){ return 1; }
    };
    """
    cppclass A:
        A()
        int a  # error goes undetected
        int a()

cdef A x = A()
print(x.a())

The reason why I'm asking is because there's this SageMath bug sagemath/sage#39092 which actually leads to Cython generates code that contains the literal string <error> (and thus is invalid code), although I haven't been able to find a small example that reproduce the issue yet.


Actually, there are some convoluted cases where it actually works:

# distutils: language = c++
# distutils: extra_compile_args = -std=c++11
cdef extern from *:
    r"""
    using F = int(*)();
    struct B{
        operator int() const{return 1;}
        operator F() const{return [](){return 2;};}
    };
    struct A {
    public:
        B a;
    };
    """
    cppclass A:
        A()
        int a
        int a()

cdef A x = A()
print(<int>x.a, x.a())

So anyway, do you think it's reasonable to forbid member and function with the same name entirely?

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

No branches or pull requests

1 participant