+2004-06-28  Zack Weinberg  <zack@codesourcery.com>
+
+       * cp-demangle.h: Declare cplus_demangle_operators,
+       cplus_demangle_builtin_types, cplus_demangle_mangled_name, and
+       cplus_demangle_type as static if IN_GLIBCPP_V3.
+
+2004-06-28  Ian Lance Taylor  <ian@wasabisystems.com>
+
+       PR other/16240
+       * cp-demangle.c (d_expr_primary): Check for a failure return from
+       cplus_demangle_type.
+       * testsuite/demangle-expected: Add test case.
+
 2004-05-31  Danny Smith  <dannysmith@users.sourceforge.net>
 
        * pex-win32.c (fix_argv): Expand comment.
 
 2003-08-12  Nathanael Nerode  <neroden@gcc.gnu.org>
 
-        * cp-demangle.c: Clarify what package(s) this is part of.
+       * cp-demangle.c: Clarify what package(s) this is part of.
 
 2003-07-05  Danny Smith  <dannysmith@users.sourceforge.net>
 
 
       const char *s;
 
       type = cplus_demangle_type (di);
+      if (type == NULL)
+       return NULL;
 
       /* If we have a type we know how to print, we aren't going to
         print the type name itself.  */
 
 
 /* Functions and arrays in cp-demangle.c which are referenced by
    functions in cp-demint.c.  */
+#ifdef IN_GLIBCPP_V3
+#define CP_STATIC_IF_GLIBCPP_V3 static
+#else
+#define CP_STATIC_IF_GLIBCPP_V3 extern
+#endif
 
-extern const struct demangle_operator_info cplus_demangle_operators[];
+CP_STATIC_IF_GLIBCPP_V3
+const struct demangle_operator_info cplus_demangle_operators[];
 
 #define D_BUILTIN_TYPE_COUNT (26)
 
-extern const struct demangle_builtin_type_info
+CP_STATIC_IF_GLIBCPP_V3
+const struct demangle_builtin_type_info
 cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT];
 
-extern struct demangle_component *
+CP_STATIC_IF_GLIBCPP_V3
+struct demangle_component *
 cplus_demangle_mangled_name PARAMS ((struct d_info *, int));
 
-extern struct demangle_component *
+CP_STATIC_IF_GLIBCPP_V3
+struct demangle_component *
 cplus_demangle_type PARAMS ((struct d_info *));
 
 extern void
 cplus_demangle_init_info PARAMS ((const char *, int, size_t, struct d_info *));
+
+/* cp-demangle.c needs to define this a little differently */
+#undef CP_STATIC_IF_GLIBCPP_V3
 
 void foo<int (*) [3]>(int (* const&) [3])
 foo<int (*) [3]>
 #
+# This used to crash the demangler--PR 16240
+--format=gnu-v3 --no-params
+_ZN13PatternDriver23StringScalarDeleteValueC1ERKNS_25ConflateStringScalarValueERKNS_25AbstractStringScalarValueERKNS_12TemplateEnumINS_12pdcomplementELZNS_16complement_namesEELZNS_14COMPLEMENTENUMEEEE
+_ZN13PatternDriver23StringScalarDeleteValueC1ERKNS_25ConflateStringScalarValueERKNS_25AbstractStringScalarValueERKNS_12TemplateEnumINS_12pdcomplementELZNS_16complement_namesEELZNS_14COMPLEMENTENUMEEEE
+PatternDriver::StringScalarDeleteValue::StringScalarDeleteValue
 # Test GNU V3 constructor and destructor identification.
 # 0 means it is not a constructor/destructor.
 # Other integers correspond to enum gnu_v3_{c,d}tor_kinds in demangle.h.