Subject: Re: [SG10] How closely should our recommendation match clang?
From: John Spicer (jhs_at_[hidden])
Date: 2013-01-25 11:17:40
On Jan 25, 2013, at 11:44 AM, Nelson, Clark wrote:
>>> To me, the most obvious question is whether testing for the presence
>> of a feature should use a function-like syntax, or just an identifier.
>> From a programming perspective, there's no practical difference between
>> these two alternatives:
>>> On the other hand, if the function-like syntax is used to test for a
>> feature, somehow there has to be a definition of the function-like
>> macro, or simply testing for the feature is likely to be an error. That
>> would either limit the usefulness of feature-testing, or require users
>> to add boilerplate to conditionally define the function-like macro.
>> Whichever form is used, either the compiler or a header is going to need
>> to define the necessary identifiers in order for programs that use them
>> to compile correctly with the desired features.
> That's true only of compilers that actually implement the new features. But a requirement that this function-like macro be supported even by a compiler that doesn't provide any of the new features seems uncomfortably close to placing a conformance requirement on a non-conforming implementation.
As I said, that is easily worked around by a command-line macro definition.
> To me, the function-like macro is just a distraction from the purpose. True, the cost of providing it very small. But I don't see any concrete compensating benefit for even that small cost.
>> Because most existing compilers with C++11 support do not support
>> __has_feature, the function-style is in some ways an advantage in that
>> if you compile code that uses such a feature, you will get an error
>> instead of potentially getting the wrong version of a given piece of
>> code (if the compiler has alignas but not __has_feature).
> But the point of the conditional compilation is presumably that there is a way for the program to do its job without the new feature. A program that is simply written to require the new feature doesn't need conditional compilation at all; it can just try to use the new feature, and fail to compile if it isn't available.
But it will not do the right thing when the feature is present. This can cause bad outcomes because of ODR violations if combined with code from another compiler.
> So I don't see the advantage of writing conditional compilation directives that will cause compilation failure on some implementations.
So that you know that something is being tested for which your implementation does not provide an answer.
> Features mailing list
SG10 list run by firstname.lastname@example.org