Bug #3823
closedwchar.h and wctype_iso.h incompatibility
100%
Description
There is an incompatibility in declarations in wchar.h and wctype_iso.h:
functions iswalnum(wint_t), iswalpha(wint_t) and similar are declared in std namespace and global namespace, later they are imported to the global namespace, and this leads to conflict. So, when compiling simple test program with clang (just #include <iostream> and make any test output), you can receive:
/usr/include/wchar.h:142:17: note: conflicting declaration
extern wctype_t wctype(const char *);
^
In file included from test.cc:1:
In file included from /usr/gcc/4.7/include/c++/4.7.3/iostream:39:
In file included from /usr/gcc/4.7/include/c++/4.7.3/ostream:39:
In file included from /usr/gcc/4.7/include/c++/4.7.3/ios:44:
In file included from /usr/gcc/4.7/include/c++/4.7.3/bits/basic_ios.h:38:
In file included from /usr/gcc/4.7/include/c++/4.7.3/bits/locale_facets.h:40:
/usr/gcc/4.7/include/c++/4.7.3/cwctype:87:11: error: target of using
declaration conflicts with declaration already in scope
using ::iswalnum;
Related issues
Updated by Dan McDonald almost 10 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 100
- Tags deleted (
needs-triage)
Integrated:
commit 693e4d84eb49b987c3d66cbcd4b13a5c6e9059bf
Author: Alexander Pyhalov <apyhalov@gmail.com>
Date: Fri Jun 14 10:16:47 2013 +0400
3787 gcc4.7 __cplusplus change incompatibility
3823 wchar.h and wctype_iso.h incompatibility
Reviewed by: Albert Lee <trisk@nexenta.com>
Approved by: Dan McDonald <danmcd@nexenta.com>
Updated by Albert Lee almost 10 years ago
Additional context from the mailing list (the first solution was taken and shown to work):
A number of <wchar.h> function declarations (visible when _XOPEN_SOURCE is defined) appear to be completely redundant. They appear to be a POSIX extension of C at the time they were introduced, hence they are not present in <iso/wchar_iso.h>. They predate the introduction of C99 <wctype.h> which also declares these functions in POSIX-1.2001. In this case the declarations conflict with <iso/wctype_iso.h> because they use the global namespace.
One solution that allows software written for older POSIX versions to still use <wchar.h> alone might be to introduce std namespace scoping for __cplusplus >= 199711L to <wchar.h> (so the declarations are still redundant, but identical). You may also have to add using statements for pre-XPG6 applications that don't also include <wctype.h> to see them in the global namespace though -- not sure if these would conflict. Another solution might be to add a condition for !defined(_XPG6) or _XOPEN_SOURCE - 0 < 600, although there are probably some corner cases for that as well."