From owner-freebsd-bugs@FreeBSD.ORG Mon Dec 4 23:57:06 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 640E316A4D8 for ; Mon, 4 Dec 2006 23:57:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.FreeBSD.org (Postfix) with ESMTP id D416043F22 for ; Mon, 4 Dec 2006 23:49:31 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id kB4No7XM028008 for ; Mon, 4 Dec 2006 23:50:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id kB4No7Aq028007; Mon, 4 Dec 2006 23:50:07 GMT (envelope-from gnats) Resent-Date: Mon, 4 Dec 2006 23:50:07 GMT Resent-Message-Id: <200612042350.kB4No7Aq028007@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Timothy Smith Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id F2B1E16A416 for ; Mon, 4 Dec 2006 23:40:21 +0000 (UTC) (envelope-from tim@mysql.com) Received: from mailgate.mysql.com (mailgate-out2.mysql.com [213.136.52.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0E4A043CEC for ; Mon, 4 Dec 2006 23:37:31 +0000 (GMT) (envelope-from tim@mysql.com) Received: from localhost (localhost.localdomain [127.0.0.1]) by mailgate.mysql.com (8.13.4/8.13.4) with ESMTP id kB4Nc6ZU018957 for ; Tue, 5 Dec 2006 00:38:06 +0100 Received: from mail.mysql.com ([10.222.1.99]) by localhost (mailgate.mysql.com [10.222.1.98]) (amavisd-new, port 10026) with LMTP id 17178-03 for ; Tue, 5 Dec 2006 00:38:05 +0100 (CET) Received: from siva.hindu.god (10-100-64-38.mysql.internal [10.100.64.38]) (authenticated bits=0) by mail.mysql.com (8.13.3/8.13.3) with ESMTP id kB4Nbv4p027731 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 5 Dec 2006 00:38:02 +0100 Received: by siva.hindu.god (Postfix, from userid 1001) id C92995C78; Mon, 4 Dec 2006 16:37:57 -0700 (MST) Message-Id: <20061204233757.C92995C78@siva.hindu.god> Date: Mon, 4 Dec 2006 16:37:57 -0700 (MST) From: Timothy Smith To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/106355: macros in stdio.h non-portable (e.g., C++ ::feof() fails) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Timothy Smith List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Dec 2006 23:57:06 -0000 >Number: 106355 >Category: kern >Synopsis: macros in stdio.h non-portable (e.g., C++ ::feof() fails) >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Dec 04 23:50:06 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Timothy Smith >Release: FreeBSD 6.1-STABLE i386 >Organization: >Environment: System: FreeBSD siva.hindu.god 6.1-STABLE FreeBSD 6.1-STABLE #0: Sun Jun 18 13:23:52 MDT 2006 root@siva.hindu.god:/usr/obj/usr/src/sys/GENERIC i386 >Description: FreeBSD's /usr/include/stdio.h defines a number of macros, such as feof(), fileno(), etc. These are not mentioned in manual pages, and I can't find any reference in POSIX or C standards which allow it. It causes code like the following C++ program to be non-portable. It compiles fine on Solaris, Linux, Windows, OS X. It does fail on HPUX as well, by the way, so FreeBSD isn't alone in using this technique. Perhaps it is allowed by the standard, and the code is non-conformant. does #undef most of these macros. But checking c++ -E -dM output after #include shows that at least fileno() is still defined as a macro that won't allow ::fileno() to succeed: #define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) >How-To-Repeat: cat > fileno.cpp < int main() { return ::feof(stdout); } EOF c++ -g -O -W -Wall fileno.cpp c++ -E -dD fileno.cpp | tail c++ -E -dM | grep -v '^#define _' >Fix: The workaround is obvious. Just don't qualify functions from the standard library as belonging to a namespace. This doesn't work if a class defines feof(), for example, and you need to call the global feof() from inside it. But arguably that's not a smart thing to do in the first place. The other workaround is also obvious: #ifdef feof #undef feof #endif It would be nice if standard library functions, included from , , etc., could be explicitly qualified with the scope operator in C++ code. A test for __cplusplus might do the trick, perhaps something like: #if __cplusplus /* Hmmm, is this a problem for 6-character-unique symbol names? */ inline int __cpp_feof(FILE *p) { return !__isthreaded ? __sfeof(p) : (feof)(p); } #define feof(p) __cpp_feof(p) #else #define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) #endif /* __cplusplus */ Probably something similar could be done for other functions. It might be a good idea to #undef fileno in cstdio as well. >Release-Note: >Audit-Trail: >Unformatted: