Add support for has_feature(cxx_alignof) and has_feature(c_alignof).
authorNico Weber <nicolasweber@gmx.de>
Wed, 3 Dec 2014 01:25:49 +0000 (01:25 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 3 Dec 2014 01:25:49 +0000 (01:25 +0000)
r142020 added support for has_feature(cxx_alignas). This does the same for
alignof.

llvm-svn: 223186

clang/docs/LanguageExtensions.rst
clang/lib/Lex/PPMacroExpansion.cpp
clang/test/Lexer/has_extension.c
clang/test/Lexer/has_feature_c1x.c
clang/test/Lexer/has_feature_cxx0x.cpp

index ae298afdeed3bd9d937d099eb0eae122097c4465..5636b8992dcb54c353b3737be00c3c5ba88b9c2c 100644 (file)
@@ -543,6 +543,9 @@ C++11 alignment specifiers
 Use ``__has_feature(cxx_alignas)`` or ``__has_extension(cxx_alignas)`` to
 determine if support for alignment specifiers using ``alignas`` is enabled.
 
+Use ``__has_feature(cxx_alignof)`` or ``__has_extension(cxx_alignof)`` to
+determine if support for the ``alignof`` keyword is enabled.
+
 C++11 attributes
 ^^^^^^^^^^^^^^^^
 
@@ -857,6 +860,9 @@ C11 alignment specifiers
 Use ``__has_feature(c_alignas)`` or ``__has_extension(c_alignas)`` to determine
 if support for alignment specifiers using ``_Alignas`` is enabled.
 
+Use ``__has_feature(c_alignof)`` or ``__has_extension(c_alignof)`` to determine
+if support for the ``_Alignof`` keyword is enabled.
+
 C11 atomic operations
 ^^^^^^^^^^^^^^^^^^^^^
 
index 1100dcaa335849143ba3a92a1c84fec4702ae1f5..37460f5e0fcbcc1554b2e2ec8c55b686d0fd6407 100644 (file)
@@ -913,6 +913,7 @@ static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) {
       .Case("arc_cf_code_audited", true)
       // C11 features
       .Case("c_alignas", LangOpts.C11)
+      .Case("c_alignof", LangOpts.C11)
       .Case("c_atomic", LangOpts.C11)
       .Case("c_generic_selections", LangOpts.C11)
       .Case("c_static_assert", LangOpts.C11)
@@ -922,6 +923,7 @@ static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) {
       .Case("cxx_access_control_sfinae", LangOpts.CPlusPlus11)
       .Case("cxx_alias_templates", LangOpts.CPlusPlus11)
       .Case("cxx_alignas", LangOpts.CPlusPlus11)
+      .Case("cxx_alignof", LangOpts.CPlusPlus11)
       .Case("cxx_atomic", LangOpts.CPlusPlus11)
       .Case("cxx_attributes", LangOpts.CPlusPlus11)
       .Case("cxx_auto_type", LangOpts.CPlusPlus11)
@@ -1030,6 +1032,7 @@ static bool HasExtension(const Preprocessor &PP, const IdentifierInfo *II) {
   return llvm::StringSwitch<bool>(Extension)
            // C11 features supported by other languages as extensions.
            .Case("c_alignas", true)
+           .Case("c_alignof", true)
            .Case("c_atomic", true)
            .Case("c_generic_selections", true)
            .Case("c_static_assert", true)
index 2ab3d1df37a8193fd23ddb96f24c54c5cac6d425..b7efece64e8363f0c307f6960c6ef49248fa79ec 100644 (file)
@@ -36,6 +36,14 @@ int has_c_alignas();
 int no_c_alignas();
 #endif
 
+// CHECK-PED-NONE: has_c_alignof
+// CHECK-PED-ERR: no_c_alignof
+#if __has_extension(c_alignof)
+int has_c_alignof();
+#else
+int no_c_alignof();
+#endif
+
 // Arbitrary feature to test that the extension name can be surrounded with
 // double underscores.
 // CHECK-PED-NONE: has_double_underscores
index cba329cfb5501aaa2f73e9620afc325b33c1f200..ff1778010b7554fda8cabeaa432b88780e71830c 100644 (file)
@@ -12,7 +12,6 @@ int has_atomic();
 #else
 int no_atomic();
 #endif
-
 // CHECK-1X: has_atomic
 // CHECK-NO-1X: no_atomic
 
@@ -21,7 +20,6 @@ int has_static_assert();
 #else
 int no_static_assert();
 #endif
-
 // CHECK-1X: has_static_assert
 // CHECK-NO-1X: no_static_assert
 
@@ -30,7 +28,6 @@ int has_generic_selections();
 #else
 int no_generic_selections();
 #endif
-
 // CHECK-1X: has_generic_selections
 // CHECK-NO-1X: no_generic_selections
 
@@ -39,10 +36,17 @@ int has_alignas();
 #else
 int no_alignas();
 #endif
-
 // CHECK-1X: has_alignas
 // CHECK-NO-1X: no_alignas
 
+#if __has_feature(c_alignof)
+int has_alignof();
+#else
+int no_alignof();
+#endif
+// CHECK-1X: has_alignof
+// CHECK-NO-1X: no_alignof
+
 #if __has_feature(c_thread_local)
 int has_thread_local();
 #else
index e558f8804b222b34e1d4d7252b9a144ae1130c4e..9fb05de31a23f9ce72d84394f376970ac911a383 100644 (file)
@@ -234,6 +234,16 @@ int no_alignas();
 // CHECK-11: has_alignas
 // CHECK-NO-11: no_alignas
 
+#if __has_feature(cxx_alignof)
+int has_alignof();
+#else
+int no_alignof();
+#endif
+
+// CHECK-1Y: has_alignof
+// CHECK-11: has_alignof
+// CHECK-NO-11: no_alignof
+
 #if __has_feature(cxx_raw_string_literals)
 int has_raw_string_literals();
 #else