Saturday, December 2, 2017

Digest for comp.lang.c++@googlegroups.com - 4 updates in 2 topics

James Kuyper <jameskuyper@verizon.net>: Dec 02 03:18PM -0500

On 12/01/2017 10:45 PM, Stefan Ram wrote:
> the C++ specification where this is allowed, but I also think
> that the general idea is that there is a general license to
> put names into namespaces and a restriction regarding »::std«.
 
I too take it for granted, I ask only because it has been repeatedly
asserted that ::std is pointless and unnecessary, an assertion which
would only make sense to me if std were a reserved identifier for use as
an namespace name. Basically, the response that I've gotten is that std
is, for practical purposes, a reserved identifier - not because code
which violates such a reservation is a constraint violation, but because
delivering such code is likely to get you fired. While I can appreciate
that argument, it's not directly relevant to my point. If it is indeed
such a bad idea to do that, I think it should be identified as a
constraint violation.
So long as it isn't a constraint violation, fully conforming
implementations must accept and correctly translate code which defines
such a namespace, and I get the impression from some of the things that
have been said, that many implementation of the C++ standard library
might malfunction if used with code that defined such a namespace.
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Dec 02 09:56PM

On Sat, 2 Dec 2017 15:18:47 -0500
> that have been said, that many implementation of the C++ standard
> library might malfunction if used with code that defined such a
> namespace.
 
The C++ standard cannot explicitly rule out every case of bad
programming practice, nor for that matter every possible case of
malicious coding by a psychopathic programmer, if that is what you mean
by "constraint violation". How long do you want the standard to be?
Only an incompetent or malicious programmer would place a 'std'
namespace within another namespace given current coding practices,
which treat 'std' as being at the top level. If a project is so
concerned about this it could put that in its coding standard for the
project, but the idea of using 'std' in this way is so outlandish that
I would view it as unnecessary.
 
Writing code in any language requires programmers to behave reasonably
and in accordance with coding standards for the project in question.
If they try to sabotage the project you fire them. That seems
perfectly reasonable to me.
 
Chris
James Kuyper <jameskuyper@verizon.net>: Dec 02 06:15PM -0500

On 12/02/2017 04:56 PM, Chris Vine wrote:
>>> "James R. Kuyper" <jameskuyper@verizon.net> writes:
>>>> believe it says nothing about, for example, ::kuyper::std. if I'm
>>>> right about that, that's sufficient to allow such a namespace.
...
> programming practice, nor for that matter every possible case of
> malicious coding by a psychopathic programmer, if that is what you mean
> by "constraint violation".
 
I tend to spend most of my time on the C newsgroups; I forgot that
"constraint violation" is a C-specific term. The key feature of a
constraint that matters in this context is that at least one diagnostic
must be issued for any program that contains any syntax errors or
constraint violations, and that either of those features means that is
an implementation is no longer required to accept the program. The C++
standard imposes the same requirements for any violation of any
diagnosable rule (1.4p2). The C standard distinguishes constraints from
other kinds of rules; the C++ standard makes the same distinction by
specifying, for a large number of different rules, that "no diagnostic
is required" - which seems to me to be a clumsier way of making the same
distinction.
Creation of such a namespace is trivially diagnosable, so I'm just
suggesting that a rule be created prohibiting it - if such a rule
accurately represents what the committee believes the standard should say.
 
> How long do you want the standard to be?
 
That's the wrong question. The key point is what a conforming
implementation is required to do. If you believe that a conforming
implementation of the C++ standard library is allowed to use std::
rather than ::std::, even in contexts where such code could break if I
defined a ::kuyper::std namespace, then the standard should explicitly
state, in some fashion, that there's a problem with me defining such a
namespace.
 
If an implementation of the C++ standard library should be required to
use ::std:: whenever my creation of such a namespace might otherwise
cause something to break, the current wording is sufficient.
 
> Only an incompetent or malicious programmer would place a 'std'
 
The standard as currently written implies that every guarantee the
standard makes about the behavior of my program will still hold, even if
I choose to define ::kuyper::std. If my own code doesn't contain any
constructs for which definition of such a namespace is problematic, that
should be sufficient to have a well-formed program, regardless of how
poorly you might think of me for writing it. This implies that any part
of the C++ standard library that I choose to use in my program must also
avoid any use of constructs that would be broken by my definition of
::kuyper::std.
 
> concerned about this it could put that in its coding standard for the
> project, but the idea of using 'std' in this way is so outlandish that
> I would view it as unnecessary.
 
I really don't care how badly you might think of me for writing such
code, and I almost certainly wouldn't write such code. But I still
believe that the standard should be clear about whether or not the C++
standard library is required to be written in such a way that it would
not be broken by such code.
 
> Writing code in any language requires programmers to behave reasonably
> and in accordance with coding standards for the project in question.
 
Actually, no it doesn't. Nothing requires that my program be part of a
project with non-trivial coding standards. All that is actually required
is that the code be, in C++ terms, well-formed, in order to ensure that
it must have the behavior that the relevant standard specifies for such
code. I don't have to be reasonable, and I don't have to conform to
anyone else's coding standards, in order for that requirement to apply.
ram@zedat.fu-berlin.de (Stefan Ram): Dec 02 03:45AM

>believe it says nothing about, for example, ::kuyper::std. if I'm right
>about that, that's sufficient to allow such a namespace.
 
I believe that this has been discussed in the Usenet before
(in this group?) and the common wisdom was then that one may
not put names into »::std«, but into any other namespace »std«.
 
I took this for granted for a long time and am surprised that
you now ask about this. I can't put my finger on a place in
the C++ specification where this is allowed, but I also think
that the general idea is that there is a general license to
put names into namespaces and a restriction regarding »::std«.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: