Title
New <system_error> header leads to name clashes
Status
resolved
Section
[syserr]
Submitter
Daniel Krügler

Created on 2007-06-24.00:00:00 last changed 163 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Fixed by issue 7 of N2422.

Date: 2007-06-24.00:00:00

The most recent state of N2241 as well as the current draft N2284 (section [syserr], p.2) proposes a new enumeration type posix_errno immediatly in the namespace std. One of the enumerators has the name invalid_argument, or fully qualified: std::invalid_argument. This name clashes with the exception type std::invalid_argument, see [std.exceptions]/p.3. This clash makes e.g. the following snippet invalid:

#include <system_error>
#include <stdexcept>

void foo() { throw std::invalid_argument("Don't call us - we call you!"); }

I propose that this enumeration type (and probably the remaining parts of <system_error> as well) should be moved into one additional inner namespace, e.g. sys or system to reduce foreseeable future clashes due to the great number of members that std::posix_errno already contains (Btw.: Why has the already proposed std::sys sub-namespace from N2066 been rejected?). A further clash candidate seems to be std::protocol_error (a reasonable name for an exception related to a std network library, I guess).

Another possible resolution would rely on the proposed strongly typed enums, as described in N2213. But maybe the forbidden implicit conversion to integral types would make these enumerators less attractive in this special case?

History
Date User Action Args
2010-11-19 19:04:45adminsetstatus: nad editorial -> resolved
2010-10-21 18:28:33adminsetmessages: + msg3468
2007-06-24 00:00:00admincreate