Bug 24012 - [11/12/13/14/15 regression] #define _POSIX_C_SOURCE breaks #include <iostream>
Summary: [11/12/13/14/15 regression] #define _POSIX_C_SOURCE breaks #include <iostream>
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.1.0
: P5 normal
Target Milestone: 11.5
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 24013 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-09-22 15:15 UTC by Gerald Pfeifer
Modified: 2024-04-26 10:28 UTC (History)
3 users (show)

See Also:
Host:
Target: i386-unknown-freebsd5.4
Build:
Known to work:
Known to fail: 4.0.4
Last reconfirmed: 2006-01-29 00:33:12


Attachments
Use dynamic checks for C99 <wchar.h> functions (1.76 KB, patch)
2017-03-28 15:19 UTC, Jonathan Wakely
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gerald Pfeifer 2005-09-22 15:15:51 UTC
The following simple program fails to compile on FreeBSD 5.4:  
  
  #define _POSIX_C_SOURCE 1   
  #include <iostream>   
  
g++ issues the following error message:   
  
  /gcc-current/bin/../lib/gcc/i386-unknown-freebsd5.4/4.1.0/../../../../incl  
ude/c++/4.1.0/cwchar:166:   
error: '::vfwscanf' has not been declared   
  /gcc-current/bin/../lib/gcc/i386-unknown-freebsd5.4/4.1.0/../../../../incl   
ude/c++/4.1.0/cwchar:170:   
error: '::vswscanf' has not been declared   
  /gcc-current/bin/../lib/gcc/i386-unknown-freebsd5.4/4.1.0/../../../../incl   
ude/c++/4.1.0/cwchar:174:   
error: '::vwscanf' has not been declared   
  /gcc-current/bin/../lib/gcc/i386-unknown-freebsd5.4/4.1.0/../../../../incl   
ude/c++/4.1.0/cwchar:191:   
error: '::wcstof' has not been declared   
   
The FreeBSD 5.4 system compiler, which basically is GCC 3.4.2, has the 
same issue.
Comment 1 Andrew Pinski 2005-09-22 15:20:55 UTC
This is a target issue.  The way we work around this on GNU/Linux is that we define _GNU_SOURCE all 
the time.
Comment 2 Andrew Pinski 2005-09-22 15:37:45 UTC
*** Bug 24013 has been marked as a duplicate of this bug. ***
Comment 3 Loren Rittle 2005-09-22 19:20:40 UTC
The better way to fix this IMHO is to mirror how we fixed other conditionally
missing symbols. Add a _DYNAMIC hook, add the support guards in various places
where the HAVE_X guards exist, add a correctly written define in os_defines.h to
describe the OS-level macro used to key the visibility of the "standard"
function or other symbol.  See the current FreeBSD os_defines.h for some examples.

In my further opinion, this is merely a QoI issue (granted, annoying): The user
defining a macro in implementor space may get this type of result.

Regards,
Loren
Comment 4 Gerald Pfeifer 2005-09-24 16:34:26 UTC
Historically, on some systems one had to define _POSIX_C_SOURCE to get at
fileno(), which has been used by code generated by flex() and probably others.
Comment 5 Mark Mitchell 2006-05-25 02:36:21 UTC
Will not be fixed in 4.1.1; adjust target milestone to 4.1.2.
Comment 6 Joseph S. Myers 2008-07-04 20:04:36 UTC
Closing 4.1 branch.
Comment 7 Joseph S. Myers 2009-03-31 18:57:22 UTC
Closing 4.2 branch.
Comment 8 Richard Biener 2009-08-04 12:26:59 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 9 Richard Biener 2010-05-22 18:10:42 UTC
GCC 4.3.5 is being released, adjusting target milestone.
Comment 10 Richard Biener 2011-06-27 12:14:05 UTC
4.3 branch is being closed, moving to 4.4.7 target.
Comment 11 Jakub Jelinek 2012-03-13 12:47:17 UTC
4.4 branch is being closed, moving to 4.5.4 target.
Comment 12 Jakub Jelinek 2013-04-12 15:16:47 UTC
GCC 4.6.4 has been released and the branch has been closed.
Comment 13 Richard Biener 2014-06-12 13:45:35 UTC
The 4.7 branch is being closed, moving target milestone to 4.8.4.
Comment 14 Jonathan Wakely 2014-06-12 14:10:59 UTC
This is not going to get fixed in the current branches, but if I get time later in stage 1 I plan to completely rework how we use feature test macros in libstdc++, so I'm updating the target milestone to 4.10
Comment 15 Jakub Jelinek 2015-04-22 11:58:30 UTC
GCC 5.1 has been released.
Comment 16 Richard Biener 2015-07-16 09:13:00 UTC
GCC 5.2 is being released, adjusting target milestone to 5.3.
Comment 17 Richard Biener 2015-12-04 10:46:25 UTC
GCC 5.3 is being released, adjusting target milestone.
Comment 18 Jonathan Wakely 2015-12-15 11:05:12 UTC
The (fairly large) changes needed to fix this didn't happen for gcc 5, or gcc6, adjusting target milestone.
Comment 19 Jonathan Wakely 2017-03-27 13:01:37 UTC
(In reply to Gerald Pfeifer from comment #4)
> Historically, on some systems one had to define _POSIX_C_SOURCE to get at
> fileno(), which has been used by code generated by flex() and probably
> others.

Yes, but you don't have to define it to 1. If you define _POSIX_C_SOURCE to 199506L or set _XOPEN_SOURCE to 500 then I think the functions we use are available, as well as fileno.
Comment 20 Jonathan Wakely 2017-03-27 13:05:27 UTC
Also, I assume this is only a problem for -std=c++98 or -std=gnu++98, because if the system headers don't declare those functions for C++11 and later dialects then that's a bug in those system headers.
Comment 21 Jonathan Wakely 2017-03-27 13:06:43 UTC
(In reply to Jonathan Wakely from comment #19)
> (In reply to Gerald Pfeifer from comment #4)
> > Historically, on some systems one had to define _POSIX_C_SOURCE to get at
> > fileno(), which has been used by code generated by flex() and probably
> > others.
> 
> Yes, but you don't have to define it to 1. If you define _POSIX_C_SOURCE to
> 199506L or set _XOPEN_SOURCE to 500 then I think the functions we use are
> available, as well as fileno.

Correction: _POSIX_C_SOURCE=200112L or _XOPEN_SOURCE=600 should declare them.
Comment 22 Jonathan Wakely 2017-03-28 15:15:48 UTC
(In reply to Jonathan Wakely from comment #20)
> Also, I assume this is only a problem for -std=c++98 or -std=gnu++98,
> because if the system headers don't declare those functions for C++11 and
> later dialects then that's a bug in those system headers.

That's not true, because we (rather bizarrely) do this:

#if _GLIBCXX_HAVE_WCSTOF
#undef wcstof
#endif

namespace std {
#if _GLIBCXX_HAVE_WCSTOF
using ::wcstof
#endif
}

#if __cplusplus >= 201103L
namespace std {
#if _GLIBCXX_HAVE_WCSTOF
using std::wcstof
#endif
}
#endif

This means we unconditionally try to declare them in namespace std, then for C++11 redeclare std::wcstof as std:wcstof (???).
Comment 23 Jonathan Wakely 2017-03-28 15:19:02 UTC
Created attachment 41068 [details]
Use dynamic checks for C99 <wchar.h> functions

This fixes it and passes the testsuite on GNU/Linux and FreeBSD 11.0-RELEASE.

Even though this bug is a regression, this is too late in the gcc-7 process to make a change like this. I'll commit it early for gcc-8 and backport it if it doesn't cause any problems.
Comment 24 Jonathan Wakely 2017-03-28 17:53:09 UTC
The new tests fail on AIX 7.2:

FAIL: 21_strings/headers/cwchar/24012.cc (test for excess errors)
Excess errors:
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:224: error: '::wcstold' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:233: error: '::wcstoll' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:234: error: '::wcstoull' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:242: error: '__gnu_cxx::wcstold' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:243: error: '__gnu_cxx::wcstoll' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:244: error: '__gnu_cxx::wcstoull' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:268: error: '::wcstof' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:279: error: '::vfwscanf' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:290: error: '::vswscanf' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:300: error: '::vwscanf' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:310: error: '__gnu_cxx::wcstof' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:313: error: '__gnu_cxx::vfwscanf' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:316: error: '__gnu_cxx::vswscanf' has not been declared
/home/jwakely/build/powerpc-ibm-aix7.2.0.0/libstdc++-v3/include/cwchar:319: error: '__gnu_cxx::vwscanf' has not been declared

This isn't caused by the patch though, it always failed, for the same reason as FreeBSD. It doesn't pass with the patch because (unlike the BSDs) there's no dynamic check in config/os/aix/os_defines.h 

It looks like _ISOC99_SOURCE is the relevant macro for AIX. If that's not defined we don't get the C99 functions from <wchar.h>
Comment 25 Jakub Jelinek 2018-05-02 10:09:04 UTC
GCC 8.1 has been released.
Comment 26 Jakub Jelinek 2018-07-26 11:22:17 UTC
GCC 8.2 has been released.
Comment 27 Richard Biener 2019-11-14 07:52:07 UTC
The GCC 7 branch is being closed, re-targeting to GCC 8.4.
Comment 28 Jakub Jelinek 2020-03-04 09:44:15 UTC
GCC 8.4.0 has been released, adjusting target milestone.
Comment 29 Jakub Jelinek 2021-05-14 09:45:34 UTC
GCC 8 branch is being closed.
Comment 30 Richard Biener 2021-06-01 08:04:08 UTC
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
Comment 31 Richard Biener 2022-05-27 09:33:31 UTC
GCC 9 branch is being closed
Comment 32 Jakub Jelinek 2022-06-28 10:29:08 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 33 Richard Biener 2023-07-07 10:28:36 UTC
GCC 10 branch is being closed.