C++11 and <vector> error

C++11 and error

Imagen de Michael M.

I'm having trouble including vectors while compiling with -std=c++11. If I try to compile

#include <vector>
int main()
{
 return 0;
}

using icpc -std=c++11 vector_test.cpp, I get the following error:

/opt/local/include/gcc48/c++/bits/alloc_traits.h(555): error: invalid type for defaulted assignment operator
__allow_copy_cons& operator=(__allow_copy_cons&&) = default;

It compiles fine under gcc 4.8. Is this a problem with icpc or with my library files?

Thanks

publicaciones de 10 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Sergey Kostrov

>>...It compiles fine under gcc 4.8. Is this a problem with icpc or with my library files?

If the test case was successfully compiled with GCC version 4.8 then it is clear that there is a problem with ICPC.

Imagen de Tim Prince

I don't see any such problem with current icpc.  Perhaps OP used a version of icpc which was too old to work with g++ 4.8.

Imagen de Michael M.

I updated to the latest version of icpc when I encountered the problem; I'm currently using 13.0.3. The problem also exists using g++ 4.7 (both versions of gcc are installed via MacPorts, incidentally, and both just updated). If I switch to (MacPorts) g++ 4.5 or the Apple g++ 4.2, then that empty test code compiles fine, but if I try to declare a vector using an initializer list, it fails with the error

error: no instance of constructor "std::vector<_Tp, _Alloc>::vector [with _Tp=double, _Alloc=std::allocator<double>]" matches the argument list
argument types are: (double, double, double)
std::vector<double> testvec = {1.0, 2.0, 3.0};

Imagen de Sergey Kostrov

>>If I switch to (MacPorts) g++ 4.5 or the Apple g++ 4.2, then that empty test code compiles fine, but if I try to declare
>>a vector using an initializer list, it fails with the error
>>
>>error: no instance of constructor "std::vector<_Tp, _Alloc>::vector [with _Tp=double, _Alloc=std::allocator]"
>>matches the argument list
>>argument types are: (double, double, double)
>>std::vector testvec = {1.0, 2.0, 3.0};

Why wouldn't you upload vector header file for review?

If g++ 4.5, g++ 4.2 and icpc are failing to compile that test project you have some issue with STL headers.

Imagen de Michael M.

I hadn't attached the headers initially since they're part of gcc, gcc doesn't complain about them, and I haven't modified them. I'm attaching the vector and alloc_traits (where the complier error occurred) headers for gcc 4.8.

Adjuntos: 

AdjuntoTamaño
Descargar alloc-traits.h17.66 KB
Descargar vector.h2.66 KB
Imagen de Sergey Kostrov

This is original version ( I've bolded where the compiler fails / line 555 ):

...
// Used to delete copy constructor of unordered containers
template<>
struct __allow_copy_cons
{
__allow_copy_cons() = default;
__allow_copy_cons(const __allow_copy_cons&) = delete;
__allow_copy_cons(__allow_copy_cons&&) = default;
__allow_copy_cons& operator=(const __allow_copy_cons&) = default;
__allow_copy_cons& operator=(__allow_copy_cons&&) = default;
};
...

Could you try the following version?

...
// Used to delete copy constructor of unordered containers
template<>
struct __allow_copy_cons
{
__allow_copy_cons() = default;
__allow_copy_cons(const __allow_copy_cons&) = delete;
__allow_copy_cons(__allow_copy_cons&&) = default;
__allow_copy_cons& operator=(const __allow_copy_cons&) = default;
__allow_copy_cons& operator=(const __allow_copy_cons&&) = default;
};
...

Note: I've added const specificator.

Imagen de AmandaS (Intel)

Like Tim, I am unable to reproduce any problems compiling with your icc version as well newwer versions. Could something be awry in your environment?

Imagen de Casey

I am also unable to reproduce problems.  Running icc version 13.1.3 (gcc version 4.6.3 compatibility) on Linux.  

Imagen de qweasd q.

nvm

Inicie sesión para dejar un comentario.