Bug #3801
open_XOPEN_SOURCE value is ignored if __XOPEN_SOURCE_EXTENDED is set
0%
Description
It seems that a lot of projects define __XOPEN_SOURCE_EXTENDED macros.
When it is tested in <sys/feature_tests.h> the value of __XOPEN_SOURCE is ignored, and we have problems - _XPG5 and _XPG6 macros can't be defined even if __XOPEN_SOURCE is 500 (GCC 3) or 600 (GCC 4).
This breaks wchar headers and can lead to the following error defined int <sys/feature_tests.h>
#error "Compiler or options invalid for pre-UNIX 03 X/Open applications \\
and pre-2001 POSIX applications"
It seems that the following patch solves the problem.
Files
Updated by Rich Lowe over 10 years ago
I think that what the existing code is doing is correct -- just completely unhelpful.
If you look at the comment above the code you changed, XOPEN_SOURCE_EXTENDED is part of saying "XPG4v2", saying that you're both 4.2 _and 5 or 6 is nonsensical, if you care about the standards.
That said, our headers are, almost certainly, way too precise about all of this to be useful but I've long had the suspicion that relaxing them piecemeal could make things worse rather than better. It's likely this would really suck to test.
Updated by Alexander Pyhalov over 10 years ago
Maybe it is a standard behavior, but it breaks G++ 4.7. By default g++ sets _STDC_C99. If someone defines _XOPEN_SOURCE_EXTENDED it breaks the program. Look at the attached test:
Corrected: It's not G++, it's feature_tests itself:
#if STDC_VERSION - 0 >= 199901L
#define _STDC_C99
#endif
$ g++ feature_test.cc -o feature_test
$ ./feature_test
_STDC_C99
_XPG4
_XPG5
_XPG6
_XOPEN_SOURCE=600
$ g++ feature_test.cc -D_XOPEN_SOURCE_EXTENDED -o feature_test_oe
/usr/include/sys/feature_tests.h:351:2: error: #error "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"
Updated by Alexander Pyhalov over 10 years ago
- File feature_test.cc feature_test.cc added
Updated by Alexander Pyhalov over 10 years ago
- File feature_tests_1.patch feature_tests_1.patch added
I've looked through SUSv2 man page. It seems that current behavior is inconsistent with declared one:
SUS (XPG4v2)
The application must define _XOPEN_SOURCE
and set _XOPEN_SOURCE_EXTENDED=1. If
_XOPEN_SOURCE is defined with a value, the
value must be less than 500.
I'm attaching the patch which corrects this.