Subject: Re: [SG10] How closely should our recommendation match clang?
From: John Spicer (jhs_at_[hidden])
Date: 2013-01-25 09:29:10
On Jan 24, 2013, at 7:40 PM, Nelson, Clark wrote:
> We can't ignore clang, as it is the only popular implementation that has done anything systematic about language feature-testing. But what clang has already done about C++11 (i.e. the past) isn't directly applicable to the future; it's only a model. On the other hand, it's very instructive, especially as regards granularity.
> 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.
I have a mild preference for the function-like syntax. If an implementation chooses to define the other style of macros, it is easy to provide a mapping from the function-style to the as a predefined macro, a macro in a header file, or a command-line macro definition.
#define __has_feature(x) __has_feature_##x
#define __has_feature_test 1
static_assert(false, "has test");
static_assert(false, "does not have test");
If the definition of __has_feature(x) is removed, it can be put on the command-line, as in:
CC -"-D__has_feature(x)=__has_feature_##x" t1.c
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).
SG10 list run by firstname.lastname@example.org