This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PR 2767, V3 regression failure on strstr et al



The following patch (my original patch when PR 2767 first cane up) does work.
It is ugly, but it does work.

It fixes the original problem report in PR 2767 in which name conflicts were
introduced after a "using namespace std" directive.

It fixes subsequent problems of permanent name conflicts.

It works because you can't overload on a function's return value, meaning

char* f(const char*)

has effectively the same signature as

const char* f(const char*),

and if they're both extern "C", they are for all intents and purposes the same
function.  That's why the name confict arose in the first place.

This patch at least should get everyone through the night 'til the shadow
headers are copacetic.

Index: include/c_std/bits/std_cstring.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/c_std/bits/std_cstring.h,v
retrieving revision 1.7
diff -c -3 -p -r1.7 std_cstring.h
*** std_cstring.h	2001/05/08 23:53:55	1.7
--- std_cstring.h	2001/05/19 02:44:52
***************
*** 40,45 ****
--- 40,52 ----
  #include <bits/std_cstddef.h>
  
  #pragma GCC system_header
+ 
+ #define memchr  glibcpp_hidden_memchr
+ #define strchr  glibcpp_hidden_strchr
+ #define strpbrk glibcpp_hidden_strpbrk
+ #define strrchr glibcpp_hidden_strrchr
+ #define strstr  glibcpp_hidden_strstr
+ 
  #include <string.h>
  
  // Get rid of those macros defined in <string.h> in lieu of real functions.
*************** namespace std 
*** 80,128 ****
    extern "C" int strncmp(const char*, const char*, size_t); 
    extern "C" size_t strxfrm(char*, const char*, size_t); 
  
!   inline const void*
!   memchr(const void* __p, int __c, size_t __n)
!   { return const_cast<const void*>(::memchr(__p, __c, __n)); }
  
    inline void*
    memchr(void* __p, int __c, size_t __n)
!   { return ::memchr(const_cast<const void*>(__p), __c, __n); }
  
!   inline const char*
!   strchr(const char* __s1, int __n)
!   { return const_cast<const char*>(::strchr(__s1, __n)); }
  
    inline char*
    strchr(char* __s1, int __n)
!   { return ::strchr(const_cast<const char*>(__s1), __n); }
  
    extern "C" size_t strcspn(const char*, const char*); 
  
!   inline const char*
!   strpbrk(const char* __s1, const char* __s2)
!   { return const_cast<char*>(::strpbrk(__s1, __s2)); }
  
    inline char*
    strpbrk(char* __s1, const char* __s2)
!   { return ::strpbrk(const_cast<const char*>(__s1), __s2); }
  
!   inline const char*
!   strrchr(const char* __s1, int __n)
!   { return const_cast<char*>(::strrchr(__s1, __n)); }
  
    inline char*
    strrchr(char* __s1, int __n)
!   { return ::strrchr(const_cast<const char*>(__s1), __n); }
  
    extern "C" size_t strspn(const char*, const char*); 
  
!   inline const char*
!   strstr(const char* __s1, const char* __s2)
!   { return const_cast<char*>(::strstr(__s1, __s2)); }
  
    inline char*
    strstr(char* __s1, const char* __s2)
!   { return ::strstr(const_cast<const char*>(__s1), __s2); }
  
    extern "C" char* strtok(char*, const char*); 
    extern "C" void* memset(void*, int, size_t); 
--- 87,130 ----
    extern "C" int strncmp(const char*, const char*, size_t); 
    extern "C" size_t strxfrm(char*, const char*, size_t); 
  
!   extern "C" const void*
!   memchr(const void* __p, int __c, size_t __n);
  
    inline void*
    memchr(void* __p, int __c, size_t __n)
!   { return const_cast<void*>(memchr(const_cast<const void*>(__p), __c, __n)); }
  
!   extern "C" const char*
!   strchr(const char* __s1, int __n);
  
    inline char*
    strchr(char* __s1, int __n)
!   { return const_cast<char*>(strchr(const_cast<const char*>(__s1), __n)); }
  
    extern "C" size_t strcspn(const char*, const char*); 
  
!   extern "C" const char*
!   strpbrk(const char* __s1, const char* __s2);
  
    inline char*
    strpbrk(char* __s1, const char* __s2)
!   { return const_cast<char*>(strpbrk(const_cast<const char*>(__s1), __s2)); }
  
!   extern "C" const char*
!   strrchr(const char* __s1, int __n);
  
    inline char*
    strrchr(char* __s1, int __n)
!   { return const_cast<char*>(strrchr(const_cast<const char*>(__s1), __n)); }
  
    extern "C" size_t strspn(const char*, const char*); 
  
!   extern "C" const char*
!   strstr(const char* __s1, const char* __s2);
  
    inline char*
    strstr(char* __s1, const char* __s2)
!   { return const_cast<char*>(strstr(const_cast<const char*>(__s1), __s2)); }
  
    extern "C" char* strtok(char*, const char*); 
    extern "C" void* memset(void*, int, size_t); 
Index: include/c_std/bits/std_cwchar.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/c_std/bits/std_cwchar.h,v
retrieving revision 1.9
diff -c -3 -p -r1.9 std_cwchar.h
*** std_cwchar.h	2001/05/08 23:53:55	1.9
--- std_cwchar.h	2001/05/19 02:44:55
***************
*** 43,48 ****
--- 43,55 ----
  
  #if _GLIBCPP_HAVE_WCHAR_H
  #pragma GCC system_header
+ 
+ #define wmemchr glibcpp_hidden_wmemchr
+ #define wcschr  glibcpp_hidden_wcschr
+ #define wcspbrk glibcpp_hidden_wcspbrk
+ #define wcsrchr glibcpp_hidden_wcsrchr
+ #define wcsstr  glibcpp_hidden_wcsstr
+ 
  #include <wchar.h>
  #endif
  
*************** namespace std
*** 157,208 ****
    extern "C" int wcsncmp(const wchar_t*, const wchar_t*, size_t); 
    extern "C" size_t wcsxfrm(wchar_t*, const wchar_t*, size_t); 
  
!   inline const wchar_t*
!   wcschr(const wchar_t* __p, wchar_t __c)
!   { return const_cast<const wchar_t*>(::wcschr(__p, __c)); }
  
    inline wchar_t*
    wcschr(wchar_t* __p, wchar_t __c)
!   { return ::wcschr(const_cast<const wchar_t*>(__p), __c); }
  
    extern "C" size_t wcscspn(const wchar_t*, const wchar_t*); 
    extern "C" size_t wcslen(const wchar_t*); 
  
!   inline const wchar_t*
!   wcspbrk(const wchar_t* __s1, wchar_t* __s2)
!   { return const_cast<const wchar_t*>(::wcspbrk(__s1, __s2)); }
  
    inline wchar_t*
    wcspbrk(wchar_t* __s1, wchar_t* __s2)
!   { return ::wcspbrk(const_cast<const wchar_t*>(__s1), __s2); }
  
!   inline const wchar_t*
!   wcsrchr(const wchar_t* __p, wchar_t __c)
!   { return const_cast<const wchar_t*>(::wcsrchr(__p, __c)); }
  
    inline wchar_t*
    wcsrchr(wchar_t* __p, wchar_t __c)
!   { return ::wcsrchr(const_cast<const wchar_t*>(__p), __c); }
  
    extern "C" size_t wcsspn(const wchar_t*, const wchar_t*); 
  
!   inline const wchar_t*
!   wcsstr(const wchar_t* __s1, wchar_t* __s2)
!   { return const_cast<const wchar_t*>(::wcsstr(__s1, __s2)); }
  
    inline wchar_t*
    wcsstr(wchar_t* __s1, wchar_t* __s2)
!   { return ::wcsstr(const_cast<const wchar_t*>(__s1), __s2); }
  
    extern "C" wchar_t* wcstok(wchar_t*, const wchar_t*, wchar_t**); 
  
!   inline const wchar_t*
!   wmemchr(const wchar_t* __p, wchar_t __c, size_t __n)
!   { return const_cast<wchar_t*>(::wmemchr(__p, __c, __n)); }
  
    inline wchar_t*
    wmemchr(wchar_t* __p, wchar_t __c, size_t __n)
!   { return ::wmemchr(const_cast<const wchar_t*>(__p), __c, __n); }
  
    extern "C" int wmemcmp(const wchar_t*, const wchar_t*, size_t); 
    extern "C" wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t); 
--- 164,210 ----
    extern "C" int wcsncmp(const wchar_t*, const wchar_t*, size_t); 
    extern "C" size_t wcsxfrm(wchar_t*, const wchar_t*, size_t); 
  
!   extern "C" const wchar_t*
!   wcschr(const wchar_t* __p, wchar_t __c);
  
    inline wchar_t*
    wcschr(wchar_t* __p, wchar_t __c)
!   { return const_cast<wchar_t*>(wcschr(const_cast<const wchar_t*>(__p), __c)); }
  
    extern "C" size_t wcscspn(const wchar_t*, const wchar_t*); 
    extern "C" size_t wcslen(const wchar_t*); 
  
!   extern "C" const wchar_t*
!   wcspbrk(const wchar_t* __s1, wchar_t* __s2);
  
    inline wchar_t*
    wcspbrk(wchar_t* __s1, wchar_t* __s2)
!   { return const_cast<wchar_t*>(wcspbrk(const_cast<const wchar_t*>(__s1), __s2)); }
  
!   extern "C" const wchar_t*
!   wcsrchr(const wchar_t* __p, wchar_t __c);
  
    inline wchar_t*
    wcsrchr(wchar_t* __p, wchar_t __c)
!   { return const_cast<wchar_t*>(wcsrchr(const_cast<const wchar_t*>(__p), __c)); }
  
    extern "C" size_t wcsspn(const wchar_t*, const wchar_t*); 
  
!   extern "C" const wchar_t*
!   wcsstr(const wchar_t* __s1, wchar_t* __s2);
  
    inline wchar_t*
    wcsstr(wchar_t* __s1, wchar_t* __s2)
!   { return const_cast<wchar_t*>(wcsstr(const_cast<const wchar_t*>(__s1), __s2)); }
  
    extern "C" wchar_t* wcstok(wchar_t*, const wchar_t*, wchar_t**); 
  
!   extern "C" const wchar_t*
!   wmemchr(const wchar_t* __p, wchar_t __c, size_t __n);
  
    inline wchar_t*
    wmemchr(wchar_t* __p, wchar_t __c, size_t __n)
!   { return static_cast<wchar_t*>(wmemchr(const_cast<const wchar_t*>(__p), __c, __n)); }
  
    extern "C" int wmemcmp(const wchar_t*, const wchar_t*, size_t); 
    extern "C" wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t); 

-- 

Stephen M. Webb
stephen at bregmasoft dot com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]