From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12546 invoked by alias); 25 Jun 2007 18:13:20 -0000 Received: (qmail 12499 invoked by uid 48); 25 Jun 2007 18:13:09 -0000 Date: Mon, 25 Jun 2007 18:13:00 -0000 Message-ID: <20070625181309.12498.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/29365] Unnecessary anonymous namespace warnings In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "spark at gcc dot gnu dot org" 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: 2007-06/txt/msg02381.txt.bz2 ------- Comment #30 from spark at gcc dot gnu dot org 2007-06-25 18:13 ------- The following patch will essentially disable the warning for template instantiations in the anonymous namespace. Index: gcc/cp/decl2.c =================================================================== --- gcc/cp/decl2.c (revision 125999) +++ gcc/cp/decl2.c (working copy) @@ -1850,7 +1850,9 @@ constrain_class_visibility (tree type) if (subvis == VISIBILITY_ANON) { if (strcmp (main_input_filename, - DECL_SOURCE_FILE (TYPE_MAIN_DECL (ftype)))) + DECL_SOURCE_FILE (TYPE_MAIN_DECL (ftype))) + && !(CLASS_TYPE_P (ftype) + && CLASSTYPE_USE_TEMPLATE (ftype))) warning (0, "\ %qT has a field %qD whose type uses the anonymous namespace", type, t); @@ -1871,7 +1873,9 @@ constrain_class_visibility (tree type) if (subvis == VISIBILITY_ANON) { if (strcmp (main_input_filename, - DECL_SOURCE_FILE (TYPE_MAIN_DECL (TREE_TYPE (t))))) + DECL_SOURCE_FILE (TYPE_MAIN_DECL (TREE_TYPE (t)))) + && !(CLASS_TYPE_P (TREE_TYPE (t)) + && CLASSTYPE_USE_TEMPLATE (TREE_TYPE (t)))) warning (0, "\ %qT has a base %qT whose type uses the anonymous namespace", type, TREE_TYPE (t)); I don't know whether it's possible to do this warning accurately, as I can't figure out how to recover where the template instantiation has happened at this point in compilation. DECL_SOURCE_FILE (TYPE_MAIN_DECL (ftype)) points to the source file of the declaration of the template itself, not where the template instantiation happened. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29365