This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Is that code valid ?
Lassi A. Tuura wrote:
>
> 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:
[--snip--]
I stand corrected and I thank you for your explaination.
I've checked it and I've noticed that the use of Class::Class(arg0) can
only be to construct a temporary. It is specified that what is on the
left
of the '(' can only be a simple-type-identifier:
simple-type-specifier:
::opt nested-name-specifieropt type-name
char
etc.
And the last Class in this context is obviously a type-name:
type-name:
class-name
enum-name
typedef-name
Having said this, I do not understand why the standard explicitely
says that the constructor does not have a name, for instance in:
12.1 Constructors [class.ctor]
2 A constructor is used to initialize objects of its class type.
Because constructors do not have names, they are never found during
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
name lookup; however an explicit type conversion using the functional
^^^^^^^^^^^^
notation (_expr.type.conv_) will cause a constructor to be called to
initialize an object. [Note: for initialization of objects of class
type see _class.init_. ]
So the question is now: Why is there such a requirement? I hope we are
not missing something obvious.
> 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?
I am not sure but I think it is ok. For reference here's the important
descriptions:
9.3 Member functions [class.mfct]
2 A member function may be defined (_dcl.fct.def_) in its class defini-
tion, in which case it is an inline member function (_dcl.fct.spec_),
or it may be defined outside of its class definition if it has already
been declared but not defined in its class definition. A member func-
^^^^^^^^^^^^^^
tion definition that appears outside of the class definition shall
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
appear in a namespace scope enclosing the class definition. Except
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
for member function definitions that appear outside of a class defini-
tion, and except for explicit specializations of template member func-
tions (_temp.spec_) appearing outside of the class definition, a mem-
ber function shall not be redeclared.
5 If the definition of a member function is lexically outside its class
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
definition, the member function name shall be qualified by its class
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
name using the :: operator.
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since the definition of the constructor _is_ a member function, the
name has to be Class::Class(). Since the definition has to be in the
namescope enclosing the class definition, putting a namespace in front
of this would not make sense. If
Class::Class::Class() {}
is legal is however not so clear, but I agree. Since this is outside
the class' namespace and the class-name has put in the namespace's
scope, I would assume that
Class::Class::Class() {}
^
at this point, we are in the class' name scope. Also, since the class
name is also put into the scope of the class itself, the next
'Class::' is a scope resolution to itself and in the end specifying
the constructor.
But is that really what is intended with "shall be qualified by its
class
name using the :: operator" in 9.3.5?
If anyone have access to the final standard I'd appreciate if anyone
can comment on this. Has there been changes?
PKE.