From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28856 invoked by alias); 22 Jul 2014 16:40:09 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 28800 invoked by uid 48); 22 Jul 2014 16:40:04 -0000 From: "msebor at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/61882] New: attribute weak ignored for function templates Date: Tue, 22 Jul 2014 16:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.8.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg01521.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61882 Bug ID: 61882 Summary: attribute weak ignored for function templates Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gmail dot com In GCC 4.5 and later, and at -O and above, attribute weak (but not weak alias) is silently ignored on declarations of function templates and calls to specializations of such templates are inlined into their callers. The program below shows that GCC inlines calls to the function template specialization instantiated from the weak primary template baz, but emits a weak symbol for the weak alias foo. GCC 4.2 honored the attribute and emitted a weak symbol for both foo and baz. Clang 3.4 also emits a weak symbol for both as expected. Disabling optimization changes the current behavior to match that of GCC 4.2.1 and Clang 3.4. The GCC documentation of attribute weak doesn't say whether or not the attribute is intended to have the same effect on specializations of function templates as it does on ordinary functions. If the current GCC behavior is intended, the documentation should be updated to make it clear when attribute weak is ignored, and GCC should be enhanced to issue a warning when the attribute is ignored. $ (set -x; cc=/auto/compiler-dev/msebor/contrib/cel-5.50/bin/g++; cat z.c && $cc -c -fpic -DFOO=1 -O -Wall -Wextra z.c && $cc -fpic -Wall -Wextra z.c z.o && ./a.out) + cc=/auto/compiler-dev/msebor/contrib/cel-5.50/bin/g++ + cat z.c template void foo (T); template void baz (T); void foobar (); #if FOO template void __attribute__ ((weak, alias ("bar"))) foo (T); static void bar (int) { } template void __attribute__ ((weak)) baz (T) { } void foobar () { foo (0), baz (0); } #else # include template <> void foo (int) { puts (__func__); } template <> void baz (int) { puts (__func__); } int main (void) { foobar (); } #endif + /auto/compiler-dev/msebor/contrib/cel-5.50/bin/g++ -c -fpic -DFOO=1 -O -Wall -Wextra z.c + /auto/compiler-dev/msebor/contrib/cel-5.50/bin/g++ -fpic -Wall -Wextra z.c z.o + ./a.out foo