This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 2/2] replace several uses of the anon namespace with GCC_FINAL
- From: Trevor Saunders <tbsaunde at tbsaunde dot org>
- To: Mikhail Maltsev <maltsevm at gmail dot com>
- Cc: Jeff Law <law at redhat dot com>, tbsaunde+gcc at tbsaunde dot org, gcc-patches at gcc dot gnu dot org, richard dot sandiford at arm dot com
- Date: Fri, 14 Aug 2015 18:42:49 -0400
- Subject: Re: [PATCH 2/2] replace several uses of the anon namespace with GCC_FINAL
- Authentication-results: sourceware.org; auth=none
- References: <1439208314-7390-1-git-send-email-tbsaunde+gcc at tbsaunde dot org> <1439208314-7390-2-git-send-email-tbsaunde+gcc at tbsaunde dot org> <55CA4B93 dot 3060003 at redhat dot com> <87oaicbaht dot fsf at e105548-lin dot cambridge dot arm dot com> <55CB9888 dot 4000200 at redhat dot com> <20150812203608 dot GB4898 at tsaunders-iceball dot corp dot tor1 dot mozilla dot com> <55CCCC4F dot 9000508 at gmail dot com>
On Thu, Aug 13, 2015 at 07:56:47PM +0300, Mikhail Maltsev wrote:
> On 08/12/2015 11:36 PM, Trevor Saunders wrote:
> > In many places gcc puts classes in the anon namespace so the compiler can tell
> > they do not get inheritted from to enable better devirtualization.
> C++ does not allow class members to have static linkage, so there is no way to
> tell the compiler that a member function will not be called from another
> translation unit except for placing it into an anonymous namespace. AFAIK this
> affects inliner decisions rather significantly (i.e. devirtualization is not
> the only reason).
In general that seems valid though in these particular cases I don't
think the compiler could eliminate many members because most of them are
virtual functions, and pointers to objects of there type escape the TU.
> > are they actually all that common? I think gcc is the only C++ with
> > which I'm familiar that uses them much.
> LLVM is an example of another large project, which uses anonymous namespaces
> extensively: http://llvm.org/docs/CodingStandards.html#anonymous-namespaces
interesting
> BTW, I noticed that LLVM developers put small inline functions into anon.
> namespaces (instead of just declaring them static). I wonder, whether it is just a
> matter of style or there is some other, more important reason...
I can't think of one, and that seems to contradict the style guide you
linked?
> >> The problem is you can't get to stuff in the anonymous namespace easily in
> >> the debugger. There was talk of fixing that, but I don't think it ever went
> >> forward on the gdb side.
> I think, a possible solution is to define a macro which expands to "namespace {"
> during normal build and expands to nothing in some sort of "debug build" (for
> example, when ENABLE_CHECKING is defined).
I'm wary of it being easy to write code that works with it defined one
way but not the other.
Trev
>
> --
> Regards,
> Mikhail Maltsev