From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90994 invoked by alias); 4 Aug 2015 17:32:35 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 90985 invoked by uid 89); 4 Aug 2015 17:32:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: smtp.ispras.ru Received: from smtp.ispras.ru (HELO smtp.ispras.ru) (83.149.199.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Aug 2015 17:32:34 +0000 Received: from [10.10.3.121] (unknown [83.149.199.91]) by smtp.ispras.ru (Postfix) with ESMTP id 07A76214EC; Tue, 4 Aug 2015 20:32:32 +0300 (MSK) Date: Tue, 04 Aug 2015 17:32:00 -0000 From: Alexander Monakov To: Jonathan Wakely cc: Nikolay Vorobyov , gcc-help Subject: Re: Explicit instantiation and static objects in different modules In-Reply-To: Message-ID: References: <63FDE6C4-EFC2-44DD-991E-0BE895586162@gmail.com> User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2015-08/txt/msg00023.txt.bz2 On Tue, 4 Aug 2015, Jonathan Wakely wrote: > The extern template tells the compiler it doesn't *need* to > instantiate the template, because it will be explicitly instantiated > in another translation unit. But that doesn't mean it *must not* > instantiate it. The compiler can choose to inline the function and in > that case it will implicitly instantiate it. That should be > unobservable because the One Definition Rule means that the implicitly > instantiated definition that gets inlined and the explicitly > instantiation definition in the other translation unit must be > identical. The Windows linkage model seems to break that assumption > ... so I don't know what the right behaviour is. OK, thanks. AFAIU, a very similar problem existed with GCC on Linux prior to introduction of STB_GNU_UNIQUE (consider what happened when multiple DSOs with a common singleton are loaded with RTLD_LOCAL -- they didn't have a way to end up with a common location). In light of that, perhaps it's best to structure code in a way that prevents implementation of a singleton from being visible in translation units that can be linked into different libraries. Alexander