public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <oliva@dcc.unicamp.br>
To: "Pinwu Xu" <pinwu_xu@hotmail.com>
Cc: egcs@cygnus.com
Subject: Re: egcs-1.0.2 STL problem?
Date: Wed, 25 Mar 1998 17:22:00 -0000	[thread overview]
Message-ID: <orsoo6sg5n.fsf@zecarneiro.lsd.dcc.unicamp.br> (raw)
In-Reply-To: <19980324135940.29107.qmail@hotmail.com>

Pinwu Xu writes:

>     vector<int> a_i_vec(5, 0);  

This is a common STL gotcha.  Standard template class vector provides
several different constructors, and two of them are viable:

      explicit vector(size_type n, const T& value);
      template <class InputIterator>
        vector(InputIterator first, InputIterator last);

simplyfing for the case of vector<int> and instantiating the template
constructor for InputIterator=int, we get:

      vector(size_type, const int&);
      vector(int, int);

Since size_type is size_t, which is unsigned int, the second
constructor is preferred over the first one, since it is an exact
match.

>     int dummy_int(0);
>     vector<int> a_i_vec(5, dummy_int);

> it works.

egcs's STL is broken in this respect, because it defines two
non-standard constructors:

  vector(int n, const T& value) { fill_initialize(n, value); }
  vector(long n, const T& value) { fill_initialize(n, value); }

Now, since dummy_int is an lvalue (0 was not, so these constructors
were not selected because they would involve the creation of
temporaries), the first of these two constructors is selected as an
exact match.  But there constructors should not be defined, since they 
break ANSI/ISO C++ compliance.

Unfortunately, stl_vector is imported as-is from the SGI
implementation of STL.  Would someone who is in touch with SGI
developers please forward this message to them?

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil


  parent reply	other threads:[~1998-03-25 17:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-03-24 13:00 Pinwu Xu
1998-03-25 14:00 ` Ross Smith
1998-03-25 14:18 ` Joe Buck
1998-03-25 17:22 ` Alexandre Oliva [this message]
1998-03-25 23:43 ` Mark Mitchell
1998-03-25 23:56 ` Branko Cibej
     [not found] ` <orsoo6sg5n.fsf.cygnus.egcs@zecarneiro.lsd.dcc.unicamp.br>
1998-04-10 20:10   ` Nathan Myers
1998-03-25 17:22 Pinwu Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=orsoo6sg5n.fsf@zecarneiro.lsd.dcc.unicamp.br \
    --to=oliva@dcc.unicamp.br \
    --cc=egcs@cygnus.com \
    --cc=pinwu_xu@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).