]> granicus.if.org Git - clang/commitdiff
Implement support for __extension__ which silences extwarnings in its
authorChris Lattner <sabre@nondot.org>
Sat, 2 Feb 2008 20:20:10 +0000 (20:20 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 2 Feb 2008 20:20:10 +0000 (20:20 +0000)
scope.  This is part of the fix for PR1966

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

Parse/ParseExpr.cpp
test/Sema/exprs.c [new file with mode: 0644]

index 09f588aeec3bec2dc45576553031d41c526d5578..67ce5f1a545bdec9fc416772137ae29870bf5678 100644 (file)
@@ -567,13 +567,23 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
   case tok::tilde:         // unary-expression: '~' cast-expression
   case tok::exclaim:       // unary-expression: '!' cast-expression
   case tok::kw___real:     // unary-expression: '__real' cast-expression [GNU]
-  case tok::kw___imag:     // unary-expression: '__imag' cast-expression [GNU]
+  case tok::kw___imag: {   // unary-expression: '__imag' cast-expression [GNU]
+    SourceLocation SavedLoc = ConsumeToken();
+    Res = ParseCastExpression(false);
+    if (!Res.isInvalid)
+      Res = Actions.ActOnUnaryOp(SavedLoc, SavedKind, Res.Val);
+    return Res;
+  }    
+      
   case tok::kw___extension__:{//unary-expression:'__extension__' cast-expr [GNU]
-    // FIXME: Extension should silence extwarns in subexpressions.
+    // __extension__ silences extension warnings in the subexpression.
+    bool SavedExtWarn = Diags.getWarnOnExtensions();
+    Diags.setWarnOnExtensions(false);
     SourceLocation SavedLoc = ConsumeToken();
     Res = ParseCastExpression(false);
     if (!Res.isInvalid)
       Res = Actions.ActOnUnaryOp(SavedLoc, SavedKind, Res.Val);
+    Diags.setWarnOnExtensions(SavedExtWarn);
     return Res;
   }
   case tok::kw_sizeof:     // unary-expression: 'sizeof' unary-expression
diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c
new file mode 100644 (file)
index 0000000..0175877
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: clang %s -verify -pedantic -fsyntax-only
+
+// PR1966
+_Complex double test1() {
+  return __extension__ 1.0if;
+}
+
+_Complex double test2() {
+  return 1.0if;    // expected-warning {{imaginary constants are an extension}}
+}
+