diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-01-24 23:09:00 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-01-24 23:09:00 +0000 |
commit | dca2b7314f73fbb1e897befdc4f0ddaa9905d72c (patch) | |
tree | e5da9e3c700be38b35b6567575268a19a5b3f2c8 /lib | |
parent | 769e411b72465a63454cdd416ff26ff313d43505 (diff) |
PR3062: statement expressions should be illegal at file scope. I don't
think this has any significant effects at the moment, but it could
matter if we start constant-folding statement expressions like gcc does.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62943 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index d4babb4baa..1d55ed7c3a 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3940,6 +3940,11 @@ Sema::ExprResult Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtTy *substmt, assert(SubStmt && isa<CompoundStmt>(SubStmt) && "Invalid action invocation!"); CompoundStmt *Compound = cast<CompoundStmt>(SubStmt); + bool isFileScope = getCurFunctionOrMethodDecl() == 0; + if (isFileScope) { + return Diag(LPLoc, diag::err_stmtexpr_file_scope); + } + // FIXME: there are a variety of strange constraints to enforce here, for // example, it is not possible to goto into a stmt expression apparently. // More semantic analysis is needed. |