seanbaxter / circle

The compiler is available for download. Get it!
http://www.circle-lang.org/
2.42k stars 74 forks source link

explicit function template instantiation does not respect interfaces #171

Open mnaydenov opened 1 year ago

mnaydenov commented 1 year ago

Consider

#feature on interface self
#include <iostream>

interface IPrint {
  void print() const { std::cout<< "none\n"; }
};

impl double : IPrint {
  void print() const {
    std::cout<< self<< "\n";
  }
};

template<typename T : IPrint>
void func(T& obj) {
  obj.print();
}

template void func<double>(double&);

The above will fail to compile with

  'print' is not a member of type double
    obj.print(); 

Which is the standard template error, essentially bypassing the interface checks.

Same is true when one tries to get the address of an instantiation

auto addr = &func<double>;

Workaround Either call the function: func(x) or decltype the call: using T = decltype(func(x));