This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Emit a diagnostic for an invalid dependent function template specialization
ClosedPublic

Authored by erik.pilkington on Jul 9 2018, 9:42 AM.

Details

Summary

Previously, clang marked a decl as invalid without emitting a diagnostic. This lead to an assert in CodeGen for the attached test case.

rdar://41806724

Thanks for taking a look!
Erik

Diff Detail

Repository
rL LLVM

Event Timeline

erik.pilkington created this revision.Jul 9 2018, 9:42 AM

This is the right basic approach. I think it would be better if the diagnostic text was more like err_function_template_spec_no_match, maybe "no candidate function template was found for dependent friend function template specialization". And it would be good to emit notes on any declarations we found but discarded.

Improve the diagnostics. Thanks!

rjmccall added inline comments.Jul 19 2018, 11:18 AM
clang/include/clang/Basic/DiagnosticSemaKinds.td
4111 ↗(On Diff #156317)

Your first explanation has a subject, but the second doesn't. And I think it would be nice to suggest adding explicit scope qualification in the second case.

I assume non-templates have previously been filtered out?

Improve the diagnostics further.

clang/include/clang/Basic/DiagnosticSemaKinds.td
4111 ↗(On Diff #156317)

Oh, no, good point. A non-template can still get into here:

namespace ns1 { template <class T> struct foo {}; }
namespace ns2 { int foo() {} } // bad diag: template is not a function template
using ns1::foo;
using ns2::foo;

template <class T> class A {
    friend void foo<T>() {}
};

I added this to the testcases.

rjmccall accepted this revision.Jul 19 2018, 1:03 PM

LGTM.

clang/include/clang/Basic/DiagnosticSemaKinds.td
4111 ↗(On Diff #156317)

Thanks, these look great.

This revision is now accepted and ready to land.Jul 19 2018, 1:03 PM
This revision was automatically updated to reflect the committed changes.