This is an archive of the discontinued LLVM Phabricator instance.

[clang][Sema] Improve diagnostics for auto return type
ClosedPublic

Authored by yaxunl on May 9 2023, 11:16 AM.

Details

Summary

Currently when clang fails to deduce auto return type of a function,
it does not emit any notes about why it fails. This causes difficulty
for users to fix such errors.

Actually, clang already generates the information for emitting notes
about the failed deduction. There is a TODO for actually emitting
them.

This patch tries to implement the TODO. Basically it passes the
failed template specialization candidate set from the point of
specialization failure back to the point where the deduction starts.

It is not comprehensive but would be a start for further improvement.

Diff Detail

Event Timeline

yaxunl created this revision.May 9 2023, 11:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 11:16 AM
yaxunl requested review of this revision.May 9 2023, 11:16 AM

ping

The pre-merge check failure seems not related to the patch. Other patches also fail the same way.

rsmith added inline comments.May 29 2023, 9:30 AM
clang/include/clang/Sema/TemplateDeduction.h
338

Do we need to allow the location to be set after the set is created? Giving this type an additional state where the location is absent seems error prone, and in the uses below it looks easy to set the location in the caller instead of the callee.

yaxunl added inline comments.May 30 2023, 10:06 AM
clang/include/clang/Sema/TemplateDeduction.h
338

I will fix this.

yaxunl updated this revision to Diff 526693.May 30 2023, 10:09 AM

revised by Richard's comments

This revision is now accepted and ready to land.May 30 2023, 10:58 AM
rsmith accepted this revision.May 30 2023, 12:10 PM

LGTM too.

clang/test/SemaCXX/auto-type-from-cxx.cpp
31–43

The end of this test seems unnecessary. Is there something else you want this test to cover, or can it be simplified?

yaxunl added inline comments.May 30 2023, 7:48 PM
clang/test/SemaCXX/auto-type-from-cxx.cpp
31–43

I thought it was necessary to cause clang to emit the diagnostic messages, but you are right that they are unnecessary. I will remove them when committing.

This revision was landed with ongoing or failed builds.May 30 2023, 8:36 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2023, 8:36 PM