Bug 1220 - regex uses old-style definitions that cause g++ to fail
Summary: regex uses old-style definitions that cause g++ to fail
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: regex (show other bugs)
Version: 2.3.5
: P2 normal
Target Milestone: ---
Assignee: GOTO Masanori
URL:
Keywords:
Depends on: 1217
Blocks: 1221 1224 1231 1281
  Show dependency treegraph
 
Reported: 2005-08-20 07:26 UTC by Paul Eggert
Modified: 2018-04-19 14:53 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
use function prototypes for definitions (13.07 KB, patch)
2005-08-20 07:26 UTC, Paul Eggert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Eggert 2005-08-20 07:26:04 UTC
regex uses old (K&R) style function definitions, which causes
problems when it is compiled using g++ outside of glibc.  For example:

   g++ -W -Wswitch -Wcomment -Wpointer-arith -Wimplicit -Wreturn-type
-Wno-sign-compare -Wno-invalid-offsetof -g -DUNICODE -I. -I. -I..
-DHAVE_CONFIG_H -c regex.c
   In file included from regex.c:85:
   regex_internal.c:46: error: `reg_errcode_t re_string_allocate' redeclared as
different kind of symbol
   regex_internal.h:383: error: previous declaration of `reg_errcode_t
re_string_allocate(re_string_t*, const char*, int, int, char*, int, const
re_dfa_t*)'

For more details about the g++ problem, please see Sam Steingold's bug report
<http://lists.gnu.org/archive/html/bug-gnulib/2005-08/msg00096.html>.

These days there's no longer any reason for regex to use K&R function
definition syntax, so I'm installing the attached patch into gnulib.  Can you
please propagate this into glibc?  Thanks.
Comment 1 Paul Eggert 2005-08-20 07:26:38 UTC
Created attachment 597 [details]
use function prototypes for definitions
Comment 2 Ulrich Drepper 2005-09-06 18:10:27 UTC
> These days there's no longer any reason for regex to use K&R function
> definition syntax,

Wrong.  Using K&R function definitions ensures that the compiler warns about
missing prototypes.  This is finer grained than a compiler can achieve this.

It is simply wrong to use g++ to compile regex.c.  Period.
Comment 3 Bruno Haible 2006-04-19 17:43:22 UTC
Ulrich Drepper wrote: 
> Using K&R function definitions ensures that the compiler warns about 
> missing prototypes.  This is finer grained than a compiler can achieve this. 
 
Wrong. gcc has two options that warn for missing prototypes, even when ANSI/ISO 
C 
function definitions are used: -Wmissing-prototypes and -Wmissing-declarations. 
 
Look: 
============================== foo.c ========================= 
int foo(int, int); 
int foo (int x, int y) { return x + y; } 
 
int no_prototype (int x, int y) { return x + y; } 
============================================================ 
$ gcc -Wmissing-declarations -c foo.c 
foo.c:4: warning: no previous declaration for `no_prototype' 
$ gcc -Wmissing-prototypes -c foo.c 
foo.c:4: warning: no previous prototype for `no_prototype' 
 
> It is simply wrong to use g++ to compile regex.c.  Period. 
 
Your attitude hampers the reuse of the code in GNU clisp. Saying "Period" 
is not a sound technical argument. I'm therefore reopening this issue. 
 
Comment 4 Ulrich Drepper 2006-04-25 18:01:04 UTC
Stop reopening the bug.  This is all valid C code.  Everybody who misuses the
code is on her/his own.