C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: typedef legal?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Thomas Maeder
Guest





PostPosted: Wed Sep 17, 2003 11:48 am    Post subject: Re: typedef legal? Reply with quote



André Pönitz <poenitz (AT) gmx (DOT) net> writes:

Quote:
Is das folgende legal?

#include <list

class Foo;

typedef std::list
class Foo {};

int main()
{
FooList dummy;
}


Beachte das 'typedef' _vor_ der Definition von class Foo.

Nein.

17.4.3.6 sagt, "the effects are undefined [...] if an incomplete type is used
as a template argument when instantiating a template component." Gemeint ist
eine Template-Komponente der Standardbibliothek.

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Christoph Rabel
Guest





PostPosted: Wed Sep 17, 2003 12:04 pm    Post subject: Re: typedef legal? Reply with quote



Thomas Maeder wrote:
Quote:
17.4.3.6 sagt, "the effects are undefined [...] if an incomplete type is used
as a template argument when instantiating a template component." Gemeint ist
eine Template-Komponente der Standardbibliothek.

Durch das typedef wird aber IMHO das template nicht instantiiert. Daher
glaube ich nicht, das der Paragraph hier greift.

Man kann das ganze weiter reduzieren, denke ich:

class Foo;
typedef Foo X;

class Foo {}

int main() {
X x;
}

Wenn obiges legal ist, so dürfte auch das Beispiel von André legal sein.
Ich hab mal kurz die Definition von typedef überflogen, mir ist aber
nichts aufgefallen, das hier relevant ist.

comeau akzeptiert es, also ist es wahrscheinlich legal.

mfg

Christoph

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Christoph Rabel
Guest





PostPosted: Wed Sep 17, 2003 12:24 pm    Post subject: Re: typedef legal? Reply with quote



Christoph Rabel wrote:
Quote:
Man kann das ganze weiter reduzieren, denke ich:

class Foo;
typedef Foo X;

class Foo {}

int main() {
X x;
}

Wenn obiges legal ist, so dürfte auch das Beispiel von André legal sein.
Ich hab mal kurz die Definition von typedef überflogen, mir ist aber
nichts aufgefallen, das hier relevant ist.

Im C Standard konnte ich eine Passage(Fussnote 109) finden, die ein
typedef auf einen incomplete Type explizit erlaubt.

Im C++ Standard, 3.9.7 wird ein Beispiel mit einem incomplete Array
gebracht.

Beim Beispiel zu 14.3.1 steht "[Note: a template type argument may be an
incomplete type (3.9). ]"

Ich schliesse aus diesen zwei Passagen, das der Code von André legal ist.

mfg

Christoph

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Stefan Reuther
Guest





PostPosted: Wed Sep 17, 2003 12:31 pm    Post subject: Re: typedef legal? Reply with quote

Hallo,

Christoph Rabel <odie (AT) hal9000 (DOT) vc-graz.ac.at> wrote:
[schnippeldi]
Quote:
Im C Standard konnte ich eine Passage(Fussnote 109) finden, die ein
typedef auf einen incomplete Type explizit erlaubt.

Im C++ Standard, 3.9.7 wird ein Beispiel mit einem incomplete Array
gebracht.

Beim Beispiel zu 14.3.1 steht "[Note: a template type argument may be an
incomplete type (3.9). ]"

Ich schliesse aus diesen zwei Passagen, das der Code von André legal ist.

Es ist eine legale Verwendung der Programmiersprache C++.
Templates dürfen mit unvollständigen Typen instanziiert werden.

Es ist aber keine legale Verwendung der Standardbibliothek. Die
STL-Container dürfen nur mit vollständigen Typen instanziiert
werden.


Stefan

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Markus Schaaf
Guest





PostPosted: Wed Sep 17, 2003 12:50 pm    Post subject: Re: typedef legal? Reply with quote

"Stefan Reuther" <sr21 (AT) inf (DOT) tu-dresden.de> schrieb:

Quote:
Es ist aber keine legale Verwendung der Standardbibliothek. Die
STL-Container dürfen nur mit vollständigen Typen instanziiert
werden.

Das invalidiert jedoch nicht seinen ersten Beitrag, wo er richtigerweise
darauf hinweist, daß ein »typedef« keine Instantiation darstellt. Eine
(implizite) Instantiation findet u.a. immer dann statt, wenn ein
"completely-defined object type" benötigt wird, z.B. hier:

struct foo : std::vector< bar > { /* ... */ );

Jedoch nicht hier:

std::vector< bar > * baz;

Und nicht hier:

typedef std::vector< bar > blah;

MfG

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.