[llvm-branch-commits] [cfe-branch] r118572 - in /cfe/branches/Apple/whitney: docs/LanguageExtensions.html lib/Lex/PPMacroExpansion.cpp test/Sema/attr-deprecated.c test/Sema/attr-unavailable-message.c test/Sema/enum.c

Daniel Dunbar daniel at zuster.org
Tue Nov 9 09:32:33 PST 2010


Author: ddunbar
Date: Tue Nov  9 11:32:33 2010
New Revision: 118572

URL: http://llvm.org/viewvc/llvm-project?rev=118572&view=rev
Log:
Merge r118435:
--
Author: John McCall <rjmccall at apple.com>
Date:   Mon Nov 8 19:48:17 2010 +0000

    Document Clang's support for attributes on individual enumerators and
    tweak the documentation for deprecation-with-message.  Provide __has_feature
    tests for both.  rdar://problem/8605692

Modified:
    cfe/branches/Apple/whitney/docs/LanguageExtensions.html
    cfe/branches/Apple/whitney/lib/Lex/PPMacroExpansion.cpp
    cfe/branches/Apple/whitney/test/Sema/attr-deprecated.c
    cfe/branches/Apple/whitney/test/Sema/attr-unavailable-message.c
    cfe/branches/Apple/whitney/test/Sema/enum.c

Modified: cfe/branches/Apple/whitney/docs/LanguageExtensions.html
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/docs/LanguageExtensions.html?rev=118572&r1=118571&r2=118572&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/docs/LanguageExtensions.html (original)
+++ cfe/branches/Apple/whitney/docs/LanguageExtensions.html Tue Nov  9 11:32:33 2010
@@ -23,7 +23,8 @@
 <li><a href="#has_include">Include File Checking Macros</a></li>
 <li><a href="#builtinmacros">Builtin Macros</a></li>
 <li><a href="#vectors">Vectors and Extended Vectors</a></li>
-<li><a href="#deprecated">Deprecated and Unavailable attribute with Message</a></li>
+<li><a href="#deprecated">Messages on <tt>deprecated</tt> and <tt>unavailable</tt> attributes</a></li>
+<li><a href="#attributes-on-enumerators">Attributes on enumerators</a></li>
 <li><a href="#checking_language_features">Checks for Standard Language Features</a></li>
   <ul>
   <li><a href="#cxx_exceptions">C++ exceptions</a></li>
@@ -286,6 +287,7 @@
   c.yw = b;
   return c;
 }
+</pre>
 </blockquote>
 
 <p>Query for this feature with __has_feature(attribute_ext_vector_type).</p>
@@ -293,12 +295,51 @@
 <p>See also <a href="#__builtin_shufflevector">__builtin_shufflevector</a>.</p>
 
 <!-- ======================================================================= -->
-<h2 id="deprecated">Deprecated and Unavailable attribute with Message</h2>
+<h2 id="deprecated">Messages on <tt>deprecated</tt> and <tt>unavailable</tt> Attributes</h2>
 <!-- ======================================================================= -->
 
-<p> Optional string message can be added to Deprecated and Available attributes. </p>
+<p>An optional string message can be added to the <tt>deprecated</tt>
+and <tt>unavailable</tt> attributes.  For example:</p>
+
+<blockquote>
+<pre>void explode(void) __attribute__((deprecated("extremely unsafe!!!")));</pre>
+</blockquote>
+
+<p>If the deprecated or unavailable declaration is used, the message
+will be incorporated into the appropriate diagnostic:</p>
+
+<blockquote>
+<pre>harmless.c:4:3: warning: 'explode' is deprecated: extremely unsafe!!! [-Wdeprecated-declarations]
+  explode();
+  ^</pre>
+</blockquote>
+
+<p>Query for this feature
+with <tt>__has_feature(attribute_deprecated_with_message)</tt>
+and <tt>__has_feature(attribute_unavailable_with_message)</tt>.</p>
+
+<!-- ======================================================================= -->
+<h2 id="attributes-on-enumerators">Attributes on Enumerators</h2>
+<!-- ======================================================================= -->
+
+<p>Clang allows attributes to be written on individual enumerators.
+This allows enumerators to be deprecated, made unavailable, etc.  The
+attribute must appear after the enumerator name and before any
+initializer, like so:</p>
+
+<blockquote>
+<pre>enum OperationMode {
+  OM_Invalid,
+  OM_Normal,
+  OM_Terrified __attribute__((deprecated)),
+  OM_AbortOnError __attribute__((deprecated)) = 4
+};</pre>
+</blockquote>
+
+<p>Attributes on the <tt>enum</tt> declaration do not apply to
+individual enumerators.</p>
 
-<p> Message will be added to deprecated warning or unavailable error if present. </p>
+<p>Query for this feature with <tt>__has_feature(enumerator_attributes)</tt>.</p>
 
 <!-- ======================================================================= -->
 <h2 id="checking_language_features">Checks for Standard Language Features</h2>

Modified: cfe/branches/Apple/whitney/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Lex/PPMacroExpansion.cpp?rev=118572&r1=118571&r2=118572&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Lex/PPMacroExpansion.cpp Tue Nov  9 11:32:33 2010
@@ -521,11 +521,13 @@
            .Case("attribute_analyzer_noreturn", true)
            .Case("attribute_cf_returns_not_retained", true)
            .Case("attribute_cf_returns_retained", true)
+           .Case("attribute_deprecated_with_message", true)
            .Case("attribute_ext_vector_type", true)
            .Case("attribute_ns_returns_not_retained", true)
            .Case("attribute_ns_returns_retained", true)
            .Case("attribute_objc_ivar_unused", true)
            .Case("attribute_overloadable", true)
+           .Case("attribute_unavailable_with_message", true)
            .Case("blocks", LangOpts.Blocks)
            .Case("cxx_attributes", LangOpts.CPlusPlus0x)
            .Case("cxx_auto_type", LangOpts.CPlusPlus0x)
@@ -536,6 +538,7 @@
            .Case("cxx_strong_enums", LangOpts.CPlusPlus0x)
            .Case("cxx_static_assert", LangOpts.CPlusPlus0x)
            .Case("cxx_trailing_return", LangOpts.CPlusPlus0x)
+           .Case("enumerator_attributes", true)
            .Case("objc_nonfragile_abi", LangOpts.ObjCNonFragileABI)
            .Case("objc_weak_class", LangOpts.ObjCNonFragileABI)
            .Case("ownership_holds", true)

Modified: cfe/branches/Apple/whitney/test/Sema/attr-deprecated.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Sema/attr-deprecated.c?rev=118572&r1=118571&r2=118572&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Sema/attr-deprecated.c (original)
+++ cfe/branches/Apple/whitney/test/Sema/attr-deprecated.c Tue Nov  9 11:32:33 2010
@@ -109,3 +109,5 @@
   f = test20_a; // expected-warning {{'test20_a' is deprecated}}
   f = test20_b;
 }
+
+char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];

Modified: cfe/branches/Apple/whitney/test/Sema/attr-unavailable-message.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Sema/attr-unavailable-message.c?rev=118572&r1=118571&r2=118572&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Sema/attr-unavailable-message.c (original)
+++ cfe/branches/Apple/whitney/test/Sema/attr-unavailable-message.c Tue Nov  9 11:32:33 2010
@@ -14,3 +14,5 @@
 
   double (*fp4)(double) = dfoo;  // expected-error {{'dfoo' is unavailable: NO LONGER}}
 }
+
+char test2[__has_feature(attribute_unavailable_with_message) ? 1 : -1];

Modified: cfe/branches/Apple/whitney/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Sema/enum.c?rev=118572&r1=118571&r2=118572&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Sema/enum.c (original)
+++ cfe/branches/Apple/whitney/test/Sema/enum.c Tue Nov  9 11:32:33 2010
@@ -102,3 +102,5 @@
 void PR7911F() {
   switch (PR7911V); // expected-error {{statement requires expression of integer type}}
 }
+
+char test5[__has_feature(enumerator_attributes) ? 1 : -1];





More information about the llvm-branch-commits mailing list