From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27773 invoked by alias); 9 Sep 2003 14:08:32 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 27764 invoked by uid 48); 9 Sep 2003 14:08:32 -0000 Date: Tue, 09 Sep 2003 14:08:00 -0000 Message-ID: <20030909140832.27763.qmail@sources.redhat.com> From: "bangerth at dealii dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20030909101558.12222.stefaandr@hotmail.com> References: <20030909101558.12222.stefaandr@hotmail.com> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/12222] explicit initialization of static template members seems ignored X-Bugzilla-Reason: CC X-SW-Source: 2003-09/txt/msg00760.txt.bz2 List-Id: PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12222 bangerth at dealii dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever Confirmed| |1 Last reconfirmed|0000-00-00 00:00:00 |2003-09-09 14:08:31 date| | ------- Additional Comments From bangerth at dealii dot org 2003-09-09 14:08 ------- Your code is invalid: you have the explicit instantiation before the declaration of an explicit specialization of the member. That confuses the compiler. If you revert the order, you get this error message: tmp/g> ../build-gcc/gcc-install/bin/c++ x.cc -W -Wall /tmp/ccQIMlpO.o(.text+0x11): In function `main': : undefined reference to `a::b1' collect2: ld returned 1 exit status That is due to the fact that you only _declare_ the existence of an explicit specialization, not define it. If instead of template <> b a::b1; you write template <> b a::b1 = b(); then the code compiles properly and yields the expected result. Now, this is indeed confusing -- gcc should be able to issue a warning about specializing after instantiating. Besides, there is kind of a bug anyway: when accessing a::b1.m, gcc is apparently presently using the static member from the general template, not the specialization. That's fine, because the code is invalid. However, it is equally apparently not initializing it properly, since otherwise we would get the right answer. W.