Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2001-10-06 09:14:52


On Saturday, October 6, 2001, at 08:17 AM, Kevlin Henney wrote:

>> Maybe you ought to write up a defect report. It will be easier for
>> the LWG
>> to understand the issue if you boil it down to a very simple piece of
>> code
>> that you want to know is or isn't conforming.
>>
>> Let's see. Something like this:
>>
>> #include <stdexcept>
>>
>> class lock_error : public std::runtime_error
>> {
>> public:
>> lock_error() : std::runtime_error("thread lock error") { }
>> };
>>
>> Is this conforming code? Note the lack of #include <string>,
>> that std::runtime_error() takes a const string& argument, and
>> there is no constructor taking a const char*.
>>
>> Post it on comp.std.c++ with a subject that begins "Defect Report:"
>
> I believe that this issue (between <stdexcept> and <string>) is a known
> problem, although I don't know if it's yet a DR. It has at least been
> mentioned in passing by myself, Howard Hinnant and a couple of others at
> one or other of the ISO meetings in the last year (and the cyclic
> dependency problem was also the basis for a general solution I wrote up
> in http://www.cuj.com/experts/1911/henney.htm).

Martin Sebor has repeatedly tried to get a dr issue going in this
general area (not specifically with <string> and <stdexcept>) and
failed. This issue came up in the hs_conformance reflector prior to the
CUJ Vendor Review article. In that case it did deal specifically with
<string> and <stdexcept>.

I believe the standard should say more about this issue, but I to not
have the standard-eze in hand. Several people have proposed rules, and
I believe that at least an informal consensus may be forming. My
personal opinion, which has been influenced by similar words already
spoken by noted experts, is that the standard should say something like:

> If you explicitly use a standard defined name, then you must explicitly
> include the associated header. Otherwise you do not have to include
> the header, even if you are implicitly referring to said object.

Of course the above "rule" would have to be encoded in standard-eze so
that only high priests are capable of interpreting its true meaning. ;-)

Under this rule, Beman's example would be conforming because it only
implicitly refers to std::string, not explicitly. Thus #include
<string> is not necessary. If the example were changed to:

        lock_error() : std::runtime_error(std::string("thread lock
error")) { }

then #include <string> becomes necessary.

Just my .02.

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk