From: Chris Lattner Date: Sat, 2 Feb 2008 20:20:10 +0000 (+0000) Subject: Implement support for __extension__ which silences extwarnings in its X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=35080844d3e634c7c1b2875f476ab5f697eece61;p=clang Implement support for __extension__ which silences extwarnings in its 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 --- diff --git a/Parse/ParseExpr.cpp b/Parse/ParseExpr.cpp index 09f588aeec..67ce5f1a54 100644 --- a/Parse/ParseExpr.cpp +++ b/Parse/ParseExpr.cpp @@ -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 index 0000000000..0175877287 --- /dev/null +++ b/test/Sema/exprs.c @@ -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}} +} +