From patchwork Fri Oct 1 21:18:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 66520 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 49399B70F2 for ; Sat, 2 Oct 2010 07:18:24 +1000 (EST) Received: (qmail 3514 invoked by alias); 1 Oct 2010 21:18:22 -0000 Received: (qmail 3503 invoked by uid 22791); 1 Oct 2010 21:18:21 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Oct 2010 21:18:17 +0000 Received: by wwb28 with SMTP id 28so4290589wwb.8 for ; Fri, 01 Oct 2010 14:18:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.12.8 with SMTP id 8mr2575237wey.107.1285967894557; Fri, 01 Oct 2010 14:18:14 -0700 (PDT) Received: by 10.216.136.130 with HTTP; Fri, 1 Oct 2010 14:18:14 -0700 (PDT) Date: Fri, 1 Oct 2010 22:18:14 +0100 Message-ID: Subject: [patch] c++/42018 try to reject specialization re-declared in wrong namespace From: Jonathan Wakely To: gcc-patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch is my attempt to fix PR c++/42018, but it's wrong, because it also rejects some valid specializations, causing: FAIL: g++.old-deja/g++.ns/template12.C (test for excess errors) Excess errors: /home/redi/src/gcc/gcc-4.x/gcc/testsuite/g++.old-deja/g++.ns/template12.C:18:47: error: specialization of 'template const T bar::foo(const T&)' in different namespace [-fpermissive] /home/redi/src/gcc/gcc-4.x/gcc/testsuite/g++.old-deja/g++.ns/template12.C:13:20: error: from definition of 'template const T bar::foo(const T&)' [-fpermissive] FAIL: g++.old-deja/g++.pt/memtemp96.C (test for excess errors) Excess errors: /home/redi/src/gcc/gcc-4.x/gcc/testsuite/g++.old-deja/g++.pt/memtemp96.C:11:17: error: specialization of 'template template int A::f(U)' must appear at namespace scope Can anyone point me in the right direction so that the new test in the patch fails, but those don't? Thanks, Jonathan Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 164893) +++ gcc/cp/pt.c (working copy) @@ -1379,6 +1379,11 @@ register_specialization (tree spec, tree } else if (DECL_TEMPLATE_SPECIALIZATION (fn)) { + /* A specialization must be declared in the same namespace as the + template it is specializing. */ + if (!check_specialization_namespace (tmpl)) + return error_mark_node; + if (!duplicate_decls (spec, fn, is_friend) && DECL_INITIAL (spec)) /* Dup decl failed, but this is a new definition. Set the line number so any errors match this new Index: gcc/testsuite/g++.dg/template/pr42018.C =================================================================== --- gcc/testsuite/g++.dg/template/pr42018.C (revision 0) +++ gcc/testsuite/g++.dg/template/pr42018.C (revision 0) @@ -0,0 +1,14 @@ +// PR c++/42018 +// { dg-do compile } + +template + void foo(void); // { dg-error "from definition of" } + +template<> + void foo(); + +namespace x { + template<> + void foo() { return; } // { dg-error "in different namespace" } +} +