[PATCH] D35562: Support GNU extension StmtExpr in constexpr function
Stephan Bergmann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 18 01:57:08 PDT 2017
sberg updated this revision to Diff 111632.
sberg added a comment.
(the original diff had inadvertently lacked full -U999999 context; uploaded a new diff)
https://reviews.llvm.org/D35562
Files:
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-cxx1y.cpp
Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx1y.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1y.cpp
@@ -781,9 +781,8 @@
return ({ int n; n; }); // expected-note {{object of type 'int' is not initialized}}
}
- // FIXME: We should handle the void statement expression case.
- constexpr int h() { // expected-error {{never produces a constant}}
- ({ if (true) {} }); // expected-note {{not supported}}
+ constexpr int h() {
+ ({ if (true) {} });
return 0;
}
}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -4837,16 +4837,10 @@
for (CompoundStmt::const_body_iterator BI = CS->body_begin(),
BE = CS->body_end();
- /**/; ++BI) {
- if (BI + 1 == BE) {
- const Expr *FinalExpr = dyn_cast<Expr>(*BI);
- if (!FinalExpr) {
- Info.FFDiag((*BI)->getLocStart(),
- diag::note_constexpr_stmt_expr_unsupported);
- return false;
- }
- return this->Visit(FinalExpr);
- }
+ BI != BE; ++BI) {
+ if (BI + 1 == BE)
+ if (const Expr *FinalExpr = dyn_cast<Expr>(*BI))
+ return this->Visit(FinalExpr);
APValue ReturnValue;
StmtResult Result = { ReturnValue, nullptr };
@@ -4862,7 +4856,7 @@
}
}
- llvm_unreachable("Return from function from the loop above.");
+ return true;
}
/// Visit a value which is evaluated, but whose value is ignored.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35562.111632.patch
Type: text/x-patch
Size: 1715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170818/81cccc47/attachment.bin>
More information about the cfe-commits
mailing list