delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/10/24/15:25:33

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Lewis Hyatt <lhyatt AT princeton DOT edu>
Subject: Re: BUG REPORT: Cygwin, g++, -O2, static member function, std::string
Date: Wed, 24 Oct 2007 15:25:03 -0400
Lines: 27
Message-ID: <ffo66a$m9n$1@ger.gmane.org>
References: <Pine DOT LNX DOT 4 DOT 64 DOT 0710241031500 DOT 24456 AT snark DOT apl DOT washington DOT edu> <ffo392$9da$1 AT ger DOT gmane DOT org>
Mime-Version: 1.0
User-Agent: Thunderbird 2.0.0.6 (Windows/20070728)
In-Reply-To: <ffo392$9da$1@ger.gmane.org>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

> Can you post the bug{1,2}.cpp files? I would guess that its not a bug, 
> but rather you are relying on an undefined order of static 
> initialization that happens to do what you want sometimes but not 
> others. It's impossible to say for sure without seeing the source files, 
> though.

Oh I see, you did attach them, in the shell script. So the issue is that 
you are declaring a local static variable in an inline function, which 
is then referenced in multiple translation units. As far as I can 
remember, this is supposed to work OK, but I know a lot of compilers, 
not just gcc, get it wrong, because the standard is different than the 
ARM on this point. The bug was probably fixed in gcc 4.0, which is not 
yet available on cygwin. (You can verify that a lot of things will 
change this behavior, for instance if you just add a default constructor 
to Element() with an empty body, your example will work as you expect.) 
Anyway, for portability, you are probably better off not relying on any 
compiler getting this right, and you should just define the root() 
function non-inline in its own translation unit. That being said, gcc is 
clearly messing up here, as you would expect its most likely failure to 
be generating multiple copies of the static variable, not too few.

This isn't really cygwin-specific, you will get the same thing if you 
use the native windows MinGW compiler (ie, by using g++ -mno-cygwin). 
You're probably better off asking around in comp.lang.c++, comp.std.c++, 
or a gcc-specific mailing list, as those people will know more.

-Lewis


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019