This is an archive of the discontinued LLVM Phabricator instance.

Fix for Bug 33471: Preventing operator auto from resolving to a template operator.
ClosedPublic

Authored by erichkeane on Jun 19 2017, 3:23 PM.

Details

Summary

As the bug report says,
struct A
{

template<typename T> operator T();

};

void foo()
{

A().operator auto();

}

causes: "undeduced type in IR-generation
UNREACHABLE executed at llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:208!"

The problem is that in this case, "T" is being deduced as "auto", which I believe is incorrect.

The 'operator auto' implementation in Clang is standards compliant, however there is a defect report against core (1670).

Diff Detail

Repository
rL LLVM

Event Timeline

erichkeane created this revision.Jun 19 2017, 3:23 PM
rsmith added inline comments.Jun 19 2017, 3:39 PM
lib/Sema/SemaLookup.cpp
870–872 ↗(On Diff #103115)

This is not sufficient to catch cases such as operator auto*, and one day there'll be concepts and potentially class template argument deduction here too. Use Ty->getContainedDeducedType() instead.

erichkeane marked an inline comment as done.

Hi @rsmith
Thanks for the quick response! I spent a while going over it, and think I have what you were looking for. I Also added the operator auto * tests.

rsmith accepted this revision.Jun 20 2017, 9:29 AM

Looks good, thanks!

lib/Sema/SemaLookup.cpp
870 ↗(On Diff #103224)

Maybe only call this once?

This revision is now accepted and ready to land.Jun 20 2017, 9:29 AM
erichkeane added inline comments.Jun 20 2017, 9:33 AM
lib/Sema/SemaLookup.cpp
870 ↗(On Diff #103224)

Sure, I'll extract this into a variable above the if statement before committing.

This revision was automatically updated to reflect the committed changes.