This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Is that code valid ?
- To: Pal Engstad <engstad at hunt dot inmet dot com>
- Subject: Re: Is that code valid ?
- From: "Lassi A. Tuura" <Lassi dot Tuura at cern dot ch>
- Date: Tue, 25 Nov 1997 19:59:11 +0100
- CC: egcs at cygnus dot com
- Organization: CERN, European Laboratory for Particle Physics
- References: <347A6CE0.82CCAA81@hunt.inmet.com>
Pal Engstad wrote:
>
> Lassi Tuura wrote:
> > Olivier Galibert wrote:
> > > kftabdlg.cpp:549: parse error before `;'
> > > Line 549 is "return(QDate::QDate());"
> > > Changing that line to "return QDate();" works perfectly though.
> >
> > That is valid code, since the class name is found in its own scope.
> > Hence, one should be able to repeat `QDate::' arbitrary many times. > In
> > other words, assuming the proper declarations, the following is
> > perfectly valid, albeit weird code:
> >
> > return (QDate::QDate::QDate::QDate ());
>
> Please, do not write things out of thin air in this forum.
> Note that the constructor of a class has no name:
I believe you are confusing two things. The name above is a
qualified-id, where the nested-name-specifier nominates a class. Hence,
the following lookup rules apply:
----
3.4.3.1 Class members [class.qual]
1 If the nested-name-specifier of a qualified-id nominates a class, the
name specified after the nested-name-specifier is looked up in the
scope of the class (_class.member.lookup_). The name shall represent
one or more members of that class or of one of its base classes
(_class.derived_).
----
The class name is also found in the scope of the class itself:
----
9 Classes [class]
...
2 A class-name is inserted into the scope in which it is declared imme-
diately after the class-name is seen. The class-name is also inserted
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
into the scope of the class itself. For purposes of access checking,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the inserted class name is treated as if it were a public member name.
A class-specifier is commonly referred to as a class definition. A
class is considered defined after the closing brace of its class-spec-
ifier has been seen even though its member functions are in general
not yet defined.
----
Hence, the qualified-id `QDate::QDate::QDate::QDate' should be treated
as `QDate' in a the above context. Definition of a function with that
name would be a different thing. I am not sure it would be valid as a
constructor name---in my reading it should be (the first two `QDate's
would just be ignored). In my interpretation it should, however, be
valid as a type name in a context where a type name is allowed. Anybody
interpret the standard differently?
Cheers,
//lat
--
Lassi.Tuura@cern.ch There's no sunrise without a night