Created on 1999-05-04.00:00:00 last changed 172 months ago
Rationale:
The current wording in the standard is the result of a difficult compromise that averted delay of the standard. Based on discussions in Tokyo it is clear that there is no still no consensus on stricter wording, so the issue has been closed. It is suggested that users not write code that depends on Koenig lookup of C library functions.
Proposed resolution:
Replace [depr.c.headers] paragraph 2 with:
Each C header, whose name has the form name.h, behaves as if each name placed in the Standard library namespace by the corresponding cname header is also placed within the namespace scope of the namespace std by name.h and is followed by an explicit using-declaration (_namespace.udecl_) in global scope.
[depr.c.headers] paragraph 2 reads:
Each C header, whose name has the form name.h, behaves as if each name placed in the Standard library namespace by the corresponding cname header is also placed within the namespace scope of the namespace std and is followed by an explicit using-declaration (_namespace.udecl_)
I think it should mention the global name space somewhere... Currently, it indicates that name placed in std is also placed in std...
I don't know what is the correct wording. For instance, if struct tm is defined in time.h, ctime declares std::tm. However, the current wording seems ambiguous regarding which of the following would occur for use of both ctime and time.h:
// version 1: namespace std { struct tm { ... }; } using std::tm; // version 2: struct tm { ... }; namespace std { using ::tm; } // version 3: struct tm { ... }; namespace std { struct tm { ... }; }
I think version 1 is intended.
[Kona: The LWG agreed that the wording is not clear. It also agreed that version 1 is intended, version 2 is not equivalent to version 1, and version 3 is clearly not intended. The example below was constructed by Nathan Myers to illustrate why version 2 is not equivalent to version 1.
Although not equivalent, the LWG is unsure if (2) is enough of a problem to be prohibited. Points discussed in favor of allowing (2):
- It may be a convenience to implementors.
- The only cases that fail are structs, of which the C library contains only a few.
]
Example:
#include <time.h> #include <utility> int main() { std::tm * t; make_pair( t, t ); // okay with version 1 due to Koenig lookup // fails with version 2; make_pair not found return 0; }
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg1671 |
2010-10-21 18:28:33 | admin | set | messages: + msg1670 |
1999-05-04 00:00:00 | admin | create |