PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/external/clang/docs/LanguageExtensions.html

https://gitlab.com/brian0218/rk3066_r-box_android4.2.2_sdk
HTML | 1136 lines | 868 code | 220 blank | 48 comment | 0 complexity | c6663dbc169ae4cdae23cbc378b84036 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
  4. <html>
  5. <head>
  6. <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  7. <title>Clang Language Extensions</title>
  8. <link type="text/css" rel="stylesheet" href="../menu.css">
  9. <link type="text/css" rel="stylesheet" href="../content.css">
  10. <style type="text/css">
  11. td {
  12. vertical-align: top;
  13. }
  14. th { background-color: #ffddaa; }
  15. </style>
  16. </head>
  17. <body>
  18. <!--#include virtual="../menu.html.incl"-->
  19. <div id="content">
  20. <h1>Clang Language Extensions</h1>
  21. <ul>
  22. <li><a href="#intro">Introduction</a></li>
  23. <li><a href="#feature_check">Feature Checking Macros</a></li>
  24. <li><a href="#has_include">Include File Checking Macros</a></li>
  25. <li><a href="#builtinmacros">Builtin Macros</a></li>
  26. <li><a href="#vectors">Vectors and Extended Vectors</a></li>
  27. <li><a href="#deprecated">Messages on <tt>deprecated</tt> and <tt>unavailable</tt> attributes</a></li>
  28. <li><a href="#attributes-on-enumerators">Attributes on enumerators</a></li>
  29. <li><a href="#user_specified_system_framework">'User-Specified' System Frameworks</a></li>
  30. <li><a href="#availability">Availability attribute</a></li>
  31. <li><a href="#checking_language_features">Checks for Standard Language Features</a>
  32. <ul>
  33. <li><a href="#cxx98">C++98</a>
  34. <ul>
  35. <li><a href="#cxx_exceptions">C++ exceptions</a></li>
  36. <li><a href="#cxx_rtti">C++ RTTI</a></li>
  37. </ul></li>
  38. <li><a href="#cxx11">C++11</a>
  39. <ul>
  40. <li><a href="#cxx_access_control_sfinae">C++11 SFINAE includes access control</a></li>
  41. <li><a href="#cxx_alias_templates">C++11 alias templates</a></li>
  42. <li><a href="#cxx_alignas">C++11 alignment specifiers</a></li>
  43. <li><a href="#cxx_attributes">C++11 attributes</a></li>
  44. <li><a href="#cxx_constexpr">C++11 generalized constant expressions</a></li>
  45. <li><a href="#cxx_decltype">C++11 <tt>decltype()</tt></a></li>
  46. <li><a href="#cxx_default_function_template_args">C++11 default template arguments in function templates</a></li>
  47. <li><a href="#cxx_defaulted_functions">C++11 defaulted functions</a></li>
  48. <li><a href="#cxx_delegating_constructor">C++11 delegating constructors</a></li>
  49. <li><a href="#cxx_deleted_functions">C++11 deleted functions</a></li>
  50. <li><a href="#cxx_explicit_conversions">C++11 explicit conversion functions</a></li>
  51. <li><a href="#cxx_generalized_initializers">C++11 generalized initializers</a></li>
  52. <li><a href="#cxx_implicit_moves">C++11 implicit move constructors/assignment operators</a></li>
  53. <li><a href="#cxx_inheriting_constructors">C++11 inheriting constructors</a></li>
  54. <li><a href="#cxx_inline_namespaces">C++11 inline namespaces</a></li>
  55. <li><a href="#cxx_lambdas">C++11 lambdas</a></li>
  56. <li><a href="#cxx_local_type_template_args">C++11 local and unnamed types as template arguments</a></li>
  57. <li><a href="#cxx_noexcept">C++11 noexcept specification</a></li>
  58. <li><a href="#cxx_nonstatic_member_init">C++11 in-class non-static data member initialization</a></li>
  59. <li><a href="#cxx_nullptr">C++11 nullptr</a></li>
  60. <li><a href="#cxx_override_control">C++11 override control</a></li>
  61. <li><a href="#cxx_range_for">C++11 range-based for loop</a></li>
  62. <li><a href="#cxx_raw_string_literals">C++11 raw string literals</a></li>
  63. <li><a href="#cxx_rvalue_references">C++11 rvalue references</a></li>
  64. <li><a href="#cxx_reference_qualified_functions">C++11 reference-qualified functions</a></li>
  65. <li><a href="#cxx_static_assert">C++11 <tt>static_assert()</tt></a></li>
  66. <li><a href="#cxx_auto_type">C++11 type inference</a></li>
  67. <li><a href="#cxx_strong_enums">C++11 strongly-typed enumerations</a></li>
  68. <li><a href="#cxx_trailing_return">C++11 trailing return type</a></li>
  69. <li><a href="#cxx_unicode_literals">C++11 Unicode string literals</a></li>
  70. <li><a href="#cxx_unrestricted_unions">C++11 unrestricted unions</a></li>
  71. <li><a href="#cxx_user_literals">C++11 user-defined literals</a></li>
  72. <li><a href="#cxx_variadic_templates">C++11 variadic templates</a></li>
  73. </ul></li>
  74. <li><a href="#c11">C11</a>
  75. <ul>
  76. <li><a href="#c_alignas">C11 alignment specifiers</a></li>
  77. <li><a href="#c_atomic">C11 atomic operations</a></li>
  78. <li><a href="#c_generic_selections">C11 generic selections</a></li>
  79. <li><a href="#c_static_assert">C11 <tt>_Static_assert()</tt></a></li>
  80. </ul></li>
  81. </ul></li>
  82. <li><a href="#checking_type_traits">Checks for Type Traits</a></li>
  83. <li><a href="#blocks">Blocks</a></li>
  84. <li><a href="#objc_features">Objective-C Features</a>
  85. <ul>
  86. <li><a href="#objc_instancetype">Related result types</a></li>
  87. <li><a href="#objc_arc">Automatic reference counting</a></li>
  88. <li><a href="#objc_fixed_enum">Enumerations with a fixed underlying type</a></li>
  89. <li><a href="#objc_lambdas">Interoperability with C++11 lambdas</a></li>
  90. <li><a href="#objc_object_literals_subscripting">Object Literals and Subscripting</a></li>
  91. </ul>
  92. </li>
  93. <li><a href="#overloading-in-c">Function Overloading in C</a></li>
  94. <li><a href="#complex-list-init">Initializer lists for complex numbers in C</a></li>
  95. <li><a href="#builtins">Builtin Functions</a>
  96. <ul>
  97. <li><a href="#__builtin_readcyclecounter">__builtin_readcyclecounter</a></li>
  98. <li><a href="#__builtin_shufflevector">__builtin_shufflevector</a></li>
  99. <li><a href="#__builtin_unreachable">__builtin_unreachable</a></li>
  100. <li><a href="#__sync_swap">__sync_swap</a></li>
  101. </ul>
  102. </li>
  103. <li><a href="#non-standard-attributes">Non-standard C++11 Attributes</a>
  104. <ul>
  105. <li><a href="#clang__fallthrough">The <tt>clang::fallthrough</tt> attribute</a></li>
  106. </ul>
  107. </li>
  108. <li><a href="#targetspecific">Target-Specific Extensions</a>
  109. <ul>
  110. <li><a href="#x86-specific">X86/X86-64 Language Extensions</a></li>
  111. </ul>
  112. </li>
  113. <li><a href="#analyzerspecific">Static Analysis-Specific Extensions</a></li>
  114. <li><a href="#dynamicanalyzerspecific">Dynamic Analysis-Specific Extensions</a>
  115. <ul>
  116. <li><a href="#address_sanitizer">AddressSanitizer</a></li>
  117. </ul>
  118. </li>
  119. <li><a href="#threadsafety">Thread Safety Annotation Checking</a>
  120. <ul>
  121. <li><a href="#ts_noanal"><tt>no_thread_safety_analysis</tt></a></li>
  122. <li><a href="#ts_lockable"><tt>lockable</tt></a></li>
  123. <li><a href="#ts_scopedlockable"><tt>scoped_lockable</tt></a></li>
  124. <li><a href="#ts_guardedvar"><tt>guarded_var</tt></a></li>
  125. <li><a href="#ts_ptguardedvar"><tt>pt_guarded_var</tt></a></li>
  126. <li><a href="#ts_guardedby"><tt>guarded_by(l)</tt></a></li>
  127. <li><a href="#ts_ptguardedby"><tt>pt_guarded_by(l)</tt></a></li>
  128. <li><a href="#ts_acquiredbefore"><tt>acquired_before(...)</tt></a></li>
  129. <li><a href="#ts_acquiredafter"><tt>acquired_after(...)</tt></a></li>
  130. <li><a href="#ts_elf"><tt>exclusive_lock_function(...)</tt></a></li>
  131. <li><a href="#ts_slf"><tt>shared_lock_function(...)</tt></a></li>
  132. <li><a href="#ts_etf"><tt>exclusive_trylock_function(...)</tt></a></li>
  133. <li><a href="#ts_stf"><tt>shared_trylock_function(...)</tt></a></li>
  134. <li><a href="#ts_uf"><tt>unlock_function(...)</tt></a></li>
  135. <li><a href="#ts_lr"><tt>lock_returned(l)</tt></a></li>
  136. <li><a href="#ts_le"><tt>locks_excluded(...)</tt></a></li>
  137. <li><a href="#ts_elr"><tt>exclusive_locks_required(...)</tt></a></li>
  138. <li><a href="#ts_slr"><tt>shared_locks_required(...)</tt></a></li>
  139. </ul>
  140. </li>
  141. <li><a href="#type_safety">Type Safety Checking</a>
  142. <ul>
  143. <li><a href="#argument_with_type_tag"><tt>argument_with_type_tag(...)</tt></a></li>
  144. <li><a href="#pointer_with_type_tag"><tt>pointer_with_type_tag(...)</tt></a></li>
  145. <li><a href="#type_tag_for_datatype"><tt>type_tag_for_datatype(...)</tt></a></li>
  146. </ul>
  147. </li>
  148. </ul>
  149. <!-- ======================================================================= -->
  150. <h2 id="intro">Introduction</h2>
  151. <!-- ======================================================================= -->
  152. <p>This document describes the language extensions provided by Clang. In
  153. addition to the language extensions listed here, Clang aims to support a broad
  154. range of GCC extensions. Please see the <a
  155. href="http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html">GCC manual</a> for
  156. more information on these extensions.</p>
  157. <!-- ======================================================================= -->
  158. <h2 id="feature_check">Feature Checking Macros</h2>
  159. <!-- ======================================================================= -->
  160. <p>Language extensions can be very useful, but only if you know you can depend
  161. on them. In order to allow fine-grain features checks, we support three builtin
  162. function-like macros. This allows you to directly test for a feature in your
  163. code without having to resort to something like autoconf or fragile "compiler
  164. version checks".</p>
  165. <!-- ======================================================================= -->
  166. <h3><a name="__has_builtin">__has_builtin</a></h3>
  167. <!-- ======================================================================= -->
  168. <p>This function-like macro takes a single identifier argument that is the name
  169. of a builtin function. It evaluates to 1 if the builtin is supported or 0 if
  170. not. It can be used like this:</p>
  171. <blockquote>
  172. <pre>
  173. #ifndef __has_builtin // Optional of course.
  174. #define __has_builtin(x) 0 // Compatibility with non-clang compilers.
  175. #endif
  176. ...
  177. #if __has_builtin(__builtin_trap)
  178. __builtin_trap();
  179. #else
  180. abort();
  181. #endif
  182. ...
  183. </pre>
  184. </blockquote>
  185. <!-- ======================================================================= -->
  186. <h3><a name="__has_feature_extension"> __has_feature and __has_extension</a></h3>
  187. <!-- ======================================================================= -->
  188. <p>These function-like macros take a single identifier argument that is the
  189. name of a feature. <code>__has_feature</code> evaluates to 1 if the feature
  190. is both supported by Clang and standardized in the current language standard
  191. or 0 if not (but see <a href="#has_feature_back_compat">below</a>), while
  192. <code>__has_extension</code> evaluates to 1 if the feature is supported by
  193. Clang in the current language (either as a language extension or a standard
  194. language feature) or 0 if not. They can be used like this:</p>
  195. <blockquote>
  196. <pre>
  197. #ifndef __has_feature // Optional of course.
  198. #define __has_feature(x) 0 // Compatibility with non-clang compilers.
  199. #endif
  200. #ifndef __has_extension
  201. #define __has_extension __has_feature // Compatibility with pre-3.0 compilers.
  202. #endif
  203. ...
  204. #if __has_feature(cxx_rvalue_references)
  205. // This code will only be compiled with the -std=c++11 and -std=gnu++11
  206. // options, because rvalue references are only standardized in C++11.
  207. #endif
  208. #if __has_extension(cxx_rvalue_references)
  209. // This code will be compiled with the -std=c++11, -std=gnu++11, -std=c++98
  210. // and -std=gnu++98 options, because rvalue references are supported as a
  211. // language extension in C++98.
  212. #endif
  213. </pre>
  214. </blockquote>
  215. <p id="has_feature_back_compat">For backwards compatibility reasons,
  216. <code>__has_feature</code> can also be used to test for support for
  217. non-standardized features, i.e. features not prefixed <code>c_</code>,
  218. <code>cxx_</code> or <code>objc_</code>.</p>
  219. <p id="has_feature_for_non_language_features">
  220. Another use of <code>__has_feature</code> is to check for compiler features
  221. not related to the language standard, such as e.g.
  222. <a href="AddressSanitizer.html">AddressSanitizer</a>.
  223. <p>If the <code>-pedantic-errors</code> option is given,
  224. <code>__has_extension</code> is equivalent to <code>__has_feature</code>.</p>
  225. <p>The feature tag is described along with the language feature below.</p>
  226. <p>The feature name or extension name can also be specified with a preceding and
  227. following <code>__</code> (double underscore) to avoid interference from a macro
  228. with the same name. For instance, <code>__cxx_rvalue_references__</code> can be
  229. used instead of <code>cxx_rvalue_references</code>.</p>
  230. <!-- ======================================================================= -->
  231. <h3><a name="__has_attribute">__has_attribute</a></h3>
  232. <!-- ======================================================================= -->
  233. <p>This function-like macro takes a single identifier argument that is the name
  234. of an attribute. It evaluates to 1 if the attribute is supported or 0 if not. It
  235. can be used like this:</p>
  236. <blockquote>
  237. <pre>
  238. #ifndef __has_attribute // Optional of course.
  239. #define __has_attribute(x) 0 // Compatibility with non-clang compilers.
  240. #endif
  241. ...
  242. #if __has_attribute(always_inline)
  243. #define ALWAYS_INLINE __attribute__((always_inline))
  244. #else
  245. #define ALWAYS_INLINE
  246. #endif
  247. ...
  248. </pre>
  249. </blockquote>
  250. <p>The attribute name can also be specified with a preceding and
  251. following <code>__</code> (double underscore) to avoid interference from a macro
  252. with the same name. For instance, <code>__always_inline__</code> can be used
  253. instead of <code>always_inline</code>.</p>
  254. <!-- ======================================================================= -->
  255. <h2 id="has_include">Include File Checking Macros</h2>
  256. <!-- ======================================================================= -->
  257. <p>Not all developments systems have the same include files.
  258. The <a href="#__has_include">__has_include</a> and
  259. <a href="#__has_include_next">__has_include_next</a> macros allow you to
  260. check for the existence of an include file before doing
  261. a possibly failing #include directive.</p>
  262. <!-- ======================================================================= -->
  263. <h3><a name="__has_include">__has_include</a></h3>
  264. <!-- ======================================================================= -->
  265. <p>This function-like macro takes a single file name string argument that
  266. is the name of an include file. It evaluates to 1 if the file can
  267. be found using the include paths, or 0 otherwise:</p>
  268. <blockquote>
  269. <pre>
  270. // Note the two possible file name string formats.
  271. #if __has_include("myinclude.h") &amp;&amp; __has_include(&lt;stdint.h&gt;)
  272. # include "myinclude.h"
  273. #endif
  274. // To avoid problem with non-clang compilers not having this macro.
  275. #if defined(__has_include) &amp;&amp; __has_include("myinclude.h")
  276. # include "myinclude.h"
  277. #endif
  278. </pre>
  279. </blockquote>
  280. <p>To test for this feature, use #if defined(__has_include).</p>
  281. <!-- ======================================================================= -->
  282. <h3><a name="__has_include_next">__has_include_next</a></h3>
  283. <!-- ======================================================================= -->
  284. <p>This function-like macro takes a single file name string argument that
  285. is the name of an include file. It is like __has_include except that it
  286. looks for the second instance of the given file found in the include
  287. paths. It evaluates to 1 if the second instance of the file can
  288. be found using the include paths, or 0 otherwise:</p>
  289. <blockquote>
  290. <pre>
  291. // Note the two possible file name string formats.
  292. #if __has_include_next("myinclude.h") &amp;&amp; __has_include_next(&lt;stdint.h&gt;)
  293. # include_next "myinclude.h"
  294. #endif
  295. // To avoid problem with non-clang compilers not having this macro.
  296. #if defined(__has_include_next) &amp;&amp; __has_include_next("myinclude.h")
  297. # include_next "myinclude.h"
  298. #endif
  299. </pre>
  300. </blockquote>
  301. <p>Note that __has_include_next, like the GNU extension
  302. #include_next directive, is intended for use in headers only,
  303. and will issue a warning if used in the top-level compilation
  304. file. A warning will also be issued if an absolute path
  305. is used in the file argument.</p>
  306. <!-- ======================================================================= -->
  307. <h3><a name="__has_warning">__has_warning</a></h3>
  308. <!-- ======================================================================= -->
  309. <p>This function-like macro takes a string literal that represents a command
  310. line option for a warning and returns true if that is a valid warning
  311. option.</p>
  312. <blockquote>
  313. <pre>
  314. #if __has_warning("-Wformat")
  315. ...
  316. #endif
  317. </pre>
  318. </blockquote>
  319. <!-- ======================================================================= -->
  320. <h2 id="builtinmacros">Builtin Macros</h2>
  321. <!-- ======================================================================= -->
  322. <dl>
  323. <dt><code>__BASE_FILE__</code></dt>
  324. <dd>Defined to a string that contains the name of the main input
  325. file passed to Clang.</dd>
  326. <dt><code>__COUNTER__</code></dt>
  327. <dd>Defined to an integer value that starts at zero and is
  328. incremented each time the <code>__COUNTER__</code> macro is
  329. expanded.</dd>
  330. <dt><code>__INCLUDE_LEVEL__</code></dt>
  331. <dd>Defined to an integral value that is the include depth of the
  332. file currently being translated. For the main file, this value is
  333. zero.</dd>
  334. <dt><code>__TIMESTAMP__</code></dt>
  335. <dd>Defined to the date and time of the last modification of the
  336. current source file.</dd>
  337. <dt><code>__clang__</code></dt>
  338. <dd>Defined when compiling with Clang</dd>
  339. <dt><code>__clang_major__</code></dt>
  340. <dd>Defined to the major marketing version number of Clang (e.g., the
  341. 2 in 2.0.1). Note that marketing version numbers should not be used to
  342. check for language features, as different vendors use different numbering
  343. schemes. Instead, use the <a href="#feature_check">feature checking
  344. macros</a>.</dd>
  345. <dt><code>__clang_minor__</code></dt>
  346. <dd>Defined to the minor version number of Clang (e.g., the 0 in
  347. 2.0.1). Note that marketing version numbers should not be used to
  348. check for language features, as different vendors use different numbering
  349. schemes. Instead, use the <a href="#feature_check">feature checking
  350. macros</a>.</dd>
  351. <dt><code>__clang_patchlevel__</code></dt>
  352. <dd>Defined to the marketing patch level of Clang (e.g., the 1 in 2.0.1).</dd>
  353. <dt><code>__clang_version__</code></dt>
  354. <dd>Defined to a string that captures the Clang marketing version, including
  355. the Subversion tag or revision number, e.g., "1.5 (trunk 102332)".</dd>
  356. </dl>
  357. <!-- ======================================================================= -->
  358. <h2 id="vectors">Vectors and Extended Vectors</h2>
  359. <!-- ======================================================================= -->
  360. <p>Supports the GCC, OpenCL, AltiVec and NEON vector extensions.</p>
  361. <p>OpenCL vector types are created using <tt>ext_vector_type</tt> attribute. It
  362. support for <tt>V.xyzw</tt> syntax and other tidbits as seen in OpenCL. An
  363. example is:</p>
  364. <blockquote>
  365. <pre>
  366. typedef float float4 <b>__attribute__((ext_vector_type(4)))</b>;
  367. typedef float float2 <b>__attribute__((ext_vector_type(2)))</b>;
  368. float4 foo(float2 a, float2 b) {
  369. float4 c;
  370. c.xz = a;
  371. c.yw = b;
  372. return c;
  373. }
  374. </pre>
  375. </blockquote>
  376. <p>Query for this feature with
  377. <tt>__has_extension(attribute_ext_vector_type)</tt>.</p>
  378. <p>Giving <tt>-faltivec</tt> option to clang enables support for AltiVec vector
  379. syntax and functions. For example:</p>
  380. <blockquote>
  381. <pre>
  382. vector float foo(vector int a) {
  383. vector int b;
  384. b = vec_add(a, a) + a;
  385. return (vector float)b;
  386. }
  387. </pre>
  388. </blockquote>
  389. <p>NEON vector types are created using <tt>neon_vector_type</tt> and
  390. <tt>neon_polyvector_type</tt> attributes. For example:</p>
  391. <blockquote>
  392. <pre>
  393. typedef <b>__attribute__((neon_vector_type(8)))</b> int8_t int8x8_t;
  394. typedef <b>__attribute__((neon_polyvector_type(16)))</b> poly8_t poly8x16_t;
  395. int8x8_t foo(int8x8_t a) {
  396. int8x8_t v;
  397. v = a;
  398. return v;
  399. }
  400. </pre>
  401. </blockquote>
  402. <!-- ======================================================================= -->
  403. <h3><a name="vector_literals">Vector Literals</a></h3>
  404. <!-- ======================================================================= -->
  405. <p>Vector literals can be used to create vectors from a set of scalars, or
  406. vectors. Either parentheses or braces form can be used. In the parentheses form
  407. the number of literal values specified must be one, i.e. referring to a scalar
  408. value, or must match the size of the vector type being created. If a single
  409. scalar literal value is specified, the scalar literal value will be replicated
  410. to all the components of the vector type. In the brackets form any number of
  411. literals can be specified. For example:</p>
  412. <blockquote>
  413. <pre>
  414. typedef int v4si __attribute__((__vector_size__(16)));
  415. typedef float float4 __attribute__((ext_vector_type(4)));
  416. typedef float float2 __attribute__((ext_vector_type(2)));
  417. v4si vsi = (v4si){1, 2, 3, 4};
  418. float4 vf = (float4)(1.0f, 2.0f, 3.0f, 4.0f);
  419. vector int vi1 = (vector int)(1); // vi1 will be (1, 1, 1, 1).
  420. vector int vi2 = (vector int){1}; // vi2 will be (1, 0, 0, 0).
  421. vector int vi3 = (vector int)(1, 2); // error
  422. vector int vi4 = (vector int){1, 2}; // vi4 will be (1, 2, 0, 0).
  423. vector int vi5 = (vector int)(1, 2, 3, 4);
  424. float4 vf = (float4)((float2)(1.0f, 2.0f), (float2)(3.0f, 4.0f));
  425. </pre>
  426. </blockquote>
  427. <!-- ======================================================================= -->
  428. <h3><a name="vector_operations">Vector Operations</a></h3>
  429. <!-- ======================================================================= -->
  430. <p>The table below shows the support for each operation by vector extension.
  431. A dash indicates that an operation is not accepted according to a corresponding
  432. specification.</p>
  433. <table width="500" border="1" cellspacing="0">
  434. <tr>
  435. <th>Operator</th>
  436. <th>OpenCL</th>
  437. <th>AltiVec</th>
  438. <th>GCC</th>
  439. <th>NEON</th>
  440. </tr>
  441. <tr>
  442. <td>[]</td>
  443. <td align="center">yes</td>
  444. <td align="center">yes</td>
  445. <td align="center">yes</td>
  446. <td align="center">-</td>
  447. </tr>
  448. <tr>
  449. <td>unary operators +, -</td>
  450. <td align="center">yes</td>
  451. <td align="center">yes</td>
  452. <td align="center">yes</td>
  453. <td align="center">-</td>
  454. </tr>
  455. <tr>
  456. <td>++, --</td>
  457. <td align="center">yes</td>
  458. <td align="center">yes</td>
  459. <td align="center">-</td>
  460. <td align="center">-</td>
  461. </tr>
  462. <tr>
  463. <td>+, -, *, /, %</td>
  464. <td align="center">yes</td>
  465. <td align="center">yes</td>
  466. <td align="center">yes</td>
  467. <td align="center">-</td>
  468. </tr>
  469. <tr>
  470. <td>bitwise operators &, |, ^, ~</td>
  471. <td align="center">yes</td>
  472. <td align="center">yes</td>
  473. <td align="center">yes</td>
  474. <td align="center">-</td>
  475. </tr>
  476. <tr>
  477. <td>&gt&gt, &lt&lt</td>
  478. <td align="center">yes</td>
  479. <td align="center">yes</td>
  480. <td align="center">yes</td>
  481. <td align="center">-</td>
  482. </tr>
  483. <tr>
  484. <td>!, &&,||</td>
  485. <td align="center">no</td>
  486. <td align="center">-</td>
  487. <td align="center">-</td>
  488. <td align="center">-</td>
  489. </tr>
  490. <tr>
  491. <td>==,!=, >, <, >=, <=</td>
  492. <td align="center">yes</td>
  493. <td align="center">yes</td>
  494. <td align="center">-</td>
  495. <td align="center">-</td>
  496. </tr>
  497. <tr>
  498. <td>=</td>
  499. <td align="center">yes</td>
  500. <td align="center">yes</td>
  501. <td align="center">yes</td>
  502. <td align="center">yes</td>
  503. </tr>
  504. <tr>
  505. <td>:?</td>
  506. <td align="center">yes</td>
  507. <td align="center">-</td>
  508. <td align="center">-</td>
  509. <td align="center">-</td>
  510. </tr>
  511. <tr>
  512. <td>sizeof</td>
  513. <td align="center">yes</td>
  514. <td align="center">yes</td>
  515. <td align="center">yes</td>
  516. <td align="center">yes</td>
  517. </tr>
  518. </table>
  519. <p>See also <a href="#__builtin_shufflevector">__builtin_shufflevector</a>.</p>
  520. <!-- ======================================================================= -->
  521. <h2 id="deprecated">Messages on <tt>deprecated</tt> and <tt>unavailable</tt> Attributes</h2>
  522. <!-- ======================================================================= -->
  523. <p>An optional string message can be added to the <tt>deprecated</tt>
  524. and <tt>unavailable</tt> attributes. For example:</p>
  525. <blockquote>
  526. <pre>void explode(void) __attribute__((deprecated("extremely unsafe, use 'combust' instead!!!")));</pre>
  527. </blockquote>
  528. <p>If the deprecated or unavailable declaration is used, the message
  529. will be incorporated into the appropriate diagnostic:</p>
  530. <blockquote>
  531. <pre>harmless.c:4:3: warning: 'explode' is deprecated: extremely unsafe, use 'combust' instead!!!
  532. [-Wdeprecated-declarations]
  533. explode();
  534. ^</pre>
  535. </blockquote>
  536. <p>Query for this feature
  537. with <tt>__has_extension(attribute_deprecated_with_message)</tt>
  538. and <tt>__has_extension(attribute_unavailable_with_message)</tt>.</p>
  539. <!-- ======================================================================= -->
  540. <h2 id="attributes-on-enumerators">Attributes on Enumerators</h2>
  541. <!-- ======================================================================= -->
  542. <p>Clang allows attributes to be written on individual enumerators.
  543. This allows enumerators to be deprecated, made unavailable, etc. The
  544. attribute must appear after the enumerator name and before any
  545. initializer, like so:</p>
  546. <blockquote>
  547. <pre>enum OperationMode {
  548. OM_Invalid,
  549. OM_Normal,
  550. OM_Terrified __attribute__((deprecated)),
  551. OM_AbortOnError __attribute__((deprecated)) = 4
  552. };</pre>
  553. </blockquote>
  554. <p>Attributes on the <tt>enum</tt> declaration do not apply to
  555. individual enumerators.</p>
  556. <p>Query for this feature with <tt>__has_extension(enumerator_attributes)</tt>.</p>
  557. <!-- ======================================================================= -->
  558. <h2 id="user_specified_system_framework">'User-Specified' System Frameworks</h2>
  559. <!-- ======================================================================= -->
  560. <p>Clang provides a mechanism by which frameworks can be built in such a way
  561. that they will always be treated as being 'system frameworks', even if they are
  562. not present in a system framework directory. This can be useful to system
  563. framework developers who want to be able to test building other applications
  564. with development builds of their framework, including the manner in which the
  565. compiler changes warning behavior for system headers.</p>
  566. <p>Framework developers can opt-in to this mechanism by creating a
  567. '.system_framework' file at the top-level of their framework. That is, the
  568. framework should have contents like:</p>
  569. <pre>
  570. .../TestFramework.framework
  571. .../TestFramework.framework/.system_framework
  572. .../TestFramework.framework/Headers
  573. .../TestFramework.framework/Headers/TestFramework.h
  574. ...
  575. </pre>
  576. <p>Clang will treat the presence of this file as an indicator that the framework
  577. should be treated as a system framework, regardless of how it was found in the
  578. framework search path. For consistency, we recommend that such files never be
  579. included in installed versions of the framework.</p>
  580. <!-- ======================================================================= -->
  581. <h2 id="availability">Availability attribute</h2>
  582. <!-- ======================================================================= -->
  583. <p>Clang introduces the <code>availability</code> attribute, which can
  584. be placed on declarations to describe the lifecycle of that
  585. declaration relative to operating system versions. Consider the function declaration for a hypothetical function <code>f</code>:</p>
  586. <pre>
  587. void f(void) __attribute__((availability(macosx,introduced=10.4,deprecated=10.6,obsoleted=10.7)));
  588. </pre>
  589. <p>The availability attribute states that <code>f</code> was introduced in Mac OS X 10.4, deprecated in Mac OS X 10.6, and obsoleted in Mac OS X 10.7. This information is used by Clang to determine when it is safe to use <code>f</code>: for example, if Clang is instructed to compile code for Mac OS X 10.5, a call to <code>f()</code> succeeds. If Clang is instructed to compile code for Mac OS X 10.6, the call succeeds but Clang emits a warning specifying that the function is deprecated. Finally, if Clang is instructed to compile code for Mac OS X 10.7, the call fails because <code>f()</code> is no longer available.</p>
  590. <p>The availablility attribute is a comma-separated list starting with the platform name and then including clauses specifying important milestones in the declaration's lifetime (in any order) along with additional information. Those clauses can be:</p>
  591. <dl>
  592. <dt>introduced=<i>version</i></dt>
  593. <dd>The first version in which this declaration was introduced.</dd>
  594. <dt>deprecated=<i>version</i></dt>
  595. <dd>The first version in which this declaration was deprecated, meaning that users should migrate away from this API.</dd>
  596. <dt>obsoleted=<i>version</i></dt>
  597. <dd>The first version in which this declaration was obsoleted, meaning that it was removed completely and can no longer be used.</dd>
  598. <dt>unavailable</dt>
  599. <dd>This declaration is never available on this platform.</dd>
  600. <dt>message=<i>string-literal</i></dt>
  601. <dd>Additional message text that Clang will provide when emitting a warning or error about use of a deprecated or obsoleted declaration. Useful to direct users to replacement APIs.</dd>
  602. </dl>
  603. <p>Multiple availability attributes can be placed on a declaration, which may correspond to different platforms. Only the availability attribute with the platform corresponding to the target platform will be used; any others will be ignored. If no availability attribute specifies availability for the current target platform, the availability attributes are ignored. Supported platforms are:</p>
  604. <dl>
  605. <dt>ios</dt>
  606. <dd>Apple's iOS operating system. The minimum deployment target is specified by the <code>-mios-version-min=<i>version</i></code> or <code>-miphoneos-version-min=<i>version</i></code> command-line arguments.</dd>
  607. <dt>macosx</dt>
  608. <dd>Apple's Mac OS X operating system. The minimum deployment target is specified by the <code>-mmacosx-version-min=<i>version</i></code> command-line argument.</dd>
  609. </dl>
  610. <p>A declaration can be used even when deploying back to a platform
  611. version prior to when the declaration was introduced. When this
  612. happens, the declaration is <a
  613. href="https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html">weakly
  614. linked</a>, as if the <code>weak_import</code> attribute were added to the declaration. A weakly-linked declaration may or may not be present a run-time, and a program can determine whether the declaration is present by checking whether the address of that declaration is non-NULL.</p>
  615. <!-- ======================================================================= -->
  616. <h2 id="checking_language_features">Checks for Standard Language Features</h2>
  617. <!-- ======================================================================= -->
  618. <p>The <tt>__has_feature</tt> macro can be used to query if certain standard
  619. language features are enabled. The <tt>__has_extension</tt> macro can be used
  620. to query if language features are available as an extension when compiling for
  621. a standard which does not provide them. The features which can be tested are
  622. listed here.</p>
  623. <h3 id="cxx98">C++98</h3>
  624. <p>The features listed below are part of the C++98 standard. These features are
  625. enabled by default when compiling C++ code.</p>
  626. <h4 id="cxx_exceptions">C++ exceptions</h4>
  627. <p>Use <tt>__has_feature(cxx_exceptions)</tt> to determine if C++ exceptions have been enabled. For
  628. example, compiling code with <tt>-fno-exceptions</tt> disables C++ exceptions.</p>
  629. <h4 id="cxx_rtti">C++ RTTI</h4>
  630. <p>Use <tt>__has_feature(cxx_rtti)</tt> to determine if C++ RTTI has been enabled. For example,
  631. compiling code with <tt>-fno-rtti</tt> disables the use of RTTI.</p>
  632. <h3 id="cxx11">C++11</h3>
  633. <p>The features listed below are part of the C++11 standard. As a result, all
  634. these features are enabled with the <tt>-std=c++11</tt> or <tt>-std=gnu++11</tt>
  635. option when compiling C++ code.</p>
  636. <h4 id="cxx_access_control_sfinae">C++11 SFINAE includes access control</h4>
  637. <p>Use <tt>__has_feature(cxx_access_control_sfinae)</tt> or <tt>__has_extension(cxx_access_control_sfinae)</tt> to determine whether access-control errors (e.g., calling a private constructor) are considered to be template argument deduction errors (aka SFINAE errors), per <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1170">C++ DR1170</a>.</p>
  638. <h4 id="cxx_alias_templates">C++11 alias templates</h4>
  639. <p>Use <tt>__has_feature(cxx_alias_templates)</tt> or
  640. <tt>__has_extension(cxx_alias_templates)</tt> to determine if support for
  641. C++11's alias declarations and alias templates is enabled.</p>
  642. <h4 id="cxx_alignas">C++11 alignment specifiers</h4>
  643. <p>Use <tt>__has_feature(cxx_alignas)</tt> or
  644. <tt>__has_extension(cxx_alignas)</tt> to determine if support for alignment
  645. specifiers using <tt>alignas</tt> is enabled.</p>
  646. <h4 id="cxx_attributes">C++11 attributes</h4>
  647. <p>Use <tt>__has_feature(cxx_attributes)</tt> or
  648. <tt>__has_extension(cxx_attributes)</tt> to determine if support for attribute
  649. parsing with C++11's square bracket notation is enabled.</p>
  650. <h4 id="cxx_constexpr">C++11 generalized constant expressions</h4>
  651. <p>Use <tt>__has_feature(cxx_constexpr)</tt> to determine if support
  652. for generalized constant expressions (e.g., <tt>constexpr</tt>) is
  653. enabled.</p>
  654. <h4 id="cxx_decltype">C++11 <tt>decltype()</tt></h4>
  655. <p>Use <tt>__has_feature(cxx_decltype)</tt> or
  656. <tt>__has_extension(cxx_decltype)</tt> to determine if support for the
  657. <tt>decltype()</tt> specifier is enabled. C++11's <tt>decltype</tt>
  658. does not require type-completeness of a function call expression.
  659. Use <tt>__has_feature(cxx_decltype_incomplete_return_types)</tt>
  660. or <tt>__has_extension(cxx_decltype_incomplete_return_types)</tt>
  661. to determine if support for this feature is enabled.</p>
  662. <h4 id="cxx_default_function_template_args">C++11 default template arguments in function templates</h4>
  663. <p>Use <tt>__has_feature(cxx_default_function_template_args)</tt> or
  664. <tt>__has_extension(cxx_default_function_template_args)</tt> to determine
  665. if support for default template arguments in function templates is enabled.</p>
  666. <h4 id="cxx_defaulted_functions">C++11 <tt>default</tt>ed functions</h4>
  667. <p>Use <tt>__has_feature(cxx_defaulted_functions)</tt> or
  668. <tt>__has_extension(cxx_defaulted_functions)</tt> to determine if support for
  669. defaulted function definitions (with <tt>= default</tt>) is enabled.</p>
  670. <h4 id="cxx_delegating_constructors">C++11 delegating constructors</h4>
  671. <p>Use <tt>__has_feature(cxx_delegating_constructors)</tt> to determine if
  672. support for delegating constructors is enabled.</p>
  673. <h4 id="cxx_deleted_functions">C++11 <tt>delete</tt>d functions</h4>
  674. <p>Use <tt>__has_feature(cxx_deleted_functions)</tt> or
  675. <tt>__has_extension(cxx_deleted_functions)</tt> to determine if support for
  676. deleted function definitions (with <tt>= delete</tt>) is enabled.</p>
  677. <h4 id="cxx_explicit_conversions">C++11 explicit conversion functions</h4>
  678. <p>Use <tt>__has_feature(cxx_explicit_conversions)</tt> to determine if support for <tt>explicit</tt> conversion functions is enabled.</p>
  679. <h4 id="cxx_generalized_initializers">C++11 generalized initializers</h4>
  680. <p>Use <tt>__has_feature(cxx_generalized_initializers)</tt> to determine if
  681. support for generalized initializers (using braced lists and
  682. <tt>std::initializer_list</tt>) is enabled.</p>
  683. <h4 id="cxx_implicit_moves">C++11 implicit move constructors/assignment operators</h4>
  684. <p>Use <tt>__has_feature(cxx_implicit_moves)</tt> to determine if Clang will
  685. implicitly generate move constructors and move assignment operators where needed.</p>
  686. <h4 id="cxx_inheriting_constructors">C++11 inheriting constructors</h4>
  687. <p>Use <tt>__has_feature(cxx_inheriting_constructors)</tt> to determine if support for inheriting constructors is enabled. Clang does not currently implement this feature.</p>
  688. <h4 id="cxx_inline_namespaces">C++11 inline namespaces</h4>
  689. <p>Use <tt>__has_feature(cxx_inline_namespaces)</tt> or
  690. <tt>__has_extension(cxx_inline_namespaces)</tt> to determine if support for
  691. inline namespaces is enabled.</p>
  692. <h4 id="cxx_lambdas">C++11 lambdas</h4>
  693. <p>Use <tt>__has_feature(cxx_lambdas)</tt> or
  694. <tt>__has_extension(cxx_lambdas)</tt> to determine if support for lambdas
  695. is enabled. </p>
  696. <h4 id="cxx_local_type_template_args">C++11 local and unnamed types as template arguments</h4>
  697. <p>Use <tt>__has_feature(cxx_local_type_template_args)</tt> or
  698. <tt>__has_extension(cxx_local_type_template_args)</tt> to determine if
  699. support for local and unnamed types as template arguments is enabled.</p>
  700. <h4 id="cxx_noexcept">C++11 noexcept</h4>
  701. <p>Use <tt>__has_feature(cxx_noexcept)</tt> or
  702. <tt>__has_extension(cxx_noexcept)</tt> to determine if support for noexcept
  703. exception specifications is enabled.</p>
  704. <h4 id="cxx_nonstatic_member_init">C++11 in-class non-static data member initialization</h4>
  705. <p>Use <tt>__has_feature(cxx_nonstatic_member_init)</tt> to determine whether in-class initialization of non-static data members is enabled.</p>
  706. <h4 id="cxx_nullptr">C++11 <tt>nullptr</tt></h4>
  707. <p>Use <tt>__has_feature(cxx_nullptr)</tt> or
  708. <tt>__has_extension(cxx_nullptr)</tt> to determine if support for
  709. <tt>nullptr</tt> is enabled.</p>
  710. <h4 id="cxx_override_control">C++11 <tt>override control</tt></h4>
  711. <p>Use <tt>__has_feature(cxx_override_control)</tt> or
  712. <tt>__has_extension(cxx_override_control)</tt> to determine if support for
  713. the override control keywords is enabled.</p>
  714. <h4 id="cxx_reference_qualified_functions">C++11 reference-qualified functions</h4>
  715. <p>Use <tt>__has_feature(cxx_reference_qualified_functions)</tt> or
  716. <tt>__has_extension(cxx_reference_qualified_functions)</tt> to determine
  717. if support for reference-qualified functions (e.g., member functions with
  718. <code>&amp;</code> or <code>&amp;&amp;</code> applied to <code>*this</code>)
  719. is enabled.</p>
  720. <h4 id="cxx_range_for">C++11 range-based <tt>for</tt> loop</h4>
  721. <p>Use <tt>__has_feature(cxx_range_for)</tt> or
  722. <tt>__has_extension(cxx_range_for)</tt> to determine if support for the
  723. range-based for loop is enabled. </p>
  724. <h4 id="cxx_raw_string_literals">C++11 raw string literals</h4>
  725. <p>Use <tt>__has_feature(cxx_raw_string_literals)</tt> to determine if support
  726. for raw string literals (e.g., <tt>R"x(foo\bar)x"</tt>) is enabled.</p>
  727. <h4 id="cxx_rvalue_references">C++11 rvalue references</h4>
  728. <p>Use <tt>__has_feature(cxx_rvalue_references)</tt> or
  729. <tt>__has_extension(cxx_rvalue_references)</tt> to determine if support for
  730. rvalue references is enabled. </p>
  731. <h4 id="cxx_static_assert">C++11 <tt>static_assert()</tt></h4>
  732. <p>Use <tt>__has_feature(cxx_static_assert)</tt> or
  733. <tt>__has_extension(cxx_static_assert)</tt> to determine if support for
  734. compile-time assertions using <tt>static_assert</tt> is enabled.</p>
  735. <h4 id="cxx_auto_type">C++11 type inference</h4>
  736. <p>Use <tt>__has_feature(cxx_auto_type)</tt> or
  737. <tt>__has_extension(cxx_auto_type)</tt> to determine C++11 type inference is
  738. supported using the <tt>auto</tt> specifier. If this is disabled, <tt>auto</tt>
  739. will instead be a storage class specifier, as in C or C++98.</p>
  740. <h4 id="cxx_strong_enums">C++11 strongly typed enumerations</h4>
  741. <p>Use <tt>__has_feature(cxx_strong_enums)</tt> or
  742. <tt>__has_extension(cxx_strong_enums)</tt> to determine if support for
  743. strongly typed, scoped enumerations is enabled.</p>
  744. <h4 id="cxx_trailing_return">C++11 trailing return type</h4>
  745. <p>Use <tt>__has_feature(cxx_trailing_return)</tt> or
  746. <tt>__has_extension(cxx_trailing_return)</tt> to determine if support for the
  747. alternate function declaration syntax with trailing return type is enabled.</p>
  748. <h4 id="cxx_unicode_literals">C++11 Unicode string literals</h4>
  749. <p>Use <tt>__has_feature(cxx_unicode_literals)</tt> to determine if
  750. support for Unicode string literals is enabled.</p>
  751. <h4 id="cxx_unrestricted_unions">C++11 unrestricted unions</h4>
  752. <p>Use <tt>__has_feature(cxx_unrestricted_unions)</tt> to determine if support for unrestricted unions is enabled.</p>
  753. <h4 id="cxx_user_literals">C++11 user-defined literals</h4>
  754. <p>Use <tt>__has_feature(cxx_user_literals)</tt> to determine if support for user-defined literals is enabled.</p>
  755. <h4 id="cxx_variadic_templates">C++11 variadic templates</h4>
  756. <p>Use <tt>__has_feature(cxx_variadic_templates)</tt> or
  757. <tt>__has_extension(cxx_variadic_templates)</tt> to determine if support
  758. for variadic templates is enabled.</p>
  759. <h3 id="c11">C11</h3>
  760. <p>The features listed below are part of the C11 standard. As a result, all
  761. these features are enabled with the <tt>-std=c11</tt> or <tt>-std=gnu11</tt>
  762. option when compiling C code. Additionally, because these features are all
  763. backward-compatible, they are available as extensions in all language modes.</p>
  764. <h4 id="c_alignas">C11 alignment specifiers</h4>
  765. <p>Use <tt>__has_feature(c_alignas)</tt> or <tt>__has_extension(c_alignas)</tt>
  766. to determine if support for alignment specifiers using <tt>_Alignas</tt>
  767. is enabled.</p>
  768. <h4 id="c_atomic">C11 atomic operations</h4>
  769. <p>Use <tt>__has_feature(c_atomic)</tt> or <tt>__has_extension(c_atomic)</tt>
  770. to determine if support for atomic types using <tt>_Atomic</tt> is enabled.
  771. Clang also provides <a href="#__c11_atomic">a set of builtins</a> which can be
  772. used to implement the <tt>&lt;stdatomic.h&gt;</tt> operations on
  773. <tt>_Atomic</tt> types.</p>
  774. <h4 id="c_generic_selections">C11 generic selections</h4>
  775. <p>Use <tt>__has_feature(c_generic_selections)</tt> or
  776. <tt>__has_extension(c_generic_selections)</tt> to determine if support for
  777. generic selections is enabled.</p>
  778. <p>As an extension, the C11 generic selection expression is available in all
  779. languages supported by Clang. The syntax is the same as that given in the
  780. C11 standard.</p>
  781. <p>In C, type compatibility is decided according to the rules given in the
  782. appropriate standard, but in C++, which lacks the type compatibility rules
  783. used in C, types are considered compatible only if they are equivalent.</p>
  784. <h4 id="c_static_assert">C11 <tt>_Static_assert()</tt></h4>
  785. <p>Use <tt>__has_feature(c_static_assert)</tt> or
  786. <tt>__has_extension(c_static_assert)</tt> to determine if support for
  787. compile-time assertions using <tt>_Static_assert</tt> is enabled.</p>
  788. <!-- ======================================================================= -->
  789. <h2 id="checking_type_traits">Checks for Type Traits</h2>
  790. <!-- ======================================================================= -->
  791. <p>Clang supports the <a href="http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html">GNU C++ type traits</a> and a subset of the <a href="http://msdn.microsoft.com/en-us/library/ms177194(v=VS.100).aspx">Microsoft Visual C++ Type traits</a>. For each supported type trait <code>__X</code>, <code>__has_extension(X)</code> indicates the presence of the type trait. For example:
  792. <blockquote>
  793. <pre>
  794. #if __has_extension(is_convertible_to)
  795. template&lt;typename From, typename To&gt;
  796. struct is_convertible_to {
  797. static const bool value = __is_convertible_to(From, To);
  798. };
  799. #else
  800. // Emulate type trait
  801. #endif
  802. </pre>
  803. </blockquote>
  804. <p>The following type traits are supported by Clang:</p>
  805. <ul>
  806. <li><code>__has_nothrow_assign</code> (GNU, Microsoft)</li>
  807. <li><code>__has_nothrow_copy</code> (GNU, Microsoft)</li>
  808. <li><code>__has_nothrow_constructor</code> (GNU, Microsoft)</li>
  809. <li><code>__has_trivial_assign</code> (GNU, Microsoft)</li>
  810. <li><code>__has_trivial_copy</code> (GNU, Microsoft)</li>
  811. <li><code>__has_trivial_constructor</code> (GNU, Microsoft)</li>
  812. <li><code>__has_trivial_destructor</code> (GNU, Microsoft)</li>
  813. <li><code>__has_virtual_destructor</code> (GNU, Microsoft)</li>
  814. <li><code>__is_abstract</code> (GNU, Microsoft)</li>
  815. <li><code>__is_base_of</code> (GNU, Microsoft)</li>
  816. <li><code>__is_class</code> (GNU, Microsoft)</li>
  817. <li><code>__is_convertible_to</code> (Microsoft)</li>
  818. <li><code>__is_empty</code> (GNU, Microsoft)</li>
  819. <li><code>__is_enum</code> (GNU, Microsoft)</li>
  820. <li><code>__is_pod</code> (GNU, Microsoft)</li>
  821. <li><code>__is_polymorphic</code> (GNU, Microsoft)</li>
  822. <li><code>__is_union</code> (GNU, Microsoft)</li>
  823. <li><code>__is_literal(type)</code>: Determines whether the given type is a literal type</li>
  824. <li><code>__is_final</code>: Determines whether the given type is declared with a <code>final</code> class-virt-specifier.</li>
  825. <li><code>__underlying_type(type)</code>: Retrieves the underlying type for a given <code>enum</code> type. This trait is required to implement the C++11 standard library.</li>
  826. <li><code>__is_trivially_assignable(totype, fromtype)</code>: Determines whether a value of type <tt>totype</tt> can be assigned to from a value of type <tt>fromtype</tt> such that no non-trivial functions are called as part of that assignment. This trait is required to implement the C++11 standard library.</li>
  827. <li><code>__is_trivially_constructible(type, argtypes...)</code>: Determines whether a value of type <tt>type</tt> can be direct-initialized with arguments of types <tt>argtypes...</tt> such that no non-trivial functions are called as part of that initialization. This trait is required to implement the C++11 standard library.</li>
  828. </ul>
  829. <!-- ======================================================================= -->
  830. <h2 id="blocks">Blocks</h2>
  831. <!-- ======================================================================= -->
  832. <p>The syntax and high level language feature description is in <a
  833. href="BlockLanguageSpec.txt">BlockLanguageSpec.txt</a>. Implementation and ABI
  834. details for the clang implementation are in <a
  835. href="Block-ABI-Apple.txt">Block-ABI-Apple.txt</a>.</p>
  836. <p>Query for this feature with __has_extension(blocks).</p>
  837. <!-- ======================================================================= -->
  838. <h2 id="objc_features">Objective-C Features</h2>
  839. <!-- ======================================================================= -->
  840. <h3 id="objc_instancetype">Related result types</h3>
  841. <p>According to Cocoa conventions, Objective-C methods with certain names ("init", "alloc", etc.) always return objects that are an instance of the receiving class's type. Such methods are said to have a "related result type", meaning that a message send to one of these methods will have the same static type as an instance of the receiver class. For example, given the following classes:</p>
  842. <blockquote>
  843. <pre>
  844. @interface NSObject
  845. + (id)alloc;
  846. - (id)init;
  847. @end
  848. @interface NSArray : NSObject
  849. @end
  850. </pre>
  851. </blockquote>
  852. <p>and this common initialization pattern</p>
  853. <blockquote>
  854. <pre>
  855. NSArray *array = [[NSArray alloc] init];
  856. </pre>
  857. </blockquote>
  858. <p>the type of the expression <code>[NSArray alloc]</code> is
  859. <code>NSArray*</code> because <code>alloc</code> implicitly has a
  860. related result type. Similarly, the type of the expression
  861. <code>[[NSArray alloc] init]</code> is <code>NSArray*</code>, since
  862. <code>init</code> has a related result type and its receiver is known
  863. to have the type <code>NSArray *</code>. If neither <code>alloc</code> nor <code>init</code> had a related result type, the expressions would have had type <code>id</code>, as declared in the method signature.</p>
  864. <p>A method with a related result type can be declared by using the
  865. type <tt>instancetype</tt> as its result type. <tt>instancetype</tt>
  866. is a contextual keyword that is only permitted in the result type of
  867. an Objective-C method, e.g.</p>
  868. <pre>
  869. @interface A
  870. + (<b>instancetype</b>)constructAnA;
  871. @end
  872. </pre>
  873. <p>The related result type can also be inferred for some methods.
  874. To determine whether a method has an inferred related result type, the first
  875. word in the camel-case selector (e.g., "init" in "initWithObjects") is
  876. considered, and the method will have a related result type if its return
  877. type is compatible with the type of its class and if</p>
  878. <ul>
  879. <li>the first word is "alloc" or "new", and the method is a class
  880. method, or</li>
  881. <li>the first word is "autorelease", "init", "retain", or "self",
  882. and the method is an instance method.</li>
  883. </ul>
  884. <p>If a method with a related result type is overridden by a subclass
  885. method, the subclass method must also return a type that is compatible
  886. with the subclass type. For example:</p>
  887. <blockquote>
  888. <pre>
  889. @interface NSString : NSObject
  890. - (NSUnrelated *)init; // incorrect usage: NSUnrelated is not NSString or a superclass of NSString
  891. @end
  892. </pre>
  893. </blockquote>
  894. <p>Related result types only affect the type of a message send or
  895. property access via the given method. In all other respects, a method
  896. with a related result type is treated the same way as method that
  897. returns <tt>id</tt>.</p>
  898. <p>Use <tt>__has_feature(objc_instancetype)</tt> to determine whether
  899. the <tt>instancetype</tt> contextual keyword is available.</p>
  900. <!-- ======================================================================= -->
  901. <h2 id="objc_arc">Automatic reference counting </h2>
  902. <!-- ======================================================================= -->
  903. <p>Clang provides support for <a href="AutomaticReferenceCounting.html">automated reference counting</a> in Objective-C, which eliminates the need for manual retain/release/autorelease message sends. There are two feature macros associated with automatic reference counting: <code>__has_feature(objc_arc)</code> indicates the availability of automated reference counting in general, while <code>__has_feature(objc_arc_weak)</code> indicates that automated reference counting also includes support for <code>__weak</code> pointers to Objective-C objects.</p>
  904. <!-- ======================================================================= -->
  905. <h2 id="objc_fixed_enum">Enumerations with a fixed underlying type</h2>
  906. <!-- ======================================================================= -->
  907. <p>Clang provides support for C++11 enumerations with a fixed
  908. underlying type within Objective-C. For example, one can write an
  909. enumeration type as:</p>
  910. <pre>
  911. typedef enum : unsigned char { Red, Green, Blue } Color;
  912. </pre>
  913. <p>This specifies that the underlying type, which is used to store the
  914. enumeration value, is <tt>unsigned char</tt>.</p>
  915. <p>Use <tt>__has_feature(objc_fixed_enum)</tt> to determine whether
  916. support for fixed underlying types is available in Objective-C