[cfe-commits] r132390 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/SemaCXX/return.cpp
Nick Lewycky
nicholas at mxc.ca
Wed Jun 1 00:44:32 PDT 2011
Author: nicholas
Date: Wed Jun 1 02:44:31 2011
New Revision: 132390
URL: http://llvm.org/viewvc/llvm-project?rev=132390&view=rev
Log:
Even a return statement of an expression with a dependent type in a void
function might need to clean up its temporaries. Fixes PR10057.
Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/return.cpp
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=132390&r1=132389&r2=132390&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Jun 1 02:44:31 2011
@@ -1687,27 +1687,30 @@
ReturnStmt *Result = 0;
if (FnRetType->isVoidType()) {
- if (RetValExp && !RetValExp->isTypeDependent()) {
- // C99 6.8.6.4p1 (ext_ since GCC warns)
- unsigned D = diag::ext_return_has_expr;
- if (RetValExp->getType()->isVoidType())
- D = diag::ext_return_has_void_expr;
- else {
- ExprResult Result = Owned(RetValExp);
- Result = IgnoredValueConversions(Result.take());
- if (Result.isInvalid())
- return StmtError();
- RetValExp = Result.take();
- RetValExp = ImpCastExprToType(RetValExp, Context.VoidTy, CK_ToVoid).take();
- }
-
- // return (some void expression); is legal in C++.
- if (D != diag::ext_return_has_void_expr ||
- !getLangOptions().CPlusPlus) {
- NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
- Diag(ReturnLoc, D)
- << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
- << RetValExp->getSourceRange();
+ if (RetValExp) {
+ if (!RetValExp->isTypeDependent()) {
+ // C99 6.8.6.4p1 (ext_ since GCC warns)
+ unsigned D = diag::ext_return_has_expr;
+ if (RetValExp->getType()->isVoidType())
+ D = diag::ext_return_has_void_expr;
+ else {
+ ExprResult Result = Owned(RetValExp);
+ Result = IgnoredValueConversions(Result.take());
+ if (Result.isInvalid())
+ return StmtError();
+ RetValExp = Result.take();
+ RetValExp = ImpCastExprToType(RetValExp,
+ Context.VoidTy, CK_ToVoid).take();
+ }
+
+ // return (some void expression); is legal in C++.
+ if (D != diag::ext_return_has_void_expr ||
+ !getLangOptions().CPlusPlus) {
+ NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
+ Diag(ReturnLoc, D)
+ << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
+ << RetValExp->getSourceRange();
+ }
}
CheckImplicitConversions(RetValExp, ReturnLoc);
Modified: cfe/trunk/test/SemaCXX/return.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/return.cpp?rev=132390&r1=132389&r2=132390&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/return.cpp (original)
+++ cfe/trunk/test/SemaCXX/return.cpp Wed Jun 1 02:44:31 2011
@@ -53,3 +53,14 @@
class foo {
operator int * const ();
};
+
+namespace PR10057 {
+ struct S {
+ ~S();
+ };
+
+ template <class VarType>
+ void Test(const VarType& value) {
+ return S() = value;
+ }
+}
More information about the cfe-commits
mailing list