Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » C++11: Vector is missing copy contructor/assignment operator (Compiling for C++11 with gcc 4.8 or newer fails)
C++11: Vector is missing copy contructor/assignment operator [message #43173] Wed, 28 May 2014 10:24 Go to next message
steffen is currently offline  steffen
Messages: 38
Registered: May 2007
Location: Denmark
Member

Hi,

OS: Ubuntu 14.04
uppsrc revision 7400
gcc version 4.8.2

It seems that from gcc-4.8, the Vector class gives a compiler error when building with the -std=c++0x flag.
According to C++11 specs, it is a valid error, since it should not implicitly make copy constructors for moveable objects.

Example:
CONSOLE_APP_MAIN
{
	Vector<int> v;
	Vector<int> r = v;

	VectorMap<int,String> vm;
	VectorMap<int,String> rvm = vm;
	Vector<String> rv = vm.GetValues();
}

Compiler gives these errors:
/home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp: In function 'void ConsoleMainFn_()':
/home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp:10:18: error: use of deleted function 'constexpr Upp::Vector<int>::Vector(const Upp::Vector<int>&)'
  Vector<int> r = v;
                  ^
In file included from /home/steffen/Projects/upp/uppsrc/Core/Core.h:282:0,
                 from /home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp:1:
/home/steffen/Projects/upp/uppsrc/Core/Vcont.h:13:7: note: 'constexpr Upp::Vector<int>::Vector(const Upp::Vector<int>&)' is implicitly declared as deleted because 'Upp::Vector<int>' declares a move constructor or move assignment operator
 class Vector : public MoveableAndDeepCopyOption< Vector<T> > {
       ^
/home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp:13:30: error: use of deleted function 'Upp::VectorMap<int, Upp::String>::VectorMap(const Upp::VectorMap<int, Upp::String>&)'
  VectorMap<int,String> rvm = vm;
                              ^
In file included from /home/steffen/Projects/upp/uppsrc/Core/Core.h:285:0,
                 from /home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp:1:
/home/steffen/Projects/upp/uppsrc/Core/Map.h:145:7: note: 'Upp::VectorMap<int, Upp::String>::VectorMap(const Upp::VectorMap<int, Upp::String>&)' is implicitly deleted because the default definition would be ill-formed:
 class VectorMap : public MoveableAndDeepCopyOption<VectorMap<K, T, HashFn> >,
       ^
/home/steffen/Projects/upp/uppsrc/Core/Map.h:145:7: error: use of deleted function 'Upp::AMap<int, Upp::String, Upp::Vector<Upp::String>, Upp::StdHash<int> >::AMap(const Upp::AMap<int, Upp::String, Upp::Vector<Upp::String>, Upp::StdHash<int> >&)'
/home/steffen/Projects/upp/uppsrc/Core/Map.h:2:7: note: 'Upp::AMap<int, Upp::String, Upp::Vector<Upp::String>, Upp::StdHash<int> >::AMap(const Upp::AMap<int, Upp::String, Upp::Vector<Upp::String>, Upp::StdHash<int> >&)' is implicitly deleted because the default definition would be ill-formed:
 class AMap {
       ^
/home/steffen/Projects/upp/uppsrc/Core/Map.h:2:7: error: use of deleted function 'Upp::Index<int>::Index(const Upp::Index<int>&)'
In file included from /home/steffen/Projects/upp/uppsrc/Core/Core.h:284:0,
                 from /home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp:1:
/home/steffen/Projects/upp/uppsrc/Core/Index.h:210:7: note: 'Upp::Index<int>::Index(const Upp::Index<int>&)' is implicitly declared as deleted because 'Upp::Index<int>' declares a move constructor or move assignment operator
 class Index : MoveableAndDeepCopyOption< Index<T, HashFn > >,
       ^
In file included from /home/steffen/Projects/upp/uppsrc/Core/Core.h:285:0,
                 from /home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp:1:
/home/steffen/Projects/upp/uppsrc/Core/Map.h:2:7: error: use of deleted function 'constexpr Upp::Vector<Upp::String>::Vector(const Upp::Vector<Upp::String>&)'
 class AMap {
       ^
In file included from /home/steffen/Projects/upp/uppsrc/Core/Core.h:282:0,
                 from /home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp:1:
/home/steffen/Projects/upp/uppsrc/Core/Vcont.h:13:7: note: 'constexpr Upp::Vector<Upp::String>::Vector(const Upp::Vector<Upp::String>&)' is implicitly declared as deleted because 'Upp::Vector<Upp::String>' declares a move constructor or move assignment operator
 class Vector : public MoveableAndDeepCopyOption< Vector<T> > {
       ^
/home/steffen/Projects/Ultimatepp/VectorTest/VectorTest.cpp:14:35: error: use of deleted function 'constexpr Upp::Vector<Upp::String>::Vector(const Upp::Vector<Upp::String>&)'
  Vector<String> rv = vm.GetValues();

Re: C++11: Vector is missing copy contructor/assignment operator [message #43175 is a reply to message #43173] Thu, 29 May 2014 07:51 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You must have missed "big change of pick semantics in C++ 11" topic Smile

See current documentation.

The correct code for C++11 now is

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	Vector<int> v;
	Vector<int> r = pick(v);

	VectorMap<int,String> vm;
	VectorMap<int,String> rvm = pick(vm);

	Vector<String> rv = pick(vm.GetValues());
}


If you have a lot of code requiring old behaviour, I might consider some compilation flag to force the old behaviour. Anyway, it took only about 2 hours to fix all of U++...

[Updated on: Thu, 29 May 2014 07:51]

Report message to a moderator

Re: C++11: Vector is missing copy contructor/assignment operator [message #43176 is a reply to message #43175] Thu, 29 May 2014 07:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Here is the announcment:

http://www.ultimatepp.org/forums/index.php?t=msg&th=8527 &start=0&
Re: C++11: Vector is missing copy contructor/assignment operator [message #43191 is a reply to message #43176] Mon, 02 June 2014 15:56 Go to previous message
steffen is currently offline  steffen
Messages: 38
Registered: May 2007
Location: Denmark
Member

Thank you very much, Mirek.

I totally missed that announcement. Embarassed

For some time I had the error in a single place, but when I got it on an array too I tried to make the tests above.
And it was a bit hard for me to figure out which constructor or operator was in use in the different places.
It took only 5 seconds to fix my two error though. Very Happy
Previous Topic: Unterminated processing info in XmlParser
Next Topic: Is XML compression possible by U++ library call?
Goto Forum:
  


Current Time: Sat Apr 20 07:15:19 CEST 2024

Total time taken to generate the page: 0.02569 seconds