From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10471 invoked by alias); 29 Jan 2012 02:40:27 -0000 Received: (qmail 10368 invoked by uid 22791); 29 Jan 2012 02:40:25 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ,TW_CX,TW_DC,TW_GX X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 29 Jan 2012 02:40:11 +0000 From: "benjamin at benkay dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/52036] New: C++11 allows template parameters to have internal linkage Date: Sun, 29 Jan 2012 08:52: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-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: benjamin at benkay dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 X-SW-Source: 2012-01/txt/msg03371.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D52036 Bug #: 52036 Summary: C++11 allows template parameters to have internal linkage Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: benjamin@benkay.net First gcc bug report, so please be kind :-). When using pointers or referen= ces as template parameters, C++03 requires these to have external linkage. I th= ink (and could be wrong) that C++11 relaxes this restriction. I would expect the attached code to compile with g++ -std=3Dc++0x, but it does not. testcase.cpp: template class TestClass { public: TestClass() : _val(val) { } private: T _val; }; extern constexpr float e =3D 2.72; int main() { constexpr float pi =3D 3.14; /* Allowed in both C++03 and C++11. */ TestClass test1; /* Not allowed in C++03 because pi lacks external linkage... * But isn't this allowed in C++11? */ TestClass test2; return 0; } $ g++ -v Using built-in specs. COLLECT_GCC=3Dg++ COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Debian 4.6.2-12' --with-bugurl=3Dfile:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=3Dc,c++,fortran,objc,obj-c++,go --prefix=3D/usr --program-suffix=3D-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --with-gxx-include-dir=3D/usr/include/c++/4.6 --libdir=3D/usr/lib --enable-nls --enable-clocale=3Dgnu --enable-libstdcxx-= debug --enable-libstdcxx-time=3Dyes --enable-plugin --enable-objc-gc --with-arch-32=3Di586 --with-tune=3Dgeneric --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linu= x-gnu Thread model: posix gcc version 4.6.2 (Debian 4.6.2-12) $ g++ -std=3Dc++0x -Wall -save-temps testcase.cpp testcase.cpp: In function =E2=80=98int main()=E2=80=99: testcase.cpp:20:22: error: =E2=80=98pi=E2=80=99 is not a valid template arg= ument for type =E2=80=98const float&=E2=80=99 because object =E2=80=98pi=E2=80=99 has not = external linkage testcase.cpp:20:29: error: invalid type in declaration before =E2=80=98;=E2= =80=99 token testcase.cpp:20:24: warning: unused variable =E2=80=98test2=E2=80=99 [-Wunu= sed-variable] testcase.ii: # 1 "testcase.cpp" # 1 "" # 1 "" # 1 "testcase.cpp" template class TestClass { public: TestClass() : _val(val) { } private: T _val; }; extern constexpr float e =3D 2.72; int main() { constexpr float pi =3D 3.14; TestClass test1; TestClass test2; return 0; }