Topic: Defect Report: unclear requirement about header inclusion
Author: gennaro.prota@yahoo.com (Gennaro Prota)
Date: Wed, 14 Mar 2007 13:48:35 GMT Raw View
===================================== MODERATOR'S COMMENT:
Forwarded to the C++ committee.
===================================== END OF MODERATOR'S COMMENT
17.4.2.1 [using.headers] states:
A translation unit shall include a header only outside of any
external declaration or definition [...]
I see three problems with this requirement:
a) The C++ standard doesn't define what an "external declaration" or
an "external definition" are (incidentally the C99 standard does, and
has a sentence very similar to the above regarding header inclusion).
I think the intent is that the #include directive shall lexically
appear outside *any* declaration; instead, when the issue was pointed
out on comp.std.c++ at least one poster interpreted "external
declaration" as "declaration of an identifier with external linkage".
If this were the correct interpretation, then the two inclusions below
would be legal:
// at global scope
static void f()
{
# include <cstddef>
}
static void g()
{
# include <stddef.h>
}
(note that while the first example is unlikely to compile correctly,
the second one may well do)
b) as the sentence stands, violations will require a diagnostic; is
this the intent? It was pointed out on comp.std.c++ (by several
posters) that at least one way to ensure a diagnostic exists:
[If there is an actual file for each header,] one simple way
to implement this would be to insert a reserved identifier
such as __begin_header at the start of each standard header.
This reserved identifier would be ignored for all other
purposes, except that, at the appropriate point in phase 7, if
it is found inside an external definition, a diagnostic is
generated. There's many other similar ways to achieve the same
effect.
--James Kuyper, on comp.std.c++
c) is the term "header" meant to be limited to standard headers?
Clause 17 is all about the library, but still the general question is
interesting and affects one of the points in the explicit namespaces
proposal (n1691):
Those seeking to conveniently enable argument-dependent
lookups for all operators within an explicit namespace
could easily create a header file that does so:
namespace mymath::
{
#include "using_ops.hpp"
}
--
Genny.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]