On 2018-01-16 14:45, Andrew Pinski wrote: On Mon, Jan 15, 2018 at 10:35 PM, chenzhelu <chenz...@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. Thanks for suggestion! Yes, this test code is intent to create local classes with same name, for a small project, it's easy to find out this error, consider a big project... The root cause is, it's possible that two local classes with same name in a namespace, (or the default anonymous namespace), I know that it violate with ODR, however, the point is, it seems that compiler is somehow not consistent in the Compile and Link phase, that's what I confused of. If you want a truly local class, then use anonymous namespaces which is designed to fix this issue. This will rely on human to keep local class name unique within a namspace, or the default anonymous namespace. consider a project with hundreds of files, as a precise software, I think it'd better not allow this undefined hehavior open, whether the compile better give some warning/error on this name conflicts, or link with the "nearest" local class ? Thanks, Andrew