]> granicus.if.org Git - clang/commitdiff
c: make __has_attribute(const) work for const
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 13 Aug 2012 18:04:58 +0000 (18:04 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 13 Aug 2012 18:04:58 +0000 (18:04 +0000)
function attribute. // rdar://10253857

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161767 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPMacroExpansion.cpp
test/Sema/inline.c
test/Sema/unused-expr.c

index 3a7f02cafbf7c69615507de608b3d5508d558df8..7aef2f1a0e4c10828abf8086753d38a7b64d7db7 100644 (file)
@@ -1062,6 +1062,13 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
         if (Tok.is(tok::r_paren))
           IsValid = true;
       }
+      else if (Tok.is(tok::kw_const)) {
+        FeatureII = getIdentifierInfo("const");
+        // Read the ')'.
+        Lex(Tok);
+        if (Tok.is(tok::r_paren))
+          IsValid = true;
+      }
     }
 
     bool Value = false;
index c27c00efaad27a90d77a4aa073b0b2b926ea9e17..6377d40b8f34673aff5f960db18fc4bde2243302 100644 (file)
@@ -34,7 +34,9 @@ extern inline int useStaticInlineFromExtern () {
   return useStaticFromStatic(); // no-warning
 }
 
+#if __has_attribute(const)
 static int constFunction() __attribute__((const));
+#endif
 
 inline int useConst () {
   return constFunction(); // no-warning
index d8d8795278a847eeb6e830a447d3089ede8db101..6081ce651f0457f29f9a624291d049187abc0abb 100644 (file)
@@ -82,7 +82,9 @@ void t5() {
 
 int fn1() __attribute__ ((warn_unused_result));
 int fn2() __attribute__ ((pure));
-int fn3() __attribute__ ((const));
+#if __has_attribute(__const)
+int fn3() __attribute__ ((__const));
+#endif
 // rdar://6587766
 int t6() {
   if (fn1() < 0 || fn2(2,1) < 0 || fn3(2) < 0)  // no warnings