r195888 - Add support for C++'s SD6 feature test macros.
Richard Smith
richard-llvm at metafoo.co.uk
Wed Nov 27 14:58:17 PST 2013
Author: rsmith
Date: Wed Nov 27 16:58:16 2013
New Revision: 195888
URL: http://llvm.org/viewvc/llvm-project?rev=195888&view=rev
Log:
Add support for C++'s SD6 feature test macros.
Added:
cfe/trunk/test/Lexer/cxx-features.cpp
Modified:
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/www/cxx_status.html
Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=195888&r1=195887&r2=195888&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Wed Nov 27 16:58:16 2013
@@ -346,6 +346,38 @@ static void InitializeStandardPredefined
Builder.defineMacro("__ASSEMBLER__");
}
+/// Initialize the predefined C++ language feature test macros defined in
+/// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations".
+static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
+ MacroBuilder &Builder) {
+ // C++11 features.
+ if (LangOpts.CPlusPlus11) {
+ Builder.defineMacro("__cpp_unicode_characters", "200704");
+ Builder.defineMacro("__cpp_raw_strings", "200710");
+ Builder.defineMacro("__cpp_unicode_literals", "200710");
+ Builder.defineMacro("__cpp_user_defined_literals", "200809");
+ Builder.defineMacro("__cpp_lambdas", "200907");
+ Builder.defineMacro("__cpp_constexpr",
+ LangOpts.CPlusPlus1y ? "201304" : "200704");
+ Builder.defineMacro("__cpp_static_assert", "200410");
+ Builder.defineMacro("__cpp_decltype", "200707");
+ Builder.defineMacro("__cpp_attributes", "200809");
+ Builder.defineMacro("__cpp_rvalue_references", "200610");
+ Builder.defineMacro("__cpp_variadic_templates", "200704");
+ }
+
+ // C++14 features.
+ if (LangOpts.CPlusPlus1y) {
+ Builder.defineMacro("__cpp_binary_literals", "201304");
+ Builder.defineMacro("__cpp_init_captures", "201304");
+ Builder.defineMacro("__cpp_generic_lambdas", "201304");
+ Builder.defineMacro("__cpp_decltype_auto", "201304");
+ Builder.defineMacro("__cpp_return_type_deduction", "201304");
+ Builder.defineMacro("__cpp_aggregate_nsdmi", "201304");
+ Builder.defineMacro("__cpp_variable_templates", "201304");
+ }
+}
+
static void InitializePredefinedMacros(const TargetInfo &TI,
const LangOptions &LangOpts,
const FrontendOptions &FEOpts,
@@ -438,6 +470,9 @@ static void InitializePredefinedMacros(c
Builder.defineMacro("IBAction", "void)__attribute__((ibaction)");
}
+ if (LangOpts.CPlusPlus)
+ InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder);
+
// darwin_constant_cfstrings controls this. This is also dependent
// on other things like the runtime I believe. This is set even for C code.
if (!LangOpts.NoConstantCFStrings)
Added: cfe/trunk/test/Lexer/cxx-features.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx-features.cpp?rev=195888&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/cxx-features.cpp (added)
+++ cfe/trunk/test/Lexer/cxx-features.cpp Wed Nov 27 16:58:16 2013
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 -std=c++98 -verify %s
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify %s
+
+// expected-no-diagnostics
+
+#if __cplusplus < 201103L
+#define check(macro, cxx98, cxx11, cxx1y) cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98
+#elif __cplusplus < 201304L
+#define check(macro, cxx98, cxx11, cxx1y) cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11
+#else
+#define check(macro, cxx98, cxx11, cxx1y) cxx1y == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx1y
+#endif
+
+#if check(binary_literals, 0, 0, 201304)
+#error "wrong value for __cpp_binary_literals"
+#endif
+
+#if check(init_captures, 0, 0, 201304)
+#error "wrong value for __cpp_init_captures"
+#endif
+
+#if check(generic_lambdas, 0, 0, 201304)
+#error "wrong value for __cpp_generic_lambdas"
+#endif
+
+#if check(constexpr, 0, 200704, 201304)
+#error "wrong value for __cpp_constexpr"
+#endif
+
+#if check(decltype_auto, 0, 0, 201304)
+#error "wrong value for __cpp_decltype_auto"
+#endif
+
+#if check(return_type_deduction, 0, 0, 201304)
+#error "wrong value for __cpp_return_type_deduction"
+#endif
+
+#if check(runtime_arrays, 0, 0, 0)
+#error "wrong value for __cpp_runtime_arrays"
+#endif
+
+#if check(aggregate_nsdmi, 0, 0, 201304)
+#error "wrong value for __cpp_aggregate_nsdmi"
+#endif
+
+#if check(variable_templates, 0, 0, 201304)
+#error "wrong value for __cpp_variable_templates"
+#endif
+
+#if check(unicode_characters, 0, 200704, 200704)
+#error "wrong value for __cpp_unicode_characters"
+#endif
+
+#if check(raw_strings, 0, 200710, 200710)
+#error "wrong value for __cpp_raw_strings"
+#endif
+
+#if check(unicode_literals, 0, 200710, 200710)
+#error "wrong value for __cpp_unicode_literals"
+#endif
+
+#if check(user_defined_literals, 0, 200809, 200809)
+#error "wrong value for __cpp_user_defined_literals"
+#endif
+
+#if check(lambdas, 0, 200907, 200907)
+#error "wrong value for __cpp_lambdas"
+#endif
+
+#if check(static_assert, 0, 200410, 200410)
+#error "wrong value for __cpp_static_assert"
+#endif
+
+#if check(decltype, 0, 200707, 200707)
+#error "wrong value for __cpp_decltype"
+#endif
+
+#if check(attributes, 0, 200809, 200809)
+#error "wrong value for __cpp_attributes"
+#endif
+
+#if check(rvalue_references, 0, 200610, 200610)
+#error "wrong value for __cpp_rvalue_references"
+#endif
+
+#if check(variadic_templates, 0, 200704, 200704)
+#error "wrong value for __cpp_variadic_templates"
+#endif
Modified: cfe/trunk/www/cxx_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=195888&r1=195887&r2=195888&view=diff
==============================================================================
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Wed Nov 27 16:58:16 2013
@@ -491,6 +491,31 @@ available.</p>
<p>You can use Clang in C++1z mode with the <code>-std=c++1z</code> option.</p>
-->
+<h2 id="ts">Technical specifications and standing documents</h2>
+
+<p>ISO C++ also publishes a number of documents describing additional language
+and library features that are not part of standard C++. The following table
+describes which language features have been implemented in Clang and in which
+Clang version they became available:</p>
+
+<table width="689" border="1" cellspacing="0">
+ <tr>
+ <th>Document</th>
+ <th>Latest draft</th>
+ <th>Available in Clang?</th>
+ </tr>
+ <tr>
+ <td>SD-6: SG10 feature test recommendations</td>
+ <td><a href="http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations">SD-6</a></td>
+ <td class="svn" align="center">SVN (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3745">N3745</a>)</td>
+ </tr>
+ <tr>
+ <td>[DRAFT TS] Array extensions (arrays of runtime bound)</td>
+ <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3820.html">N3820</a></td>
+ <td class="none" align="center">No</td>
+ </tr>
+</table>
+
</div>
</body>
</html>
More information about the cfe-commits
mailing list