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

Typedef causes error "not declared in scope" #11

Closed
vrmpx opened this issue Jul 19, 2017 · 3 comments
Closed

Typedef causes error "not declared in scope" #11

vrmpx opened this issue Jul 19, 2017 · 3 comments
Assignees

Comments

@vrmpx
Copy link

vrmpx commented Jul 19, 2017

Consider the file vector.h

namespace example {

        template<typename Real>
        class Vector{
        public:
                Vector() { }
                void Set(int i, Real r){
                        //Sets i-th element equal to r
                }
        };

        template<class ObjectType>
        class ObjectTypeHolder {
        public:
                typedef ObjectType T;

                ObjectTypeHolder() { }

                void FailTerribly(ObjectTypeHolder<T> *other){
                  // Fails...
                }

                void DoNothing(ObjectTypeHolder<T> &other){
                        //Does not fail...
                }
        };


}

We wrap it in vector.clif

from "vector.h":
  namespace `example`:

    class `Vector<float>` as Vector:
      def Set(self, i:int, r:float)

    class `ObjectTypeHolder< Vector<float> >` as VectorHolder:
      def DoNothing(self, other:VectorHolder)
      def FailTerribly(self, other:VectorHolder)

Which raises the following issue when doing python setup.py install

vector-clifwrap.cc: In function ‘PyObject* vector_clifwrap::pyVectorHolder::wrapFailTerribly(PyObject*, PyObject*, PyObject*)’:
vector-clifwrap.cc:218:60: error: ‘Vector’ was not declared in this scope
   ::example::ObjectTypeHolder< ::example::ObjectTypeHolder<Vector<float> >::T> * arg1;
                                                            ^
vector-clifwrap.cc:218:60: note: suggested alternative:
In file included from vector-clifwrap.h:9:0,
                 from vector-clifwrap.cc:11:
vector.h:9:8: note:   ‘example::Vector’
  class Vector{
        ^
vector-clifwrap.cc:218:72: error: template argument 1 is invalid
   ::example::ObjectTypeHolder< ::example::ObjectTypeHolder<Vector<float> >::T> * arg1;
                                                                        ^
vector-clifwrap.cc:218:74: error: template argument 1 is invalid
   ::example::ObjectTypeHolder< ::example::ObjectTypeHolder<Vector<float> >::T> * arg1;
                                                                          ^
vector-clifwrap.cc:218:78: error: expected initializer before ‘>’ token
   ::example::ObjectTypeHolder< ::example::ObjectTypeHolder<Vector<float> >::T> * arg1;
                                                                              ^
vector-clifwrap.cc:219:28: error: ‘arg1’ was not declared in this scope
   if (!Clif_PyObjAs(a[0], &arg1)) return ArgError("FailTerribly", names[0], "::example::ObjectTypeHolder< ::example::ObjectTypeHolder<
                            ^
vector-clifwrap.cc:226:21: error: ‘arg1’ was not declared in this scope
     c->FailTerribly(arg1);
                     ^
error: command 'gcc' failed with exit status 1

As you may see, this error does not happen for DoNothing and it goes away if we do not expose FailTerribly in the clif file. For comparison, here are the important parts from the produced code in both methods:

DoNothing

if (!PyArg_ParseTupleAndKeywords(args, kw, "O:DoNothing", names, &a[0])) return nullptr;
  ::example::ObjectTypeHolder< ::example::Vector<float> >* arg1;

FailTerribly

if (!PyArg_ParseTupleAndKeywords(args, kw, "O:FailTerribly", names, &a[0])) return nullptr;
  ::example::ObjectTypeHolder< ::example::ObjectTypeHolder<Vector<float> >::T> * arg1;

What would be the general advice to wrap such cases?

@mrovner mrovner self-assigned this Jul 31, 2017
@mrovner
Copy link
Contributor

mrovner commented Jul 31, 2017

Thank you for the report. The bug was identified (in LLVM API) and we are working to alleviate it in CLIF. ETA fix is the next release coming this quarter.

There is no good workaround on the user side but if you can avoid typedefs in FailTerribly it might help.

@vrmpx
Copy link
Author

vrmpx commented Jul 31, 2017

Thank you for your reply and for making clif.
I'll be looking forward for the next release.

@rwgk
Copy link
Contributor

rwgk commented Oct 6, 2020

This repo was unmaintained from December 2017 to September 2019.
It was recently updated, see #36 (comment) for some background.

If this issue is still relevant please repopen it or ask questions at https://github.com/google/clif/discussions/.

@rwgk rwgk closed this as completed Oct 6, 2020
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

3 participants