C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[g++] Bug avec les itérateurs et -O3 ?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Vincent Richard
Guest





PostPosted: Tue Aug 19, 2003 10:36 am    Post subject: [g++] Bug avec les itérateurs et -O3 ? Reply with quote



Bonjour,

Pouvez-vous me dire si le code suivant est correct ?

Il compile avec g++ (aucune erreur, aucun avertissement), mais avec l'option
d'optimisation -O3, l'exécution produit une boucle infinie :

g++ -ansi -Wall -pedantic -o it it.cpp FONCTIONNE

g++ -O3 -ansi -Wall -pedantic -o it it.cpp NE FONCTIONNE PAS !!

Version de g++ :

g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

Voici le code (it.cpp) :

#include <vector>

class A
{
public:

std::vector <int> v;
typedef std::vector <int>::iterator IT;

A()
{
for (int i = 0 ; i < 10 ; ++i)
{
v.push_back(i);
}

f(v.end() - 2);
}

const IT f(const IT i)
{
IT j = i - 1;

for (;Wink
{
IT p = j;
p = j - 1;
j = p;
if (j == v.begin()) break;
}

return j;
}
};

int main()
{
A a;
}

Autre fait très étrange : si je déclare une variable "std::string s;" dans
la boucle (après la ligne "j = p"), l'exécution fonctionne dans les 2 cas...

Là, je comprends pas tout...

Merci d'avance pour vos réponses.

Vincent

--
SL> Au fait elle est mieux ma signature maintenant ?
Oui. T'enlève encore les conneries que t'as écrit dedans et c'est bon.
-+- JB in <http://www.le-gnu.net> : Le neuneuttoyage par le vide -+-
Back to top
Richard Delorme
Guest





PostPosted: Tue Aug 19, 2003 5:46 pm    Post subject: Re: [g++] Bug avec les itérateurs et -O3 ? Reply with quote



Vincent Richard a écrit :

Quote:
Bonjour,

Pouvez-vous me dire si le code suivant est correct ?

Il m'a au moins l'air tordu.

Quote:
Il compile avec g++ (aucune erreur, aucun avertissement), mais avec
l'option d'optimisation -O3, l'exécution produit une boucle infinie :

g++ -ansi -Wall -pedantic -o it it.cpp FONCTIONNE

g++ -O3 -ansi -Wall -pedantic -o it it.cpp NE FONCTIONNE PAS !!

Version de g++ :

g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

ça ne marche pas non plus avec g++ 3.2.3, mais ça marche avec g++ 3.3.1. Il
s'agit sans doute d'un bogue corrigé.

--
Richard

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.