[cfe-dev] [libcxx] using has_extension instead of has_feature

Jean-Daniel Dupas devlists at shadowlab.org
Fri Aug 12 09:06:42 PDT 2011


Le 12 août 2011 à 17:58, Howard Hinnant a écrit :

> On Aug 12, 2011, at 5:25 AM, Jean-Daniel Dupas wrote:
> 
>> Hello,
>> 
>> I'd like to propose to use __has_extension instead of __has_feature to detect available features in libc++ headers.
>> 
>> Using __has_feature prevent usage of functionalities provided by clang as extension when compiling in older standard mode.
>> 
>> As __has_extension is a superset of __has_feature, it should not have any effect on people using the library in c++0x mode.
>> 
>> And when using -pedantic, __has_extension have the same behavior than __has_feature, so it is always be possible to disable extensions if needed.
>> 
>> Path to perform this change (if accepted) attached.
> 
> Thanks for doing this work.  I was previously ignorant of the difference between __has_feature and __has_extension.
> 
> I surveyed the differences and found only three where this change would actually impact libc++ (using tags/Apple/clang-211.9):
> 
> In C++03 mode the following features are turned on by using __has_extension but not by using __has_feature:
> 
> cxx_rvalue_references
> cxx_reference_qualified_functions
> cxx_deleted_functions

In clang trunk, the HasExtension() method (in Lex/PPMacroExpansion.cpp) defines 5 extensions for C++:

cxx_deleted_functions
cxx_inline_namespaces
cxx_override_control
cxx_reference_qualified_functions
cxx_rvalue_references

Now that I think about it, it may cause problems as if I understand correctly, to properly handle rvalue, you have to support cxx_noexcept too.

> Does clang actually make these features work in C++03?  Or is the syntax merely accepted?

My understanding was that feature defined as extension are fully available, but I may be wrong.

> 
> Howard
> 

-- Jean-Daniel








More information about the cfe-dev mailing list