Project

General

Profile

Actions

Bug #3801

open

_XOPEN_SOURCE value is ignored if __XOPEN_SOURCE_EXTENDED is set

Added by Alexander Pyhalov over 10 years ago. Updated over 10 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
lib - userland libraries
Start date:
2013-06-06
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:
External Bug:

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

feature_tests.patch (456 Bytes) feature_tests.patch Alexander Pyhalov, 2013-06-06 09:38 AM
feature_test.cc (382 Bytes) feature_test.cc Alexander Pyhalov, 2013-06-07 03:09 AM
feature_tests_1.patch (536 Bytes) feature_tests_1.patch Alexander Pyhalov, 2013-06-07 06:03 AM
Actions #1

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.

Actions #2

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"

Actions #4

Updated by Alexander Pyhalov over 10 years ago

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.

Actions

Also available in: Atom PDF