On Mon, 2013-02-04 at 20:08 -0800, mmcwilli@xxxxxxx wrote: > Hello All > > I have a compilation error in a very large program. We have managed to > isolate the problem with the following test problem: > > #include <vector> > #include <iostream> > > using namespace std; > > int main() > { > double* myPointer=NULL; // no error on this line > vector<double*> myVect(1,NULL); // error on this line > return 0; > } > > Compiling this spits out the error: > > Cannot convert 'int' to 'std::vector<double*>::value_type {aka double*}' > > When I compile this on GNU gcc compiler version 4.5.1 I do not get this > error. When I compile it on GNU gcc compiler version 4.7.1 I get the > error. > > Note that this error occurs on a colleagues computer that I do not have > access to so I cannot give the exact source code and the exact error and > all the other details. > > Since the first reference to NULL works then we can conclude that NULL is > defined and it can be used to initialize pointers. However when NULL is > passed as an initialization to a std::vector container it is no longer > type compatible. > > Is this a bug in the 4.7.1 compiler or did the compiler change to conform > to some standard that does not allow vector's to initialized to NULL. > > I just want to check with you all before I submit it as a bug. Any > comments would be much appreciated! > > Thanks > Mike > Confirmed w/ GCC 4.7.2: nick@nimble ~/temp6 $ cat ./test.cpp #include <vector> #include <iostream> using namespace std; int main() { vector<double*> myVect(1,NULL); } nick@nimble ~/temp6 $ g++-4.7.2 -std=c++11 ./test.cpp In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include/g ++-v4/vector:65:0, from ./test.cpp:1: /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include/g++-v4/bits/stl_vector.h: In instantiation of 'void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_Integer, _Integer, std::__true_type) [with _Integer = int; _Tp = double*; _Alloc = std::allocator<double*>]': /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include/g ++-v4/bits/stl_vector.h:393:4: required from 'std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = int; _Tp = double*; _Alloc = std::allocator<double*>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<double*>]' ./test.cpp:8:31: required from here /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include/g ++-v4/bits/stl_vector.h:1137:4: error: invalid conversion from 'int' to 'std::vector<double*>::value_type {aka double*}' [-fpermissive] /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include/g ++-v4/bits/stl_vector.h:1179:7: error: initializing argument 2 of 'void std::vector<_Tp, _Alloc>::_M_fill_initialize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = double*; _Alloc = std::allocator<double*>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::value_type = double*]' [-fpermissive] But I see that if you use a variable or 'nullptr' it works: nick@nimble ~/temp6 $ cat ./test.cpp #include <vector> #include <iostream> using namespace std; int main() { double* myPointer=NULL; vector<double*> myVect(1,myPointer); } nick@nimble ~/temp6 $ g++-4.7.2 -std=c++11 ./test.cpp nick@nimble ~/temp6 $ nick@nimble ~/temp6 $ cat ./test.cpp #include <vector> #include <iostream> using namespace std; int main() { vector<double*> myVect(1,nullptr); } nick@nimble ~/temp6 $ g++-4.7.2 -std=c++11 ./test.cpp nick@nimble ~/temp6 $ Nick