[cfe-commits] r93312 - in /cfe/trunk: docs/LanguageExtensions.html lib/Lex/PPMacroExpansion.cpp test/Lexer/has_feature_cxx0x.cpp

Sean Hunt rideau3 at gmail.com
Wed Jan 13 00:31:50 PST 2010


Author: coppro
Date: Wed Jan 13 02:31:49 2010
New Revision: 93312

URL: http://llvm.org/viewvc/llvm-project?rev=93312&view=rev
Log:
Add a bunch more feature-checking macros for C++0x features. Some of these are
disabled with the intent that users can start with them now and not have to change
a thing to have them work when we implement the features.


Added:
    cfe/trunk/test/Lexer/has_feature_cxx0x.cpp
Modified:
    cfe/trunk/docs/LanguageExtensions.html
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Modified: cfe/trunk/docs/LanguageExtensions.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.html?rev=93312&r1=93311&r2=93312&view=diff

==============================================================================
--- cfe/trunk/docs/LanguageExtensions.html (original)
+++ cfe/trunk/docs/LanguageExtensions.html Wed Jan 13 02:31:49 2010
@@ -28,6 +28,19 @@
   <li><a href="#cxx_exceptions">C++ exceptions</a></li>
   <li><a href="#cxx_rtti">C++ RTTI</a></li>
   </ul>
+<li><a href="#checking_upcoming_features">Checks for Upcoming Standard Language Features</a></li>
+  <ul>
+  <li><a href="#cxx_attributes">C++0x attributes</a></li>
+  <li><a href="#cxx_decltype">C++0x <tt>decltype()</tt></a></li>
+  <li><a href="#cxx_deleted_functions">C++0x deleted functions</a></li>
+  <li><a href="#cxx_concepts">C++ TR concepts</a></li>
+  <li><a href="#cxx_lambdas">C++0x lambdas</a></li>
+  <li><a href="#cxx_nullptr">C++0x nullptr</a></li>
+  <li><a href="#cxx_rvalue_references">C++0x rvalue references</a></li>
+  <li><a href="#cxx_static_assert">C++0x <tt>static_assert()</tt></a></li>
+  <li><a href="#cxx_auto_type">C++0x type inference</a></li>
+  <li><a href="#cxx_variadic_templates">C++0x variadic templates</a></li>
+  </ul>
 <li><a href="#blocks">Blocks</a></li>
 <li><a href="#overloading-in-c">Function Overloading in C</a></li>
 <li><a href="#builtins">Builtin Functions</a>
@@ -216,6 +229,70 @@
 compiling code with <tt>-fno-rtti</tt> disables the use of RTTI.</p>
 
 <!-- ======================================================================= -->
+<h2 id="checking_upcoming_features">Checks for Upcoming Standard Language Features</h2>
+<!-- ======================================================================= -->
+
+<p>The <tt>__has_feature</tt> macro can be used to query if certain upcoming
+standard language features are enabled.  Those features are listed here.</p>
+
+<p>Currently, all features listed here are slated for inclusion in the upcoming
+C++0x standard. As a result, all the features that clang supports are enabled
+with the <tt>-std=c++0x</tt> option when compiling C++ code. Features that are
+not yet implemented will be noted.</p>
+
+<h3 id="cxx_decltype">C++0x <tt>decltype()</tt></h3>
+
+<p>Use <tt>__has_feature(cxx_decltype)</tt> to determine if support for the
+<tt>decltype()</tt> specifier is enabled.</p>
+
+<h3 id="cxx_attributes">C++0x attributes</h3>
+
+<p>Use <tt>__has_feature(cxx_attributes)</tt> to determine if support for
+attribute parsing with C++0x's square bracket notation is enabled.
+
+<h3 id="cxx_deleted_functions">C++0x deleted functions</tt></h3>
+
+<p>Use <tt>__has_feature(cxx_deleted_functions)</tt> to determine if support for
+deleted function definitions (with <tt>= delete</tt>) is enabled.
+
+<h3 id="cxx_concepts">C++ TR <tt>concepts</tt></h3>
+
+<p>Use <tt>__has_feature(cxx_lambdas)</tt> to determine if support for
+concepts is enabled. clang does not currently implement this feature.
+
+<h3 id="cxx_lambdas">C++0x <tt>nullptr</tt></h3>
+
+<p>Use <tt>__has_feature(cxx_lambdas)</tt> to determine if support for
+lambdas is enabled. clang does not currently implement this feature.
+
+<h3 id="cxx_nullptr">C++0x <tt>nullptr</tt></h3>
+
+<p>Use <tt>__has_feature(cxx_nullptr)</tt> to determine if support for
+<tt>nullptr</tt> is enabled. clang does not yet fully implement this feature.
+
+<h3 id="cxx_rvalue_references">C++0x rvalue references</tt></h3>
+
+<p>Use <tt>__has_feature(cxx_rvalue_references)</tt> to determine if support for
+rvalue references is enabled. clang does not yet fully implement this feature.
+
+<h3 id="cxx_static_assert">C++0x <tt>static_assert()</tt></h3>
+
+<p>Use <tt>__has_feature(cxx_static_assert)</tt> to determine if support for
+compile-time assertions using <tt>static_assert</tt> is enabled.</p>
+
+<h3 id="cxx_auto_type">C++0x type inference</h3>
+
+<p>Use <tt>__has_feature(cxx_auto_type)</tt> to determine C++0x type inference
+is supported using the <tt>auto</tt> specifier. If this is disabled,
+<tt>auto</tt> will instead be a storage class specifier, as in C or C++98.</p>
+
+<h3 id="cxx_variadic_templates">C++0x variadic templates</tt></h3>
+
+<p>Use <tt>__has_feature(cxx_variadic_templates)</tt> to determine if support
+for templates taking any number of arguments with the ellipsis notation is
+enabled. clang does not yet fully implement this feature.</p>
+
+<!-- ======================================================================= -->
 <h2 id="blocks">Blocks</h2>
 <!-- ======================================================================= -->
 

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=93312&r1=93311&r2=93312&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Wed Jan 13 02:31:49 2010
@@ -485,9 +485,19 @@
   return llvm::StringSwitch<bool>(II->getName())
            .Case("blocks", LangOpts.Blocks)
            .Case("cxx_rtti", LangOpts.RTTI)
+         //.Case("cxx_lambdas", false)
+         //.Case("cxx_nullptr", false)
+         //.Case("cxx_concepts", false)
+           .Case("cxx_decltype", LangOpts.CPlusPlus0x)
+           .Case("cxx_auto_type", LangOpts.CPlusPlus0x)
            .Case("cxx_exceptions", LangOpts.Exceptions)
+           .Case("cxx_attributes", LangOpts.CPlusPlus0x)
+           .Case("cxx_static_assert", LangOpts.CPlusPlus0x)
            .Case("objc_nonfragile_abi", LangOpts.ObjCNonFragileABI)
+           .Case("cxx_deleted_functions", LangOpts.CPlusPlus0x)
+         //.Case("cxx_rvalue_references", false)
            .Case("attribute_overloadable", true)
+         //.Case("cxx_variadic_templates", false)
            .Case("attribute_ext_vector_type", true)
            .Case("attribute_analyzer_noreturn", true)
            .Case("attribute_ns_returns_retained", true)

Added: cfe/trunk/test/Lexer/has_feature_cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/has_feature_cxx0x.cpp?rev=93312&view=auto

==============================================================================
--- cfe/trunk/test/Lexer/has_feature_cxx0x.cpp (added)
+++ cfe/trunk/test/Lexer/has_feature_cxx0x.cpp Wed Jan 13 02:31:49 2010
@@ -0,0 +1,101 @@
+// RUN: %clang -E -std=c++0x %s -o - | FileCheck --check-prefix=CHECK-0X %s
+// RUN: %clang -E %s -o - | FileCheck --check-prefix=CHECK-NO-0X %s
+
+#if __has_feature(cxx_lambdas)
+int lambdas();
+#else
+int no_lambdas();
+#endif
+
+// CHECK-0X: no_lambdas
+// CHECK-NO-0X: no_lambdas
+
+
+#if __has_feature(cxx_nullptr)
+int nullptr();
+#else
+int no_nullptr();
+#endif
+
+// CHECK-0X: no_nullptr
+// CHECK-NO-0X: no_nullptr
+
+
+#if __has_feature(cxx_concepts)
+int concepts();
+#else
+int no_concepts();
+#endif
+
+// CHECK-0X: no_concepts
+// CHECK-NO-0X: no_concepts
+
+
+#if __has_feature(cxx_decltype)
+int decltype();
+#else
+int no_decltype();
+#endif
+
+// CHECK-0X: decltype
+// CHECK-NO-0X: no_decltype
+
+
+#if __has_feature(cxx_auto_type)
+int auto_type();
+#else
+int no_auto_type();
+#endif
+
+// CHECK-0X: auto_type
+// CHECK-NO-0X: no_auto_type
+
+
+#if __has_feature(cxx_attributes)
+int attributes();
+#else
+int no_attributes();
+#endif
+
+// CHECK-0X: attributes
+// CHECK-NO-0X: no_attributes
+
+
+#if __has_feature(cxx_static_assert)
+int static_assert();
+#else
+int no_static_assert();
+#endif
+
+// CHECK-0X: static_assert
+// CHECK-NO-0X: no_static_assert
+
+
+#if __has_feature(cxx_deleted_functions)
+int deleted_functions();
+#else
+int no_deleted_functions();
+#endif
+
+// CHECK-0X: deleted_functions
+// CHECK-NO-0X: no_deleted_functions
+
+
+#if __has_feature(cxx_rvalue_references)
+int rvalue_references();
+#else
+int no_rvalue_references();
+#endif
+
+// CHECK-0X: no_rvalue_references
+// CHECK-NO-0X: no_rvalue_references
+
+
+#if __has_feature(cxx_variadic_templates)
+int variadic_templates();
+#else
+int no_variadic_templates();
+#endif
+
+// CHECK-0X: no_variadic_templates
+// CHECK-NO-0X: no_variadic_templates





More information about the cfe-commits mailing list