[cfe-dev] Is this a clang bug? "Foo::Foo::bar"

Serge Pavlov sepavloff at gmail.com
Tue Jul 16 06:53:47 PDT 2013


This is "injected-class-name", see C++ standard (clause 9p2):

A class-name is inserted into the scope in which it is declared immediately
after the class-name is seen.
The class-name is also inserted into the scope of the class itself; this is
known as the injected-class-name.

--Serge


2013/7/16 Jonathan Sauer <jonathan.sauer at gmx.de>

> Hello,
>
> the following program compiles with clang r186311, and I'm not sure if
> this is a bug
> or correct behavior:
>
> struct Foo {
>     void bar();
> };
>
>
> void Foo::Foo::Foo::Foo::Foo::Foo::bar()
> {
> }
>
>
> According to §3.3.7p1 bullet 5 (basic.scope.class), the potential scope of
> a class
> includes "the regions defined by its member definitions [...] including
> the member
> function body and any portion of the declarator part of such definitions
> which follows
> the declarator-id", and §3.4.3.1p1 (class.qual) states that "A class
> member can be
> referred to using a qualified-id at any point in its potential scope"
> while "the name
> [specified after the nested-name-specifier] shall represent one or more
> members of
> that class or of one of its base classes."
>
> However in the code above the member function "bar" is referred to using a
> qualified-id
> in its declarator-id, which is not part of the class' potential scope, and
> "Foo" isn't
> a base class of itself, so this shouldn't be allowed.
>
> Still, I'm not sure if I got all the subtleties of C++'s name lookup rules
> right, so
> I'd like to make sure if this is a bug in clang or merely the somewhat
> amusing result
> of the way names in C++ can be specified.
>
>
> With many thanks in advance,
> Jonathan
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>



-- 
Thanks,
--Serge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130716/13f1caa6/attachment.html>


More information about the cfe-dev mailing list