Record if a compound literal expression is @ file scope. This allows us to implement C99 6.5.2.5p6. This could have been done without modifying the AST (by checking the decl type and passing the info down to isContextExpr), however we concluded this is more desirable.

Bug/patch by Eli Friedman!



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45966 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index ced6953..9f5e8e6 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -673,12 +673,13 @@
   // FIXME: add more semantic analysis (C99 6.5.2.5).
   if (CheckInitializerTypes(literalExpr, literalType))
     return true;
-    
-  if (!CurFunctionDecl && !CurMethodDecl) { // 6.5.2.5p3
+
+  bool isFileScope = !CurFunctionDecl && !CurMethodDecl;
+  if (isFileScope) { // 6.5.2.5p3
     if (CheckForConstantInitializer(literalExpr, literalType))
       return true;
   }
-  return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr);
+  return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr, isFileScope);
 }
 
 Action::ExprResult Sema::
@@ -1963,7 +1964,7 @@
   
   // Otherwise, create a compound literal expression as the base, and
   // iteratively process the offsetof designators.
-  Expr *Res = new CompoundLiteralExpr(SourceLocation(), ArgTy, 0);
+  Expr *Res = new CompoundLiteralExpr(SourceLocation(), ArgTy, 0, false);
   
   // offsetof with non-identifier designators (e.g. "offsetof(x, a.b[c])") are a
   // GCC extension, diagnose them.