diff options
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticKinds.def | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 5 | ||||
| -rw-r--r-- | clang/test/Sema/stmt_exprs.c | 2 | 
3 files changed, 9 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def index 13f54037451..93b023e5609 100644 --- a/clang/include/clang/Basic/DiagnosticKinds.def +++ b/clang/include/clang/Basic/DiagnosticKinds.def @@ -1301,6 +1301,8 @@ DIAG(ext_typecheck_comparison_of_distinct_pointers, WARNING,       "comparison of distinct pointer types (%0 and %1)")  DIAG(err_typecheck_assign_const, ERROR,       "read-only variable is not assignable") +DIAG(err_stmtexpr_file_scope, ERROR, +     "statement expression not allowed at file scope")  DIAG(err_invalid_this_use, ERROR,       "invalid use of 'this' outside of a nonstatic member function") diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index d4babb4baa4..1d55ed7c3aa 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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. diff --git a/clang/test/Sema/stmt_exprs.c b/clang/test/Sema/stmt_exprs.c index ee835a355dc..0d6fe8585f5 100644 --- a/clang/test/Sema/stmt_exprs.c +++ b/clang/test/Sema/stmt_exprs.c @@ -20,3 +20,5 @@ int test5() { return ({L1: L2: L3: 5;}); }  int test6() { return ({5;}); }  void test7() { ({5;}); }                   // expected-warning {{expression result unused}} +// PR3062 +int x[({10;})]; // expected-error {{illegal statement expression}}  | 

