473,848 Members | 1,835 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 2073

"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
2271
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
1643
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
2369
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
3357
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
1485
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
1476
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
6533
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
3070
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
1853
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
9893
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
9738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10665
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...
1
10723
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10349
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
7894
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
7070
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4544
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
3
3177
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.