473,770 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_uninitializ ed.h:86: instantiated from `_ForwardIterat or
std::__uninitia lized_copy_aux( _InputIterator, _InputIterator, _ForwardIterato r, __false_type) [with _InputIterator =
__gnu_cxx::__no rmal_iterator<c onst char (*)[3], std::vector<cha r[3], std::allocator< char[3]> > >, _ForwardIterato r = char (*)[3]]'
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_uninitializ ed.h:112: instantiated from `_ForwardIterat or
std::uninitiali zed_copy(_Input Iterator, _InputIterator, _ForwardIterato r) [with _InputIterator = __gnu_cxx::__no rmal_iterator<c onst
char (*)[3], std::vector<cha r[3], std::allocator< char[3]> > >, _ForwardIterato r = char (*)[3]]'
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_vector.h:22 1: instantiated from `std::vector<_T p,
_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 2068

"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_uninitializ ed.h:86: instantiated from `_ForwardIterat or
std::__uninitia lized_copy_aux( _InputIterator, _InputIterator,
_ForwardIterato r, __false_type) [with _InputIterator =
__gnu_cxx::__no rmal_iterator<c onst char (*)[3], std::vector<cha r[3],
std::allocator< char[3]> > >, _ForwardIterato r = char (*)[3]]'
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_uninitializ ed.h:112: instantiated from `_ForwardIterat or
std::uninitiali zed_copy(_Input Iterator, _InputIterator, _ForwardIterato r)
[with _InputIterator = __gnu_cxx::__no rmal_iterator<c onst char (*)[3],
std::vector<cha r[3], std::allocator< char[3]> > >, _ForwardIterato r = char
(*)[3]]'
c:/djgpp/bin/../lib/gcc/djgpp/3.41/../../../../include/cxx/3.41/bits/stl_vector.h:22 1: instantiated from `std::vector<_T p, _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
2262
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: http://www.doctaur.com/dtdocs/databases/origman/manual_437.html The following is what I get when I run that simple query: $ cat test.sql
11
416
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
1639
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 { 3 SmartPtr(T*) {} 4 ~SmartPtr() { delete pm_impl; } 5 T* pm_impl; 6 };
10
2359
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 begun to use GNU Autotools. I'm sorry to say I'm new to gcc as well :( Now I get the most ridiculous compile error which I'm unable to solve. Can someone, please, help me with this? gcc output together with the files mentioned in the gcc error...
3
3351
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 from 'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\1f575646\ad3a161b\assembly\dl2\57ca505e\044565c0_f84fc401\Test1.DLL' The problem is that the control is defined in two different assemblies
9
1481
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
1472
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 - which I deploy. However, in 2005, my bin is empty, and i'm having to also deploy the App_Code folder to get it to work. This can't be right! can anyone tell me how to do this properly?! :o)
13
6518
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
3054
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. In C#, there appears to be no analog. I have to compile all my .cs files into a single .dll. This has serious drawbacks in terms of compilation. With Eclipse, I change a file and only that file is re-compiled. With Visual Studio, I
4
1851
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. "Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified." Any idea on how to fix this please?
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10057
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.