C++ Logo


Advanced search

Subject: Re: [SG10] How closely should our recommendation match clang?
From: Nelson, Clark (clark.nelson_at_[hidden])
Date: 2013-01-25 10:44:26

> > 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:
> >
> > __has_feature(cxx_alignas)
> > __has_feature_cxx_alignas
> >
> > 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.

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.

So I don't see the advantage of writing conditional compilation directives that will cause compilation failure on some implementations.


SG10 list run by sg10-owner@lists.isocpp.org