From patchwork Mon Jun 10 19:37:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 250342 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id B9ADF2C0095 for ; Tue, 11 Jun 2013 05:37:48 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=cK4roEOrjqZIGUptTQsgW0kfd5v8z6cHFsNEZtr8HeS egDLC0c3irHK6rg95gDvjtt7bXcGay79aHhqUOt7E+/OR5Vwg6/YJ9YXwVbrVGLk XrjxOnM4XcuhWKnyOVr8QwKCljAexGkA86d8oi8RyWCdK1JdoNqgAQ/CmNuiiAg4 = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=BobWFM3IvI88Wc7TYvWIL7lCAwk=; b=QUooFMRse6i26PZ/X 4dCQFHWwZOo27HnZLaETeFvmwohdSGrB7YQv0zFj34X8O0I7dqBB0/MhI674TIoP edxynlkwKCS2hXvkQO3LdkA4+d+knFReGES4H0RuLYzde1bKviBli2Y9gjSuXWBF GkzXLOjFYXZ7W0YOxCGinNbXuo= Received: (qmail 23509 invoked by alias); 10 Jun 2013 19:37:43 -0000 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 Received: (qmail 23483 invoked by uid 89); 10 Jun 2013 19:37:37 -0000 X-Spam-SWARE-Status: No, score=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 10 Jun 2013 19:37:36 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5AJbZMp014116 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 10 Jun 2013 15:37:35 -0400 Received: from [10.3.113.39] (ovpn-113-39.phx2.redhat.com [10.3.113.39]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5AJbYI2001706; Mon, 10 Jun 2013 15:37:34 -0400 Message-ID: <51B62AFE.4000809@redhat.com> Date: Mon, 10 Jun 2013 15:37:34 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:23.0) Gecko/20100101 Thunderbird/23.0a2 MIME-Version: 1.0 To: gcc-patches List CC: Gabriel Dos Reis Subject: C++ PATCH to warn about undefined functions in anonymous namespace X-Virus-Found: No Since members of the anonymous namespace can't be defined in another translation unit, we should treat them like statics for diagnostic purposes. Tested x86_64-pc-linux-gnu, applying to trunk. commit 815fbf1df6dafdbeb04a35827222d78c9b419219 Author: Jason Merrill Date: Mon Jun 10 12:29:35 2013 -0400 * name-lookup.c (add_decl_to_level): Add decls in an anonymous namespace to static_decls. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 17d5ca2..2b1f9fb 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -597,7 +597,9 @@ add_decl_to_level (tree decl, cp_binding_level *b) if ((VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) || (TREE_CODE (decl) == FUNCTION_DECL - && (!TREE_PUBLIC (decl) || DECL_DECLARED_INLINE_P (decl)))) + && (!TREE_PUBLIC (decl) + || decl_anon_ns_mem_p (decl) + || DECL_DECLARED_INLINE_P (decl)))) vec_safe_push (b->static_decls, decl); } } diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-5.C b/gcc/testsuite/g++.dg/warn/anonymous-namespace-5.C new file mode 100644 index 0000000..6f5a081 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-5.C @@ -0,0 +1,8 @@ +namespace { + void f(); // { dg-message "never defined" } +} + +int main() +{ + f(); +}