This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/13121] Inserting struct with valarray in map fails
- From: "Uwe dot Seimet at seimet dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Nov 2003 15:00:35 -0000
- Subject: [Bug libstdc++/13121] Inserting struct with valarray in map fails
- References: <20031119101223.13121.Uwe.Seimet@seimet.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From Uwe dot Seimet at seimet dot de 2003-11-19 15:00 -------
Subject: Re: Inserting struct with valarray in map fails
Hello!
> ------- Additional Comments From bangerth at dealii dot org 2003-11-19 14:47 -------
> This is because this program
> ------------------
> #include <valarray>
> #include <iostream>
>
> int main ()
> {
> std::valarray <int> v1(5);
> std::valarray <int> v2;
> v2 = v1;
>
> std::cout << v1.size() << " " << v2.size() << std::endl;
> }
> -----------------------
> when compiled with any gcc version returns
> g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc ; ./a.out
> 5 0
>
> icc, for reference, returns "5 5". Both results are standards conforming,
> since 26.3.2.2/1 reads: "...The resulting behavior is undefined if the
> length of the argument array is not equal to the length of the *this
> array."
>
> What you do with your map is the following: you first create an entry
> by using m[(void*)0], and only then do you assign to it, so the result
> is fully conforming.
Thank you for your rapid response! So gcc is obviously right, and our code
is wrong. Nevertheless we think that the standard is a bit strange, allowing
undefined behavior for an assignment.
Best regards, Uwe
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13121