This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug 2



>>>>> "Breymann" == Breymann  <Breymann@t-online.de> writes:

    Breymann> A few days ago I fetched egcs-1.0 and found another
    Breymann> little bug (see testcase below)

    Breymann> Best regards!  Uli

    Breymann> **************** test case ****************************
    Breymann> // simple, but not working example for int-vector
    Breymann> container // because it is not possible to initialize
    Breymann> container // in the second case below.  #include<vector>
    Breymann> #include<iostream.h>

    Breymann> // using namespace std;

    Breymann> int main() { // OK: an int vector of 10 elements
    Breymann> vector<int> intV(10);
 
    Breymann>     // ERROR: an int vector of 10 elements initialized
    Breymann> with 1 // must be possible according to C++ FDIS, see
    Breymann> example + hints on p. 23-6 vector<int> intV1(10, 1); //
    Breymann> error!

This code is not legal.  There are only four constructors given by
the standard:

vector(const Allocator& = Allocator());
template <class InputIterator>
vector(InputIterator, InputIterator, const Allocator& = Allocator());
vector(const vector<T, Allocator>&);
vector(size_type, const T&, const Allocator& = Allocator());

The best match, by the rules in the stanard is for the InputIterator
version.   You can get the behavior you expect by saying:

vector<int> v((vector<int>::size_type) 10, 1);

or just

vector<int> v(10U, 1);

SGI has added a few additional constructors, but they are nonstandard,
and do not match in this case.

    Breymann>     // However, with an intermediate variable it works:
    Breymann> int thisIsTwo = 2; vector<int> intV2(10, thisIsTwo); //
    Breymann> ok now }

    Breymann> Reason: implementation supports vector<T>::vector<T>(int
    Breymann> n, const T& val); but not vector<T>::vector<T>(int n, T
    Breymann> val); (same problem with other integral types)

    Breymann> It is not possible to decide wether to take 'T' or
    Breymann> 'const T&', therefore the solution is to provide a
    Breymann> specialization vector<int>::vector<int>(int n, int val);
    Breymann> (and other integral types)



-- 
Mark Mitchell		mmitchell@usa.net
Stanford University	http://www.stanford.edu



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]