Message ID | m2bog69xqx.fsf@igel.home |
---|---|
State | New |
Headers | show |
On Sat, Oct 13, 2012 at 8:51 AM, Andreas Schwab <schwab@linux-m68k.org> wrote: > PR gcov-profile/44728 > * gcov.c (create_file_names): When stripping extension only look > at base name. > diff --git a/gcc/gcov.c b/gcc/gcov.c > index cf26ce1..09831c2 100644 > --- a/gcc/gcov.c > +++ b/gcc/gcov.c > @@ -842,7 +842,7 @@ create_file_names (const char *file_name) > } > > /* Remove the extension. */ > - cptr = strrchr (name, '.'); > + cptr = strrchr (CONST_CAST (char *, lbasename (name)), '.'); > if (cptr) > *cptr = 0; Why do you need the CONST_CAST? strrchr is a standard function and it takes const char * as the first argument. There is other code in gcc that calls strrchr with a const char * argument. This patch is OK without the CONST_CAST. Thanks. Ian
Ian Lance Taylor <iant@google.com> writes: > Why do you need the CONST_CAST? strrchr is a standard function and it > takes const char * as the first argument. There is other code in gcc > that calls strrchr with a const char * argument. strrchr is overloaded as const and non-const in C++. We need the non-const version. Andreas.
On Sat, Oct 13, 2012 at 11:23 AM, Andreas Schwab <schwab@linux-m68k.org> wrote: > Ian Lance Taylor <iant@google.com> writes: > >> Why do you need the CONST_CAST? strrchr is a standard function and it >> takes const char * as the first argument. There is other code in gcc >> that calls strrchr with a const char * argument. > > strrchr is overloaded as const and non-const in C++. We need the > non-const version. Oh yeah. Really we should overload lbasename the same way. Suppose you drop this into include/libiberty.h: #ifdef __cplusplus inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); } #endif I'll preapprove that if it works. Ian
Ian Lance Taylor <iant@google.com> writes: > Suppose you drop this into include/libiberty.h: > > #ifdef __cplusplus > inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); } > #endif That doesn't work: ../../gcc/libcpp/../include/libiberty.h: In function ‘char* lbasename(char*)’: ../../gcc/libcpp/../include/libiberty.h:123:31: error: declaration of C function ‘char* lbasename(char*)’ conflicts with ../../gcc/libcpp/../include/libiberty.h:121:20: error: previous declaration ‘const char* lbasename(const char*)’ here Andreas.
On Sat, Oct 13, 2012 at 1:11 PM, Andreas Schwab <schwab@linux-m68k.org> wrote: > Ian Lance Taylor <iant@google.com> writes: > >> Suppose you drop this into include/libiberty.h: >> >> #ifdef __cplusplus >> inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); } >> #endif > > That doesn't work: > > ../../gcc/libcpp/../include/libiberty.h: In function ‘char* lbasename(char*)’: > ../../gcc/libcpp/../include/libiberty.h:123:31: error: declaration of C function ‘char* lbasename(char*)’ conflicts with > ../../gcc/libcpp/../include/libiberty.h:121:20: error: previous declaration ‘const char* lbasename(const char*)’ here Hmmm, of course. OK, your patch with CONST_CAST is OK. Thanks. Ian
On 10/15/2012 05:00 AM, Ian Lance Taylor wrote: > On Sat, Oct 13, 2012 at 1:11 PM, Andreas Schwab <schwab@linux-m68k.org> wrote: >> Ian Lance Taylor <iant@google.com> writes: >> >>> Suppose you drop this into include/libiberty.h: >>> >>> #ifdef __cplusplus >>> inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); } >>> #endif >> >> That doesn't work: >> >> ../../gcc/libcpp/../include/libiberty.h: In function ‘char* lbasename(char*)’: >> ../../gcc/libcpp/../include/libiberty.h:123:31: error: declaration of C function ‘char* lbasename(char*)’ conflicts with >> ../../gcc/libcpp/../include/libiberty.h:121:20: error: previous declaration ‘const char* lbasename(const char*)’ here > > Hmmm, of course. Wrapping with extern "C++" makes it work: #ifdef __cplusplus extern "C++" { inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); } } #endif > > OK, your patch with CONST_CAST is OK. > > Thanks.
diff --git a/gcc/gcov.c b/gcc/gcov.c index cf26ce1..09831c2 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -842,7 +842,7 @@ create_file_names (const char *file_name) } /* Remove the extension. */ - cptr = strrchr (name, '.'); + cptr = strrchr (CONST_CAST (char *, lbasename (name)), '.'); if (cptr) *cptr = 0;