Template Deduction Error Oddity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Before a bug report gets filed on this, I wanted input as to whether I
am doing something wrong.  While I am pretty sure gcc is wrong here, I
figured people smarter than I might want to weigh in... :)

Consider the following stripped down code:

class Ref { ... };
class A { ... };
class B { ... };
class C { ... };
Class Dummy {
  template<typename T>
  struct IterRet { ... };
 template<typename R, typename... Args_>
  using iter_ret_fn = IterRet<R> (*)(const Ref&, Args_&&... args);
  template<typename R, typename... Defn_>
  using iter_ret_fn_type = iter_ret_fn<R, Defn_...>;
  template<typename R, typename... Args_>
  inline IterRet<R>
  iterate_items_until_ret(iter_ret_fn_type<R, Args_...> fn, Args_&&...
args) const noexcept
  { ... }
};

The following compiles:

Dummy::iter_ret_fn<int, const A&, const B& C&> lambda = [](const Ref&
r, const A& a, const B& b, C& c) -> Dummy::IterRet<int> { ... };
auto&& [state, retval] = object->iterate_until_ret<int, const A&,
const B&, C&>(lambda, x, y, z);

However, if I change to this:

auto lambda = [](const Ref& r, const A& a, const B& b, C& c) ->
Dummy::IterRet<int> { ... };
auto [state, retval] = object->iterate_until_ret<int, const A&, const
B&, C&>(lambda, x, y, z);

I get this error:

File.hh:298:3: note:   template argument deduction/substitution failed:
File.cc:599:143: note:   mismatched types ‘Dummy::IterRet<int>
(*)(const Ref&, Defn_&& ...)’ and ‘fn_name(...)::<lambda(const Ref&,
const A&, const B&, Cl&)>’
... = object->iterate_until_ret<int, const A&, const B&, C&>(lambda, x, y, z);

If I do this:

auto lambda = [](const Ref& r, const A& a, const B& b, C& c) ->
Dummy::IterRet<int> { ... };
Dummy::iter_ret_fn_type<int, const A&, const B&, C&>l2 = lambda;
auto [state, retval] = object->iterate_until_ret<int, const A&, const
B&, C&>(l2, x, y, z);

Then it compiles just fine, indicating that auto is being deduced
correctly. (And if I use the decltype(lambda)::_ trick, the error
message from gcc 8.1.0 indicates the right fn signature).

So... bug?  Or am I doing something wrong?

Thanks,

--Mike

P.S. The reason the lambda isn't just embedded in the call to
Dummy::iterate_until_ret() is because it produces the same deduction
error.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux