This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] check for using declarations not in an anonymous namespace when there exists one
Needs ReviewPublic

Authored by Ywicheng on Dec 6 2018, 8:53 PM.

Details

Summary

This patch adds one check corresponding to the Unnamed Namespace section in https://abseil.io/tips/119.

In particular, if there exists an anonymous, it is better to put all aliases there.

Diff Detail

Event Timeline

Ywicheng created this revision.Dec 6 2018, 8:53 PM
Ywicheng updated this revision to Diff 177115.Dec 6 2018, 9:01 PM

Updated abseil-anonymous-enclosed-alises.rst and ReleaseNotes.rst

Ywicheng updated this revision to Diff 177121.Dec 6 2018, 9:43 PM

Please upload with full context.

aaron.ballman requested changes to this revision.Dec 10 2018, 5:06 AM
aaron.ballman added inline comments.
clang-tidy/abseil/AnonymousEnclosedAliasesCheck.cpp
33

Spurious newline.

42

I don't think this logic works in practice because there's no way to determine that the anonymous namespace is even a candidate for putting the using declaration into it. Consider a common scenario where there's an anonymous namespace declared in a header file (like an STL header outside of the user's control), and a using declaration inside of an implementation file. Just because the STL declared an anonymous namespace doesn't mean that the user could have put their using declaration in it.

44–45

Diagnostics should not be complete sentences or contain hyperlinks. (Same below.)

clang-tidy/abseil/AnonymousEnclosedAliasesCheck.h
21

Detecting incorrect -> Detecting the incorrect

22

when there exists one -> when one exists

This revision now requires changes to proceed.Dec 10 2018, 5:06 AM
JonasToth resigned from this revision.Dec 13 2018, 3:14 AM
Naysh marked an inline comment as done.Apr 10 2019, 5:24 PM
Naysh added a subscriber: Naysh.
Naysh added inline comments.
clang-tidy/abseil/AnonymousEnclosedAliasesCheck.cpp
42

If we altered the check to only apply to anonymous namespaces and using declarations at namespace scope (that is, we only suggest aliases be moved to anonymous namespaces when the unnamed namespace and alias are themselves inside some other namespace), would this issue be resolved?

aaron.ballman added inline comments.Apr 11 2019, 10:06 AM
clang-tidy/abseil/AnonymousEnclosedAliasesCheck.cpp
42

If they're inside the same namespace, then I think that could work, but if the namespaces are different I don't know that you can be sure the alias can be moved into the anonymous namespace.

Ywicheng updated this revision to Diff 195656.Apr 17 2019, 5:56 PM