[PATCH] Fix return type deduction for member templates

Faisal Vali faisalv at gmail.com
Thu Jun 13 11:30:25 PDT 2013

While implementing return type deduction for generic lambdas, I stumbled upon
a bug which led to clang mishandling the following code:

struct Lambda {
  template<class T> auto operator()(T t) {
    return 5;
template<class T> auto foo(T t) { return t; }
void test() {
    Lambda L;
    int i = L(3);

The issue (as i understand it) was that in some contexts only the
function template (and not the specialization) would get passed to
DiagnoseUseOfDecl (which deduces the return type of the function).  So
the specialization would flow through to Codegen with auto as its
return type.

So, with that in mind, this patch implements a trivial fix.

What do you think Richard? Is there a better way to address this bug?
Are there other places
this could happen (ie. template conversion operator?)

Faisal Vali
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-return-type-deduction-for-member-templates.patch
Type: application/octet-stream
Size: 2291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130613/8e828483/attachment.obj>

More information about the cfe-commits mailing list