Topic: Support for INHERITED keyword and related problem
Author: Esmond Pitt <pitte@cpgen.cpg.com.au>
Date: 1997/11/26 Raw View
This is a multi-part message in MIME format.
--------------94702C7D3A3079148B178FF1
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Demian Johnston wrote:
> I have encountered a problem with this
> method with 3 compilers (Digital C++, Visual C++, and GCC) . The
> compilers are allowing the code below to compile and run. My belief is
> that the following code should not compile
The typedef doesn't introduce a new type, it just introduces a new name
for an existing type; the new name doesn't have protection of its own,
it has the protection of the existing type, i.e. public (because you
said class Middle : public Base).
Also, it is not correct to speak of private definitions being 'out of
scope'. They aren't: the names can still be seen, they just can't be
accessed.
--------------94702C7D3A3079148B178FF1
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Esmond Pitt
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Esmond Pitt
n: Pitt;Esmond
org: CP Telemedia Software Laboratories
adr: 1/493 St Kilda Rd;;;Melbourne;Victoria;3004;Australia
email;internet: pitte@cpgen.cpg.anti-spam.com.au
title: Consultant
tel;work: 61 3 9243 2285
tel;fax: 61 3 9243 2233
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
end: vcard
--------------94702C7D3A3079148B178FF1--
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/11/27 Raw View
[Moderator's note: followups redirected to comp.std.c++ only. -mod (fjh).]
Esmond Pitt wrote:
> Demian Johnston wrote:
> > I have encountered a problem with this
> > method with 3 compilers (Digital C++, Visual C++, and GCC) . The
> > compilers are allowing the code below to compile and run. My belief is
> > that the following code should not compile
>
> The typedef doesn't introduce a new type, it just introduces a new name
> for an existing type;
Correct. A typedef defines a typename, not a type and that's why
it's spelled typedef (if it was logically called typename_def people
would understand it easilly: that wouldn't be C++).
> the new name doesn't have protection of its own,
Simply impossible. You can't have a member name without
protection in C++. (In your opinion, what could possibly
be the protection of 'private: typedef int my_int;' ?)
friend declarations don't care in which protection they
are defined (private, protected or public) but they don't
introduce members names.
> Also, it is not correct to speak of private definitions being 'out of
> scope'. They aren't: the names can still be seen, they just can't be
> accessed.
That's right.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/11/27 Raw View
Esmond Pitt <pitte@cpgen.cpg.com.au> writes:
>Demian Johnston wrote:
>> I have encountered a problem with this
>> method with 3 compilers (Digital C++, Visual C++, and GCC) . The
>> compilers are allowing the code below to compile and run. My belief is
>> that the following code should not compile
>
>The typedef doesn't introduce a new type, it just introduces a new name
>for an existing type; the new name doesn't have protection of its own,
>it has the protection of the existing type, i.e. public (because you
>said class Middle : public Base).
This is wrong; it is specifically denied by 11 [class.access] paragraph 3
in the C++ draft standard. Access control applies uniformly to all names,
including typedef names.
--
Fergus Henderson <fjh@cs.mu.oz.au> WWW: <http://www.cs.mu.oz.au/~fjh>
Note: due to some buggy software and a (probably accidental)
denial-of-service attack, any mail sent to me or posted to comp.std.c++
between about Tue Nov 25 20:00:00 UTC (6am Wed, local time)
and Wed Nov 26 06:00:00 UTC (4pm, local time)
may have gone into the bit-bucket. Please re-send it.
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: jensk@bbn.hp.com (Jens Kilian)
Date: 1997/11/24 Raw View
Valentin Bonnard (bonnardv@pratique.fr) wrote:
> Yes. It's surprising to see that three compilers have the same
> bug. The program is ill-formed.
Make that four compilers; Metrowerks C++ (at least the BeOS version) also
gets this wrong.
Jens.
--
mailto:jjk@acm.org phone:+49-7031-14-7698 (HP TELNET 778-7698)
http://www.bawue.de/~jjk/ fax:+49-7031-14-7351
PGP: 06 04 1C 35 7B DC 1F 26 As the air to a bird, or the sea to a fish,
0x555DA8B5 BB A2 F0 66 77 75 E1 08 so is contempt to the contemptible. [Blake]
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Demian Johnston <djohnston@factset.com>
Date: 1997/11/21 Raw View
I have seen discussion here before with regards to a proposal for an
INHERITED keyword to represent an alias for the typename of a base
class. I have also seen the work around to use class-scoped typedef s
to simulate this behavior. I have encountered a problem with this
method with 3 compilers (Digital C++, Visual C++, and GCC) . The
compilers are allowing the code below to compile and run. My belief is
that the following code should not compile, explanation after code:
#include <iostream.h>
class Base {
public:
Base() {}
virtual void go() { cout << "Base Fun" << endl; }
};
class Middle : public Base{
private:
typedef Base inherited;
public:
Middle() {}
virtual void go() { cout << "Middle Fun" << endl; inherited::go(); }
};
class Derived : public Middle{
public:
Derived() {}
virtual void go() { cout << "Derived Fun" << endl; inherited::go(); }
};
main() {
Derived x;
x.go();
return 0;
}
The compiler should error on the defintion for Derived::go(). The
typename inherited should be out of scope. The ARM Section 11.2c (Per
Class Protection) states that
"Another important aspect of the C++ protection system is that it
applies uniformly to all names. There are no special rules for data
member names, function member names, type names, or any other names."
Clearly the "typedef Base inherited;" line is scope private to the
Middle Base Class, yet all three compilers resolve the inherited
typename in Derived::go() to be Base.
Am I missing something here?
Are all these compilers buggy in their implementations?
Does the newly adopted standard diverge from the ARM in this
respect?
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/11/21 Raw View
[Followups directed to comp.std.c++]
Demian Johnston <djohnston@factset.com> writes:
>class Middle : public Base{
>private:
> typedef Base inherited;
[...]
>};
>
>class Derived : public Middle{
[...]
> virtual void go() { cout << "Derived Fun" << endl; inherited::go();
}
>};
[...]
>The compiler should error on the defintion for Derived::go(). The
>typename inherited should be out of scope.
Not out of scope, but inaccessible.
(Scope and access are two different things.)
> Clearly the "typedef Base inherited;" line is scope private to the
>Middle Base Class, yet all three compilers resolve the inherited
>typename in Derived::go() to be Base.
The code is ill-formed; if the compilers accept it without any
diagnostics, then they are not conforming.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the
pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S.
Garp.
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/11/21 Raw View
[Followup set to comp.std.c++]
Demian Johnston wrote:
> class Middle : public Base{
> private:
> typedef Base inherited;
> class Derived : public Middle{
>
> public:
> Derived() {}
> virtual void go() { cout << "Derived Fun" << endl; inherited::go(); }
> };
> The compiler should error on the defintion for Derived::go().
Yes. It's surprising to see that three compilers have the same
bug. The program is ill-formed.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]