This is an archive of the discontinued LLVM Phabricator instance.

[clang] Improve diagnostic for reopened inline namespace
ClosedPublic

Authored by fwolff on Mar 22 2022, 6:13 PM.

Details

Summary

Fixes #50794. Reopening an inline namespace without the inline keyword yields a warning:

inline namespace abc {}
namespace abc {}
namespace abc {}
<source>:2:11: warning: inline namespace reopened as a non-inline namespace [-Winline-namespace-reopened-noninline]
namespace abc {}
          ^
inline 
<source>:1:18: note: previous definition is here
inline namespace abc {}
                 ^
<source>:3:11: warning: inline namespace reopened as a non-inline namespace [-Winline-namespace-reopened-noninline]
namespace abc {}
          ^
inline 
<source>:2:11: note: previous definition is here
namespace abc {}
          ^

But you'll notice that the second "previous definition is here" is actually not helpful, because this previous definition isn't explicitly marked inline. I think that the note should point to the first definition instead, which must always have the inline if the namespace is supposed to be an inline namespace.

Diff Detail

Event Timeline

fwolff created this revision.Mar 22 2022, 6:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2022, 6:13 PM
fwolff requested review of this revision.Mar 22 2022, 6:13 PM
cor3ntin accepted this revision.Mar 23 2022, 2:23 AM

This looks good to me, thanks!

This revision is now accepted and ready to land.Mar 23 2022, 2:23 AM

Thank you for the fix! This LGTM with a minor nit, but please also add a release note for the fix.

clang/lib/Sema/SemaDeclCXX.cpp
11062–11066

There are no circumstances under which getFirstDecl() should return null, so I think this can be simplified.

aaron.ballman accepted this revision.Mar 23 2022, 5:23 AM
This revision was automatically updated to reflect the committed changes.