This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re:Re: Local class name conflict
- From: chenzhelu <chenzero at netease dot com>
- To: "Andrew Pinski" <pinskia at gmail dot com>
- Cc: gcc <gcc at gcc dot gnu dot org>
- Date: Tue, 16 Jan 2018 17:08:32 +0800 (CST)
- Subject: Re:Re: Local class name conflict
- Authentication-results: sourceware.org; auth=none
- References: <78c6c19f.5.160fdae42c8.Coremail.chenzero@netease.com> <CA+=Sn1kgG=ETom7Cs5yTZ-2MxbbaauJ+hZwFC-K82sFXJLZ0nw@mail.gmail.com>
On 2018-01-16 14:45, Andrew Pinski wrote:
> On Mon, Jan 15, 2018 at 10:35 PM, chenzhelu <chenzero@netease.com> wrote:
>> Hello all,
>> I encountered a problem on "local class name conflict",
>> I searched on net and found that years ago, some people also encoutered this kind of problem.
>
> The correct name for this is One Definition Rule (or ODR for short).
> Basically a violation of this rule causes the code to be invalid (with
> no diagnostic required; therefor undefined code). If you use LTO, GCC
> sometimes will warn about this violation.
>
> If you want a truly local class, then use anonymous namespaces which
> is designed to fix this issue.
After I tried the anonymous namespace, it really solve this!
namspace {
class LocalClassX {
.....
};
}
In before, I took for granted that the default "empty namespace" is same with
"anonymous namespace", they are different.
C++ is really complex, I never use anonymouse namespace bofore.
Thanks a lot!