Bug #3823

wchar.h and wctype_iso.h incompatibility

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

Status:ResolvedStart date:2013-06-18
Priority:NormalDue date:
Assignee:Alexander Pyhalov% Done:

100%

Category:lib - userland libraries
Target version:-
Difficulty:Medium Tags:c++, posix

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

Related to illumos gate - Bug #3787: gcc4.7 __cplusplus change incompatibility Resolved 2013-05-25

History

#1 Updated by Dan McDonald over 4 years ago

  • Tags deleted (needs-triage)
  • % Done changed from 0 to 100
  • Status changed from New to Resolved

Integrated:

commit 693e4d84eb49b987c3d66cbcd4b13a5c6e9059bf
Author: Alexander Pyhalov <>
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 &lt;&gt;
Approved by: Dan McDonald &lt;&gt;

#2 Updated by Albert Lee over 4 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."

#3 Updated by Albert Lee over 4 years ago

  • Tags set to c++, posix

Also available in: Atom