473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Compilation problem when upgrading from g++ 3.3 to g++ 3.4

Hi,

The code below has no problem with GNU g++ 3.3,
but it has a problem with GNU g++ 3.4.

Any suggestions?

------ foo.cpp ------
#include <vector>
using namespace std;

typedef char foo_t[3];
#define ELEM1 "ab"
#define ELEM2 "cd"

const foo_t a[] = {ELEM1, ELEM2};
const vector<foo_t> v = vector<foo_t>(a, a + sizeof (a)/sizeof (*a));

int main()
{
return 0;
}
---------------------

------ Compilation with GNU gcc 3.3 (Cygwin) : BEGIN ------

$ g++ --version
g++ (GCC) 3.3.3 (cygwin special)
[---omitted---]

$ g++ -W -Wall foo.cpp
// No errors/warnings

------ Compilation with GNU gcc 3.3 (Cygwin) : END --------

------ Compilation with GNU gcc 3.4 (DJGPP) : BEGIN ------

$ gpp --version
gpp.exe (GCC) 3.4.1
[---omitted---]
$ gpp -W -Wall foo.cpp
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_construct.h: In function `void std::_Construct(_T1*, const
_T2&) [with _T1 = char[3], _T2 = char[3]]':
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_uninitialized.h:86: instantiated from `_ForwardIterator
std::__uninitialized_copy_aux(_InputIterator, _InputIterator, _ForwardIterator, __false_type) [with _InputIterator =
__gnu_cxx::__normal_iterator<const char (*)[3], std::vector<char[3], std::allocator<char[3]> > >, _ForwardIterator = char (*)[3]]'
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_uninitialized.h:112: instantiated from `_ForwardIterator
std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const
char (*)[3], std::vector<char[3], std::allocator<char[3]> > >, _ForwardIterator = char (*)[3]]'
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_vector.h:221: instantiated from `std::vector<_Tp,
_Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = char[3], _Alloc = std::allocator<char[3]>]'
foo.cpp:9: instantiated from here
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_construct.h:81: error: ISO C++ forbids initialization in
array new

------ Compilation with GNU gcc 3.4 (DJGPP) : END --------

--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Jul 22 '05 #1
4 2034

"Alex Vinokur" <al****@big-foot.com> wrote in message
news:2v*************@uni-berlin.de...
Hi,

The code below has no problem with GNU g++ 3.3,
but it has a problem with GNU g++ 3.4.

Any suggestions?
Arrays cannot be members of STL containers because they are not copyable or
assignable. No idea why g++ 3.3 allowed it in the first place.

------ foo.cpp ------
#include <vector>
using namespace std;

typedef char foo_t[3];
#define ELEM1 "ab"
#define ELEM2 "cd"

const foo_t a[] = {ELEM1, ELEM2};
const vector<foo_t> v = vector<foo_t>(a, a + sizeof (a)/sizeof (*a));

int main()
{
return 0;
}
---------------------


Try something like this

class Char3
{
public:
Char3(const char*);
char operator[](size_t i);
char c[3];
};

const Char3 a[] = {ELEM1, ELEM2};
const vector<Char3> v = vector<Char3>(a, a + sizeof (a)/sizeof (*a));

john
Jul 22 '05 #2
John Harrison wrote:
Arrays cannot be members of STL containers because they are not copyable or
assignable. No idea why g++ 3.3 allowed it in the first place.

G++ has an extension to give copy semantics to arrays. The later versions
of G++ (I assumed that this happened before 3.3 though) turn the extensions
off by default.
Jul 22 '05 #3
"John Harrison" <jo*************@hotmail.com> wrote in message news:<2v*************@uni-berlin.de>...
"Alex Vinokur" <al****@big-foot.com> wrote in message
news:2v*************@uni-berlin.de...
Hi,

The code below has no problem with GNU g++ 3.3,
but it has a problem with GNU g++ 3.4.

Any suggestions?


Arrays cannot be members of STL containers because they are not copyable or
assignable. No idea why g++ 3.3 allowed it in the first place.


It might have used memcpy, which would be a legal implementation
since char[3] is a POD. You just can't rely on such an implementation,
as g++3.4 shows.

Regards,
Michiel Salters
Jul 22 '05 #4
Hi,

g++ 3.4 is more pinky about right c++. A std::vector initializes elements
with new. You define a std::vector of a array, so it should use new[]. It
is not allowed to define a std::vector of array.

Tommi
Alex Vinokur wrote:
Hi,

The code below has no problem with GNU g++ 3.3,
but it has a problem with GNU g++ 3.4.

Any suggestions?

------ foo.cpp ------
#include <vector>
using namespace std;

typedef char foo_t[3];
#define ELEM1 "ab"
#define ELEM2 "cd"

const foo_t a[] = {ELEM1, ELEM2};
const vector<foo_t> v = vector<foo_t>(a, a + sizeof (a)/sizeof (*a));

int main()
{
return 0;
}
---------------------

------ Compilation with GNU gcc 3.3 (Cygwin) : BEGIN ------

$ g++ --version
g++ (GCC) 3.3.3 (cygwin special)
[---omitted---]

$ g++ -W -Wall foo.cpp
// No errors/warnings

------ Compilation with GNU gcc 3.3 (Cygwin) : END --------

------ Compilation with GNU gcc 3.4 (DJGPP) : BEGIN ------

$ gpp --version
gpp.exe (GCC) 3.4.1
[---omitted---]
$ gpp -W -Wall foo.cpp
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_construct.h: In function `void std::_Construct(_T1*, const _T2&) [with _T1 = char[3],
_T2 = char[3]]':
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_uninitialized.h:86: instantiated from `_ForwardIterator
std::__uninitialized_copy_aux(_InputIterator, _InputIterator,
_ForwardIterator, __false_type) [with _InputIterator =
__gnu_cxx::__normal_iterator<const char (*)[3], std::vector<char[3],
std::allocator<char[3]> > >, _ForwardIterator = char (*)[3]]'
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_uninitialized.h:112: instantiated from `_ForwardIterator
std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator)
[with _InputIterator = __gnu_cxx::__normal_iterator<const char (*)[3],
std::vector<char[3], std::allocator<char[3]> > >, _ForwardIterator = char
(*)[3]]'
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_vector.h:221: instantiated from `std::vector<_Tp, _Alloc>::vector(const
std::vector<_Tp, _Alloc>&) [with _Tp = char[3], _Alloc =
std::allocator<char[3]>]'
foo.cpp:9: instantiated from here
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_construct.h:81: error: ISO C++ forbids initialization in array new

------ Compilation with GNU gcc 3.4 (DJGPP) : END --------


--
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Edoardo Costa | last post by:
Dear SQL wizards, I'm having a little problem with sub queries under mysql and I'd like to know if you can help me out. The example is streight out from the ref manual:...
11
by: Alex Vinokur | last post by:
Hi, The code below has no problem with GNU g++ 3.3, but it has a problem with GNU g++ 3.4. What is reason for that? --------- foo.cpp : BEGIN --------- template <typename T> struct Boo
3
by: derek.google | last post by:
While porting an application to Linux I hit a strange compiler error with GCC 3.3.2. Here is the most stripped down version of the code I could write: 1 template <typename T> struct SmartPtr 2...
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
3
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition...
9
by: dotnettester | last post by:
Hi, Can any one point me to a good resource on what to expect for .NET Applications when upgrading from IIS 5.0 to IIS 6.0 We are thinking to move to IIS 6.0 but fear...... Thanks,
2
by: bikerchick | last post by:
I'm used to using VS2003, but am now upgrading some of my VB.NET applications to VS2005 using the upgrade wizard. My web services normally consist of the bin folder, .asmx and .config files -...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
35
by: mwelsh1118 | last post by:
Why doesn't C# allow incremental compilation like Java? Specifically, in Java I can compile single .java files in isolation. The resulting individual .class files can be grouped into .jar files....
4
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I removed my VS 2008 beta installation and reinstalled the final version that was released in November. However, my ajax-enabled application gives the following error message on compilation. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.