This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR 29365 - unnecessary warnings for anonymous namespace


On 4/12/07, Mark Mitchell <mark@codesourcery.com> wrote:
Seongbae Park wrote:

> gcc/ChangeLog:
> 2007-04-04  Seongbae Park <seongbae.park@gmail.com>
>
>        PR c++/29365
>
>        * cp/decl2.c (constrain_class_visiblity):
>        Extra checking for anonymous namespace used in the main input file.

I don't understand what's going on here.  Can you explain in more detail
why you're suggesting this change?

Thanks,

Thanks for looking at my patch. Here's what the patch is about:


foo.C from PR29365:

class foo {
	class bar;
};

/// Header ends here

namespace {
	class gazonk { };
}

class foo::bar : public gazonk { };

and compiling this gives you the warning at "public gaznok" line
because gaznok is in the anonymous namespace.

However, this pattern (of using anonymous namespace
within .C/.cc file to avoid name collision) is quite common,
and the goal of such pattern is to make sure
certain types are not visible outside the .C/.cc file
(but still is available for other methods within the .C file)
- somewhat like "file static" variables/functions but for types.
Such usage doesn't cause any correctness problem,
as long as there's only one object file
corresponding to a single .C/.cc file.

My patch tries to avoid giving warning for cases
where anonymous namespace was defined within the current main input file
(i.e. .C or .cc files).
The only false negative of my patch is when a program
has multiple object files coming from a single source file.
I believe that's rare enough not to warrant another compiler flag
but I wouldn't mind adding a flag to control this behavior.
--
#pragma ident "Seongbae Park, compiler, http://seongbae.blogspot.com";


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]