From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26776 invoked by alias); 1 Aug 2004 20:13:42 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 26767 invoked by uid 48); 1 Aug 2004 20:13:40 -0000 Date: Sun, 01 Aug 2004 20:13:00 -0000 Message-ID: <20040801201340.26766.qmail@sourceware.org> From: "carlo at gcc dot gnu dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20040801025152.16848.igodard@pacbell.net> References: <20040801025152.16848.igodard@pacbell.net> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libstdc++/16848] code in /ext/demangle.h appears broken X-Bugzilla-Reason: CC X-SW-Source: 2004-08/txt/msg00038.txt.bz2 List-Id: ------- Additional Comments From carlo at gcc dot gnu dot org 2004-08-01 20:13 ------- 1) The template "demangle" takes two typename arguments. The first appears to be never used. The change log says: 2004-02-26 Benjamin Kosnik * include/bits/demangle.h: Add type template parameter to all templates with just an Allocator template parameter. I have no idea why he did that - I remember he asked me to add that patch and I refused it because I didn't understand it. Then he didn't explain it to me but applied this patch (and I have not been aware of that until now). 2) The template "demangle" is commented as constituting the public interface. However, it exports functions which take mandatory (not with default) arguments of type "implementation_details", which type is declared in the local namespace "demangler". There exists no public data of this type. A public interface that requires use of a private type cannot be called public :-) Yes and no. You can consider __gnu_cxx::demangler::implementation_details public interface if you want - but more importantly - you shouldn't really use those exported functions. I suppose that you are right that these should have a default value perhaps - but then again, it doesn't hurt when programmers that use this templated demangler to implement their own demangler are forced to be aware of the fact that they have to decide what implementation details they want to use. 3) There is no default value for the allocator (second) argument to template "demangle", forcing the user to explicitly supply one. This violates the conventions used throughout the standard library. That is deliberate. This interface is not intended for normal programmers but for demangler writers: if you need a demangler that uses a non-standard allocator - THEN you will use this - otherwise you'd just use the std::__cxa_demangle standard interface... which used to be based on THIS templated demangler implementation using the a default allocator. However, Benjamin Kosnik removed it: 2004-02-26 Benjamin Kosnik PR libstdc++/10246 * libsupc++/Makefile.am: Use libiberty demangler. (c_sources): Add cp-demangle.c. * libsupc++/Makefile.in: Regenerate. * src/Makefile.am (sources): Remove demangle.cc. * src/Makefile.in: Regenerate. * include/Makefile.am (bits_headers): Move demangle.h. (ext_headers): ...here. * include/Makefile.in: Regenerate. * include/bits/demangle.h: Move... * include/ext/demangle.h: ...here. * src/demangle.cc: Remove. 5) There is no usage documentation that either I or Google can find. All examples available refer to the demangler in cxxabi.h, which has a "C" interface and fails to parse mangled types (cf. bug #16845). True - there is lack of documentation. However, all the documentation one really needed was in that default __cxa_demangle implementation... that is unfortunately been removed. 6) The above code fails to compile in 3.4.0. I struggled for a while trying to find out what was wrong, but frankly the compiler output for this is something only a mother would love. The code I last maintained compiles perfectly and works. Someone else broke it - probably one of the patches by Benjamin - which, again, I wasn't even aware of till now. I don't consider myself maintainer of this code anymore now. Thanks Carlo PS Using the last demangle.h that I maintained; the correct usage for your code snippet would have been like this: #include #include #include #include // strlen #include int main(void) { const char* name = typeid(int).name(); __gnu_cxx::demangler::session > demangle_session(name, std::strlen(name)); std::string result; demangle_session.decode_type(result); std::cout << result << std::endl; return 0; } Changing bits/demangle.h into ext/demangle.h and adding a 'char' template parameter doesn't help with the distributed version of demangle.h (I tried 3.4.1). But it does work with my version: ~/c++/demangler>g++-3.4.1 -I. bug16848.cc ~/c++/demangler>a.out int -- What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|carlo at alinoe dot com |bkoz at redhat dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16848