Bug 27606

Summary: stddef.h has wrong defines. 'mbstate_t' and so on.
Product: Base System Reporter: yakisoba <yakisoba>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.3-STABLE   
Hardware: Any   
OS: Any   

Description yakisoba 2001-05-24 05:40:00 UTC
The <stddef.h> header defines 'wchar_t'.
The <wchar.h> header defines 'mbstate_t' and 'wint_t'.

SUSV2

Fix: 

<stddef.h> -> wchar_t (RELENG_4 and CURRENT)
 <wchar.h>  -> mbstate_t wint_t (CURRENT)
How-To-Repeat:  libstdc++-v3 cat not compiled.
 FreeBSD 4.3-STABLE don't have <wchar.h>. libstdc++-v3 defines
'mbstate_t' in <bits/std_cwchar.h>. This is conflict with <stddef.h>.
Comment 1 ru freebsd_committer freebsd_triage 2001-05-24 12:10:22 UTC
David,

I have verified that ports/devel/stlport builds OK on the
-CURRENT box without patch-cwchar and with stddef.h,v 1.3.
As discussed on IRC, the solution is to back the revision
1.4 out from stddef.h, and to MFC the whole wchar_t stuff.


Cheers,
-- 
Ruslan Ermilov		Oracle Developer/DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 2 David E. O'Brien freebsd_committer freebsd_triage 2001-05-24 20:29:28 UTC
State Changed
From-To: open->closed

These types were added to FreeBSD's stddef.h because they were in the 
NetBSD Citrus branch's stddef.h.  Could someone explain why they were there 
then?
Comment 3 yakisoba 2001-05-26 18:18:22 UTC
 Thank you for committing. And I'm sorry for my rude and poor English.

libstdc++-v3 <bits/std_cwchar.h>
gcc/libstdc++-v3/include/c_std/bits/std_cwchar.h gcc-3_0-branch rev. 1.5.2.2

  // -*- C++ -*- forwarding header.
  
  // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
  // terms of the GNU General Public License as published by the
  // Free Software Foundation; either version 2, or (at your option)
  // any later version.
  
  // This library is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  // GNU General Public License for more details.
  
  // You should have received a copy of the GNU General Public License along
  // with this library; see the file COPYING.  If not, write to the Free
  // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  // USA.
  
  // As a special exception, you may use this file as part of a free software
  // library without restriction.  Specifically, if other files instantiate
  // templates or use macros or inline functions from this file, or you compile
  // this file and link it with other files to produce an executable, this
  // file does not by itself cause the resulting executable to be covered by
  // the GNU General Public License.  This exception does not however
  // invalidate any other reasons why the executable file might be covered by
  // the GNU General Public License.
  
  //
  // ISO C++ 14882: ???
  //
  
  // Note: This is not a conforming implementation.
  
  #ifndef _CPP_CWCHAR
  #define _CPP_CWCHAR 1
  
  #include <bits/c++config.h>
  #include <bits/std_cstddef.h>
  #include <bits/std_cstdio.h>
  #include <bits/std_cstdarg.h>
  
  #if _GLIBCPP_HAVE_WCHAR_H
  // Need to mangle these "C" functions because C++ modifies their signature.
  #define wcschr  __glibcpp_wcschr
  #define wcsbrk  __glibcpp_wcspbrk
  #define wcsrchr  __glibcpp_wcsrchr
  #define wcsstr  __glibcpp_wcsstr
  #define wmemchr  __glibcpp_wmemchr
  
  #pragma GCC system_header
  #include <wchar.h>
  #endif
  
  // Need to do a bit of trickery here with mbstate_t as char_traits
> // assumes it is in wchar.h, regardless of wchar_t specializations.
! #ifndef _GLIBCPP_HAVE_MBSTATE_T
! extern "C" 
! {
!   typedef struct 
!   {
!     int __fill[6];
!   } mbstate_t;
! }
! #endif
  
  ....

 If _GLIBCPP_HAVE_WCHAR_H is 0, _GLIBCPP_HAVE_MBSTATE_T is not defined.
So 'mbstate_t' is defined here.

                 The Single UNIX ® Specification, Version 2
                      Copyright © 1997 The Open Group
     _________________________________________________________________
   
     NAME
    
     stddef.h - standard type definitions
     
     SYNOPSIS
    

#include <stddef.h>

     DESCRIPTION
    
     The <stddef.h> header defines the following:
   NULL
          Null pointer constant.
   offsetof(type, member-designator)
          Integral constant expression of type size_t, the value of which
          is the offset in bytes to the structure member
          (member-designator), from the beginning of its structure
          (type).
          
     The <stddef.h> header defines through typedef:
   ptrdiff_t
          Signed integral type of the result of subtracting two pointers.
   wchar_t
          Integral type whose range of values can represent distinct
          wide-character codes for all members of the largest character
          set specified among the locales supported by the compilation
          environment: the null character has the code value 0 and each
          member of the Portable Character Set has a code value equal to
          its value when used as the lone character in an integer
          character constant.
   size_t
          Unsigned integral type of the result of the sizeof operator.

.....

                 The Single UNIX ® Specification, Version 2
                      Copyright © 1997 The Open Group
     _________________________________________________________________
   
     NAME
    
     wchar.h - wide-character types
     
     SYNOPSIS
    

#include <wchar.h>

     DESCRIPTION
    
     The <wchar.h> header defines the following data types through
   wchar_t
          As described in [1]<stddef.h>.
   wint_t
          An integral type capable of storing any valid value of wchar_t,
          or WEOF.
   wctype_t
          A scalar type of a data object that can hold values which
          represent locale-specific character classification.
   mbstate_t
          An object type other than an array type that can hold the
          conversion state information necessary to convert between
          sequences of (possibly multibyte) characters and
          wide-characters. If a codeset is being used such that an
          mbstate_t needs to preserve more than 2 levels of reserved
          state, the results are unspecified.
   FILE
          As described in <stdio.h>.
   size_t
          As described in <stddef.h>.
          
.....


/*	$NetBSD: basesrc/include/stddef.h,v 1.9 2000/11/10 06:35:45 tshiozak Exp $	*/

/*-
 * Copyright (c) 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)stddef.h	8.1 (Berkeley) 6/2/93
 */

#ifndef _STDDEF_H_
#define _STDDEF_H_

#include <machine/ansi.h>

typedef	_BSD_PTRDIFF_T_	ptrdiff_t;

#ifdef	_BSD_SIZE_T_
typedef	_BSD_SIZE_T_	size_t;
#undef	_BSD_SIZE_T_
#endif

#ifdef	_BSD_WCHAR_T_
typedef	_BSD_WCHAR_T_	wchar_t;
#undef	_BSD_WCHAR_T_
#endif

#include <sys/null.h>

#define	offsetof(type, member)	((size_t)(unsigned long)(&((type *)0)->member))

#endif /* _STDDEF_H_ */

/*	$NetBSD: basesrc/include/wchar.h,v 1.9 2000/12/29 15:26:33 kleink Exp $	*/

/*-
 * Copyright (c)1999 Citrus Project,
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*-
 * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Julian Coleman.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _WCHAR_H_
#define _WCHAR_H_

#include <sys/cdefs.h>
#include <machine/ansi.h>
#include <sys/null.h>

#ifdef	_BSD_WCHAR_T_
typedef	_BSD_WCHAR_T_	wchar_t;
#undef	_BSD_WCHAR_T_
#endif

#ifdef	_BSD_MBSTATE_T_
typedef	_BSD_MBSTATE_T_	mbstate_t;
#undef	_BSD_MBSTATE_T_
#endif

#ifdef	_BSD_WINT_T_
typedef	_BSD_WINT_T_	wint_t;
#undef	_BSD_WINT_T_
#endif

#ifdef	_BSD_SIZE_T_
typedef	_BSD_SIZE_T_	size_t;
#undef	_BSD_SIZE_T_
#endif

#ifndef WEOF
#define	WEOF 	((wint_t)-1)
#endif

.....