Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A::A::A::A

0 views
Skip to first unread message

Giovanni Bajo

unread,
Oct 4, 2004, 11:16:04 AM10/4/04
to
Is this code really valid?

struct A {
void foo() {}
};

void bar() {
A a;
a.A::A::A::A::A::A::foo();
}

--
Giovanni Bajo

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Alberto Barbati

unread,
Oct 5, 2004, 12:37:26 AM10/5/04
to
Giovanni Bajo wrote:
> Is this code really valid?
>
> struct A {
> void foo() {}
> };
>
> void bar() {
> A a;
> a.A::A::A::A::A::A::foo();
> }
>

AFAIK, the syntax A::whatever refers to a member of class A. Although
the name A is injected in the scope of A, it's not a member of A, so
writing A::A is illegal. Notice that it doesn't even refer to the class
constructor, because constructors have no name.

That said, applying ::A a second or more times won't improve the
situation, so the answer is definitely no.

Alberto

Gabriel Dos Reis

unread,
Oct 5, 2004, 12:37:36 AM10/5/04
to
no...@sorry.com ("Giovanni Bajo") writes:

| Is this code really valid?
|
| struct A {
| void foo() {}
| };
|
| void bar() {
| A a;
| a.A::A::A::A::A::A::foo();

No.

A::A designates the constructor for class A. GCC is defective in not
implementing the rules. I've filled a PR a long time ago.

--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112

Bob Hairgrove

unread,
Oct 5, 2004, 11:27:12 AM10/5/04
to
On Mon, 4 Oct 2004 15:16:04 GMT, no...@sorry.com ("Giovanni Bajo")
wrote:

>Is this code really valid?
>
>struct A {
> void foo() {}
>};
>
>void bar() {
> A a;
> a.A::A::A::A::A::A::foo();
>}

Why shouldn't it be?

--
Bob Hairgrove
NoSpam...@Home.com

Ganesh

unread,
Oct 5, 2004, 11:27:47 AM10/5/04
to
> Is this code really valid?
> a.A::A::A::A::A::A::foo();
>From 3.4.5[4], "If the name is found only in the scope of the class of
the object expression, the name shall refer to a class-name". Since
the qualifying "class-name-or-namespace-name" is not a class-name, it
is not valid.

However, in the compilers I checked the code with, g++ 3.2, aCC 3.55,
comeau online, it passed. In VC++, it gives a misleading error "error
2039: '__ctor' : is not a member of 'A'"; might be that the vc++
compiler confuses series of A::A as constructors and tries to
interpret it.

-Ganesh

news

unread,
Oct 5, 2004, 11:28:02 AM10/5/04
to

"Gabriel Dos Reis" <g...@cs.tamu.edu> wrote in message news:m3sm8tv...@merlin.cs.tamu.edu...

> A::A designates the constructor for class A. GCC is defective in not
> implementing the rules. I've filled a PR a long time ago.

Only in the special case of defining that function. Since the constructors
don't "have names" you can't do
a.A::A()
or even
a.A();

Vladimir Marko

unread,
Oct 5, 2004, 12:34:18 PM10/5/04
to
no...@sorry.com ("Giovanni Bajo") wrote in message news:<mQb8d.23473$N45.6...@twister2.libero.it>...

> Is this code really valid?
>
> struct A {
> void foo() {}
> };
>
> void bar() {
> A a;
> a.A::A::A::A::A::A::foo();
> }

I believe it is valid. See thread
``How to avoid / check typing mistake ":" instead of "::" , with C++ ?''
from April 2004.

Regards,

Vladimir Marko

Gabriel Dos Reis

unread,
Oct 5, 2004, 1:26:02 PM10/5/04
to
Alberto...@libero.it (Alberto Barbati) writes:

| Giovanni Bajo wrote:
| > Is this code really valid?
| > struct A {
| > void foo() {}
| > };
| > void bar() {
| > A a;
| > a.A::A::A::A::A::A::foo();
| > }
| >
|
| AFAIK, the syntax A::whatever refers to a member of class A. Although
| the name A is injected in the scope of A, it's not a member of A, so
| writing A::A is illegal.

That is wrong.

A::A is valid. It designates the constructor.

| Notice that it doesn't even refer to the
| class constructor, because constructors have no name.

That is not true. The standard specifically says that it designates
the constructor.


--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112

---

Gabriel Dos Reis

unread,
Oct 5, 2004, 3:23:36 PM10/5/04
to
inv...@bigfoot.com (Bob Hairgrove) writes:

| On Mon, 4 Oct 2004 15:16:04 GMT, no...@sorry.com ("Giovanni Bajo")
| wrote:
|
| >Is this code really valid?
| >
| >struct A {
| > void foo() {}
| >};
| >
| >void bar() {
| > A a;
| > a.A::A::A::A::A::A::foo();
| >}
|
| Why shouldn't it be?

Why should it be?

--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112

---

Alberto Barbati

unread,
Oct 5, 2004, 6:18:48 PM10/5/04
to
Gabriel Dos Reis wrote:
> Alberto...@libero.it (Alberto Barbati) writes:
>
> | Giovanni Bajo wrote:
> | > Is this code really valid?
> | > struct A {
> | > void foo() {}
> | > };
> | > void bar() {
> | > A a;
> | > a.A::A::A::A::A::A::foo();
> | > }
> | >
> |
> | AFAIK, the syntax A::whatever refers to a member of class A. Although
> | the name A is injected in the scope of A, it's not a member of A, so
> | writing A::A is illegal.
>
> That is wrong.
>
> A::A is valid. It designates the constructor.
>
> | Notice that it doesn't even refer to the
> | class constructor, because constructors have no name.
>
> That is not true. The standard specifically says that it designates
> the constructor.
>

Of course I may have been mistaken, but I couldn't find where the
standard says that. Could you enlighten me, please?

Alberto

johnchx

unread,
Oct 5, 2004, 7:12:46 PM10/5/04
to
g...@cs.tamu.edu (Gabriel Dos Reis) wrote
> Alberto...@libero.it (Alberto Barbati) writes:
>
> A::A is valid. It designates the constructor.
>
> | Notice that it doesn't even refer to the
> | class constructor, because constructors have no name.
>

Yes...the trick is to notice that A::A is not actually a name. A name
is the use of an identifier (3/4) and an identifier may not include
the ":" character. IIRC, A::A is a qualified-id (A.4). And yes, it
designates the ctor.

Gabriel Dos Reis

unread,
Oct 5, 2004, 10:17:28 PM10/5/04
to

| "Gabriel Dos Reis" <g...@cs.tamu.edu> wrote in message news:m3sm8tv...@merlin.cs.tamu.edu...
|
| > A::A designates the constructor for class A. GCC is defective in not
| > implementing the rules. I've filled a PR a long time ago.
|
| Only in the special case of defining that function.

No, the meaning of A::A is independent of whether you're defining the
constructor. The meaning is what it is; only the *use* is valid in
context of constructor definition out of class definition.

For example, the following is invalid

A::A a;

Applying you reasoning, it would be valid; alas it is not. See 3.4.3.1.

--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112

---

Gabriel Dos Reis

unread,
Oct 5, 2004, 11:48:58 PM10/5/04
to
Alberto...@libero.it (Alberto Barbati) writes:

[...]

| > | the name A is injected in the scope of A, it's not a member of A, so
| > | writing A::A is illegal.
| > That is wrong.
| > A::A is valid. It designates the constructor.
| > | Notice that it doesn't even refer to the
| > | class constructor, because constructors have no name.
| > That is not true. The standard specifically says that it designates
| > the constructor.
| >
|
| Of course I may have been mistaken, but I couldn't find where the
| standard says that. Could you enlighten me, please?

3.4.3.1/1a

If the nested-name-specifier nominates a class C, and the name
specified after the nested-name-specifier, when looked up in C, is
the injected-class-name of C (clause 9), the name is instead
considered to name the constructor of class C. Such a constructor
name shall be used only in the declarator-id of a constructor
definition that appears outside of the class definition. [Example:

struct A { A(); };
struct B: public A { B(); };

A::A() { }
B::B() { }

B::A ba; // object of type A
A::A a; // error A::A is a not a type name

--end example]

So, if a constructor does not have a name, how can "the name is
instead considered to name the constructor"? That is a rhetorical
question :-)

--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112

---

Gabriel Dos Reis

unread,
Oct 5, 2004, 11:49:11 PM10/5/04
to
sgga...@gmail.com (Ganesh) writes:

| > Is this code really valid?
| > a.A::A::A::A::A::A::foo();
| >From 3.4.5[4], "If the name is found only in the scope of the class of
| the object expression, the name shall refer to a class-name". Since
| the qualifying "class-name-or-namespace-name" is not a class-name, it
| is not valid.
|
| However, in the compilers I checked the code with, g++ 3.2, aCC 3.55,
| comeau online, it passed. In VC++, it gives a misleading error "error
| 2039: '__ctor' : is not a member of 'A'"; might be that the vc++
| compiler confuses series of A::A as constructors and tries to
| interpret it.

I believe VC++ correctly rejects the code because it implements DR
#whatever, that went into the TC1 as 3.4.3.1/1a.

G++ does not implement that rule.

--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112

---

Alberto Barbati

unread,
Oct 6, 2004, 1:23:23 PM10/6/04
to

So what I said wasn't completely wrong as you stated. I wrote "writing
A::A is illegal" and *in that context* (which wasn't "in the

declarator-id of a constructor definition that appears outside of the

class definition") it was in fact illegal. ;-)

> So, if a constructor does not have a name, how can "the name is
> instead considered to name the constructor"? That is a rhetorical
> question :-)

:-D

Alberto

ka...@gabi-soft.fr

unread,
Oct 6, 2004, 1:23:34 PM10/6/04
to
g...@cs.tamu.edu (Gabriel Dos Reis) wrote in message
news:<m3ekkcp...@merlin.cs.tamu.edu>...

> So, if a constructor does not have a name, how can "the name is
> instead considered to name the constructor"? That is a rhetorical
> question :-)

Not so rhetorical. To name has several meanings in English. One of
them is to designate, which doesn't imply that what is designated
actually has a name. (The example in the American Heritage Dictionary
is "to name the time for our meeting" -- certainly the time named
doesn't have a name.) That would seem to be the meaning here.
Otherwise, why the "instead", which suggests that the name actually
names something else (perhaps the injected class name).

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

0 new messages