Page MenuHomePhabricator

Improve diagnostics if friend function redefines file-level function.
ClosedPublic

Authored by sepavloff on Oct 27 2016, 11:00 PM.

Details

Summary

Clang makes check for function redefinition after it merged the new
declaration with the existing one. As a result, it produces poor
diagnostics in the case of a friend function defined inline, as in
the code:

void func() {}
class C { friend void func() {} };

Error message in this case states that `inline declaration of 'func'
follows non-inline definition`, which is misleading, as func does
not have explicit inline specifier.

With this changes compiler reports function redefinition if the new
function is a friend defined inline and it does not have explicit
inline specifier.

Diff Detail

Repository
rL LLVM

Event Timeline

sepavloff updated this revision to Diff 76166.Oct 27 2016, 11:00 PM
sepavloff retitled this revision from to Improve diagnostics if friend function redefines file-level function..
sepavloff updated this object.
sepavloff added a subscriber: cfe-commits.
sepavloff updated this object.Oct 31 2016, 9:49 AM
sepavloff updated this revision to Diff 76520.Oct 31 2016, 10:25 PM

Do not use getFriendObjectKind(), friend kind sometimes is set too late.

arphaman added inline comments.
lib/Sema/SemaDeclCXX.cpp
646 ↗(On Diff #76520)

This is somewhat confusing to me: are you using the !New->isOutOfLine() || !New->getLexicalDeclContext()->isRecord() check to ensure that this new declaration is not a friend?

sepavloff added inline comments.Jun 6 2017, 9:32 PM
lib/Sema/SemaDeclCXX.cpp
646 ↗(On Diff #76520)

Indeed, this check is obscure. Replaced by call to getFriendObjectKind.

sepavloff updated this revision to Diff 101666.Jun 6 2017, 9:33 PM

Rebased and enhance check

arphaman accepted this revision.Jun 7 2017, 9:51 AM

LGTM.

This revision is now accepted and ready to land.Jun 7 2017, 9:51 AM
rsmith accepted this revision.Jun 7 2017, 6:52 PM
This revision was automatically updated to reflect the committed changes.