[Bug libstdc++/30928] New: add casts to libc overloads

marc dot glisse at normalesup dot org gcc-bugzilla@gcc.gnu.org
Thu Feb 22 18:20:00 GMT 2007


Headers like cwchar add overloads to libc functions. Here I am interested in
the functions for which the standard C version takes a const pointer and
returns a non-const pointer and in C++ this version is replaced by one with
const everywhere and one with no const anywhere. For this, in c_std mode, g++
takes the libc version (instead of the full-const version) and adds an overload
which looks like:

  inline wchar_t*
  wcschr(wchar_t* __p, wchar_t __c)
  { return wcschr(const_cast<const wchar_t*>(__p), __c); }

The const_cast does not look very useful, but that is not the issue (it makes
it easier to understand, which is good). I was wondering whether it would be
acceptable to add a const_cast<wchar_t*> to the returned value? For the current
uses, it would do nothing. But now if a libc decided to provide the full-const
version when called by a c++ compiler, this would make it work.

Is there any real case where it would help? Well if bugs 27340 (trivial) and
30112 get fixed, with the following fixinclude rule, it would be the last thing
preventing from being able to set __cplusplus to either 1 or 199711L with no
testsuite regression (except for breaking the ABI) on solaris (I only checked
with 8). Of course this is only one way to achieve this (not the best one, but
it requires very little patching).

I will understand if you say no, I am just hoping for a "why not? It doesn't
hurt." (remember that in this bug I am only talking about adding some
const_casts, the __cplusplus value is an other issue)

The fixinclude rule, for info (I am not proposing it here, just mentionning it
for completeness)
/*
 *  Remove extern "C++" parts of solaris libc
 */
fix = {
    hackname  = solaris_no_extern_cpp;
    mach     = '*-*-solaris*';
    files     = "iso/ctype_iso.h";
    files     = "iso/limits_iso.h";
    files     = "iso/locale_iso.h";
    files     = "iso/math_iso.h";
    files     = "iso/setjmp_iso.h";
    files     = "iso/signal_iso.h";
    files     = "iso/stdarg_iso.h";
    files     = "iso/stddef_iso.h";
    files     = "iso/stdio_iso.h";
    files     = "iso/stdlib_iso.h";
    files     = "iso/string_iso.h";
    files     = "iso/time_iso.h";
    files     = "iso/wchar_iso.h";
    files     = "iso/wctype_iso.h";
    select    = 'extern[ \t]*"C\+\+"';
    shell     = "perl -e 'undef $/;$_=<>;s/extern[ \t]*\"C\\\+\\\+\"[
\t]*{([^{}]*{[^{}]*})*[^{}]*}//gs;print'";
    test_text = 'extern "C++" {void f();}';
};

(this uses perl, which I think has been part of the system for a very long
time, because I don't know how to do it with sed. I also don't know if the
files field accepts wildcards)


-- 
           Summary: add casts to libc overloads
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: marc dot glisse at normalesup dot org
  GCC host triplet: sparc-sun-solaris2.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30928



More information about the Gcc-bugs mailing list