NetBSD Problem Report #36444

From mlelstv@henery.1st.de  Tue Jun  5 14:29:51 2007
Return-Path: <mlelstv@henery.1st.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id C7D5B63B882
	for <gnats-bugs@gnats.NetBSD.org>; Tue,  5 Jun 2007 14:29:51 +0000 (UTC)
Message-Id: <20070605142932.BA0FF28156@henery.1st.de>
Date: Tue,  5 Jun 2007 16:29:32 +0200 (CEST)
From: mlelstv@serpens.de
Reply-To: mlelstv@serpens.de
To: gnats-bugs@NetBSD.org
Subject: flex generates bad C++ code
X-Send-Pr-Version: 3.95

>Number:         36444
>Category:       bin
>Synopsis:       flex generates bad C++ code
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 05 14:30:01 +0000 2007
>Closed-Date:    Tue May 03 17:57:27 +0000 2016
>Last-Modified:  Tue May 03 17:57:27 +0000 2016
>Originator:     Michael van Elst
>Release:        NetBSD 4.0_BETA2
>Organization:
-- 
                                Michael van Elst
Internet: mlelstv@serpens.de
                                "A potential Snark may lurk in every tree."
>Environment:


System: NetBSD henery 4.0_BETA2 NetBSD 4.0_BETA2 (HENERY) #1: Sun Jun 3 12:09:36 CEST 2007 mlelstv@henery:/home/netbsd4/obj/home/netbsd4/src/sys/arch/i386/compile/HENERY i386
Architecture: i386
Machine: i386
>Description:

When compiling a flex source from the net/irrtoolkit-nox11 package,
I get an error message from the C++ compiler about the ambigous
call to an overloaded function.

>How-To-Repeat:

Here is a test case that shows the problem:

-------- snip --------
%option case-insensitive

%{
#include <cstdio>
#include <cstring>
%}

%%

[A-Z][A-Z0-9]* {
	printf("word = %s\n",yytext);
}

%%

class Object {
public:
	char *contents;
	unsigned long size;
	Object(const char buf[]) {
		contents = strdup(buf);
		size = strlen(buf);
	}
};

int length(const char *s)
{
	return strlen(s);
}

int main() {
	Object *o = new Object("1 Word");
	void *p;
	p = yy_scan_bytes(o->contents, o->size);
	BEGIN(INITIAL);
}

extern "C" {
int yywrap() {
	return 1;
}
}
-------- snip --------

% flex c.l
% % c++ lex.yy.c 
c.l: In function 'int main()':
c.l:34: error: call of overloaded 'yy_scan_bytes(char*&, long unsigned int&)' is ambiguous
lex.yy.c:1321: note: candidates are: yy_buffer_state* yy_scan_bytes(const char*, yy_size_t)
lex.yy.c:1355: note:                 yy_buffer_state* yy_scan_bytes(const char*, int)

The reason for this is a change in src/usr.bin/lex/flex.skl:1.21

| Traditional flex uses int instead of yy_size_t for some api functions.
| Unfortunately this mangles differently in c++, so we get undefined symbols.
| So we define the old function prototype to keep things happy.

This creates function duplicates for C (using yy_size_t) and C++ (using int)
that cause the ambiguity.

>Fix:

Reverting the change in flex.skl:1.21 solves the problem.

>Release-Note:

>Audit-Trail:
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Cc: 
Subject: Re: bin/36444: flex generates bad C++ code
Date: Tue, 5 Jun 2007 10:56:33 -0400

 On Jun 5,  2:30pm, mlelstv@serpens.de (mlelstv@serpens.de) wrote:
 -- Subject: bin/36444: flex generates bad C++ code

 | >Number:         36444
 | >Category:       bin
 | >Synopsis:       flex generates bad C++ code
 | >Confidential:   no
 | >Severity:       serious
 | >Priority:       medium
 | >Responsible:    bin-bug-people
 | >State:          open
 | >Class:          sw-bug
 | >Submitter-Id:   net
 | >Arrival-Date:   Tue Jun 05 14:30:01 +0000 2007
 | >Originator:     Michael van Elst
 | >Release:        NetBSD 4.0_BETA2
 | >Organization:
 | -- 
 |                                 Michael van Elst
 | Internet: mlelstv@serpens.de
 |                                 "A potential Snark may lurk in every tree."
 | >Environment:
 | 	
 | 	
 | System: NetBSD henery 4.0_BETA2 NetBSD 4.0_BETA2 (HENERY) #1: Sun Jun 3 12:09:36 CEST 2007 mlelstv@henery:/home/netbsd4/obj/home/netbsd4/src/sys/arch/i386/compile/HENERY i386
 | Architecture: i386
 | Machine: i386
 | >Description:
 | 
 | When compiling a flex source from the net/irrtoolkit-nox11 package,
 | I get an error message from the C++ compiler about the ambigous
 | call to an overloaded function.
 | 
 | >How-To-Repeat:
 | 
 | Here is a test case that shows the problem:
 | 
 | -------- snip --------
 | %option case-insensitive
 | 
 | %{
 | #include <cstdio>
 | #include <cstring>
 | %}
 | 
 | %%
 | 
 | [A-Z][A-Z0-9]* {
 | 	printf("word = %s\n",yytext);
 | }
 | 
 | %%
 | 
 | class Object {
 | public:
 | 	char *contents;
 | 	unsigned long size;
 | 	Object(const char buf[]) {
 | 		contents = strdup(buf);
 | 		size = strlen(buf);
 | 	}
 | };
 | 
 | int length(const char *s)
 | {
 | 	return strlen(s);
 | }
 | 
 | int main() {
 | 	Object *o = new Object("1 Word");
 | 	void *p;
 | 	p = yy_scan_bytes(o->contents, o->size);
 | 	BEGIN(INITIAL);
 | }
 | 
 | extern "C" {
 | int yywrap() {
 | 	return 1;
 | }
 | }
 | -------- snip --------
 | 
 | % flex c.l
 | % % c++ lex.yy.c 
 | c.l: In function 'int main()':
 | c.l:34: error: call of overloaded 'yy_scan_bytes(char*&, long unsigned int&)' is ambiguous
 | lex.yy.c:1321: note: candidates are: yy_buffer_state* yy_scan_bytes(const char*, yy_size_t)
 | lex.yy.c:1355: note:                 yy_buffer_state* yy_scan_bytes(const char*, int)
 | 
 | The reason for this is a change in src/usr.bin/lex/flex.skl:1.21
 | 
 | | Traditional flex uses int instead of yy_size_t for some api functions.
 | | Unfortunately this mangles differently in c++, so we get undefined symbols.
 | | So we define the old function prototype to keep things happy.
 | 
 | This creates function duplicates for C (using yy_size_t) and C++ (using int)
 | that cause the ambiguity.
 | 
 | >Fix:
 | 
 | Reverting the change in flex.skl:1.21 solves the problem.

 The problem should be fixed by changing:

  	unsigned long size;
 to:
 	yy_size_t size;
 or:
 	int size;
 or even:
 	size_t size;

 We could add a few more yy_scan_bytes() functions so that we have explicit
 matches for unsigned long and long, but it is not worth the trouble. Passing
 a long where an int is expected is not a good practice anyway.

 christos

From: Michael van Elst <mlelstv@serpens.de>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: bin/36444: flex generates bad C++ code
Date: Tue, 5 Jun 2007 17:17:46 +0200

 On Tue, Jun 05, 2007 at 03:00:14PM +0000, Christos Zoulas wrote:
 >  The problem should be fixed by changing:
 >   	unsigned long size;

 This can't be changed, but you can cast the value to yy_size_t
 when passing it to yy_scan_bytes.

 >  We could add a few more yy_scan_bytes() functions so that we have explicit
 >  matches for unsigned long and long, but it is not worth the trouble. Passing
 >  a long where an int is expected is not a good practice anyway.

 What problem is this function overloading trying to solve?

 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: christos@zoulas.com (Christos Zoulas)
To: Michael van Elst <mlelstv@serpens.de>, gnats-bugs@NetBSD.org
Cc: gnats-admin@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: bin/36444: flex generates bad C++ code
Date: Tue, 5 Jun 2007 11:32:57 -0400

 On Jun 5,  5:17pm, mlelstv@serpens.de (Michael van Elst) wrote:
 -- Subject: Re: bin/36444: flex generates bad C++ code

 | On Tue, Jun 05, 2007 at 03:00:14PM +0000, Christos Zoulas wrote:
 | >  The problem should be fixed by changing:
 | >   	unsigned long size;
 | 
 | This can't be changed, but you can cast the value to yy_size_t
 | when passing it to yy_scan_bytes.
 | 
 | >  We could add a few more yy_scan_bytes() functions so that we have explicit
 | >  matches for unsigned long and long, but it is not worth the trouble. Passing
 | >  a long where an int is expected is not a good practice anyway.
 | 
 | What problem is this function overloading trying to solve?

 I forget the exact problem, but it had something to do with buffers being
 yy_size_t internally where some of the flex API's used int to pass values
 to them. This caused problems to another application. I did not want to
 cause an ABI change by s/int/yy_size_t/, so I added the overloading in c++.
 This has not caused a problem until now (when someone passed an unsigned
 long to a function and the overloading could not resolve it).

 christos

From: Patrick Welche <prlw1@cam.ac.uk>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/36444
Date: Tue, 3 May 2016 14:53:52 +0100

 The test above worked for me on -current just now, which is 9 years later,
 so assume expired?

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Tue, 03 May 2016 17:57:27 +0000
State-Changed-Why:
problem has gone away with one or more of several new flex versions since
the PR was filed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.