r236996 - Disable __has_cpp_attribute when not compiling in C++ mode. As this feature test macro only supports C++ style attributes, it doesn't apply to code compiled as C code, and can lead to diagnostics when given a scoped attribute.

Aaron Ballman aaron at aaronballman.com
Mon May 11 07:09:51 PDT 2015


Author: aaronballman
Date: Mon May 11 09:09:50 2015
New Revision: 236996

URL: http://llvm.org/viewvc/llvm-project?rev=236996&view=rev
Log:
Disable __has_cpp_attribute when not compiling in C++ mode. As this feature test macro only supports C++ style attributes, it doesn't apply to code compiled as C code, and can lead to diagnostics when given a scoped attribute.

This addresses PR23435.

Modified:
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/test/Preprocessor/has_attribute.c

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=236996&r1=236995&r2=236996&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Mon May 11 09:09:50 2015
@@ -283,7 +283,11 @@ void Preprocessor::RegisterBuiltinMacros
   Ident_Pragma  = RegisterBuiltinMacro(*this, "_Pragma");
 
   // C++ Standing Document Extensions.
-  Ident__has_cpp_attribute = RegisterBuiltinMacro(*this, "__has_cpp_attribute");
+  if (LangOpts.CPlusPlus)
+    Ident__has_cpp_attribute =
+        RegisterBuiltinMacro(*this, "__has_cpp_attribute");
+  else
+    Ident__has_cpp_attribute = nullptr;
 
   // GCC Extensions.
   Ident__BASE_FILE__     = RegisterBuiltinMacro(*this, "__BASE_FILE__");

Modified: cfe/trunk/test/Preprocessor/has_attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_attribute.c?rev=236996&r1=236995&r2=236996&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/has_attribute.c (original)
+++ cfe/trunk/test/Preprocessor/has_attribute.c Mon May 11 09:09:50 2015
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple arm-unknown-linux -E %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple arm-unknown-linux -verify -E %s -o - | FileCheck %s
 
 // CHECK: always_inline
 #if __has_attribute(always_inline)
@@ -53,3 +53,6 @@ int has_no_volatile_attribute();
 #if !__has_attribute(uuid)
   int does_not_have_uuid
 #endif
+
+#if __has_cpp_attribute(selectany) // expected-error {{token is not a valid binary operator in a preprocessor subexpression}}
+#endif





More information about the cfe-commits mailing list