grasph/wrapit

Methods with template-typed arguments

Closed this issue · 4 comments

For this MWE I modified TestTemplate2

namespace N {

template<typename T>
class A {
public: 
  A(): a(0){}

  T getval(){ return a;}
  
  void setval(const T& val){ a = val; }
  T& operator[](int i) { return a; }
  T a;
};

template class A<int>;

void g(A<int>& a) { }

class B {
public:
    void f(A<int>& a) { a = data; }
    A<int> data;
};

}

and set auto_veto = true in the ".wit" toml.

Interestingly, read write access for B::data is generated, but faulty, whereas B::f is skipped. I tried to track this one down myself, but I cannot exactly pin down what leads to this failure.

Using auto_veto = false and this file here

namespace N {

template<typename T>
class A {
public: 
  A(): a(0){}

  T getval(){ return a;}
  
  void setval(const T& val){ a = val; }
  T a;
};

template class A<int>;

void g(A<int>& a) { }

class B {
public:
    void f(A<int>& a) { a = data; }
    A<int> data;
};

}

generates B::F, but the access to data is still broken.

Can you try with the new commit (38023c8) I've just pushed on the main branch? Latest development done on operator may have fixed the issue you are reporting.

Philippe.

Both still fails (if you namespace A).

clang-13: warning: argument unused during compilation: '-fmax-errors=3' [-Wunused-command-line-argument]
libTestTemplate3/src/jlTestTemplate3.cxx:83:49: error: no template named 'A'; did you mean 'N::A'?
    t.method("data", [](const N::B& a) -> const A<int>& { return a.data; });
                                                ^
                                                N::A
./A.h:4:7: note: 'N::A' declared here
class A {
      ^
libTestTemplate3/src/jlTestTemplate3.cxx:84:37: error: no template named 'A'; did you mean 'N::A'?
    t.method("data", [](N::B& a) -> A<int>& { return a.data; });
                                    ^
                                    N::A
./A.h:4:7: note: 'N::A' declared here
class A {
      ^
libTestTemplate3/src/jlTestTemplate3.cxx:85:49: error: no template named 'A'; did you mean 'N::A'?
    t.method("data", [](const N::B* a) -> const A<int>& { return a->data; });
                                                ^
                                                N::A
./A.h:4:7: note: 'N::A' declared here
class A {
      ^
libTestTemplate3/src/jlTestTemplate3.cxx:86:37: error: no template named 'A'; did you mean 'N::A'?
    t.method("data", [](N::B* a) -> A<int>& { return a->data; });
                                    ^
                                    N::A
./A.h:4:7: note: 'N::A' declared here
class A {
      ^
libTestTemplate3/src/jlTestTemplate3.cxx:92:41: error: no template named 'A'; did you mean 'N::A'?
    t.method("data!", [](N::B& a, const A<int>& val) -> A<int>& { return a.data = val; });
                                        ^
                                        N::A
./A.h:4:7: note: 'N::A' declared here
class A {
      ^
libTestTemplate3/src/jlTestTemplate3.cxx:92:57: error: no template named 'A'; did you mean 'N::A'?
    t.method("data!", [](N::B& a, const A<int>& val) -> A<int>& { return a.data = val; });
                                                        ^
                                                        N::A
./A.h:4:7: note: 'N::A' declared here
class A {
      ^
libTestTemplate3/src/jlTestTemplate3.cxx:95:41: error: no template named 'A'; did you mean 'N::A'?
    t.method("data!", [](N::B* a, const A<int>& val) -> A<int>& { return a->data = val; });
                                        ^
                                        N::A
./A.h:4:7: note: 'N::A' declared here
class A {
      ^
libTestTemplate3/src/jlTestTemplate3.cxx:95:57: error: no template named 'A'; did you mean 'N::A'?
    t.method("data!", [](N::B* a, const A<int>& val) -> A<int>& { return a->data = val; });
                                                        ^
                                                        N::A
./A.h:4:7: note: 'N::A' declared here
class A {
      ^
8 errors generated.
make: *** [../make.rules:39: libTestTemplate3/build/jlTestTemplate3.o] Error 1

And thanks for taking time so quickly!

Should be fixed by the merged PR: see test/TestNamespace new unit test. Please, reopen the issue if it's not fully fixed.

Thanks!

I am now getting very different errors, most of them related to inheritance, but I cannot find a minimal reproducer right now (tried for almost an hour now to get something). Basically I am getting errors on two types of things now:

  1. friends, e.g.
error: no candidate function template was found for dependent friend function template specialization
   friend void Swap<T>(Array<T> &, Array<T> &);
  1. inheritance, e.g.
error: cannot initialize object parameter of type 'mfem::NewtonSolver' with an expression of type 'mfem::LBFGSSolver'
      NewtonSolver::SetOperator(op);

both errors are new. I will try to bisect later this week which commit caused this.