bug 2

Breymann Breymann@t-online.de
Sat Dec 20 04:21:00 GMT 1997


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

Best regards!   Uli

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

// using namespace std;

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

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

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

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






More information about the Gcc-bugs mailing list