r201542 - PR18876: The special-case rule that ignores the destruction of a top-level
Richard Smith
richard-llvm at metafoo.co.uk
Mon Feb 17 19:51:47 PST 2014
Author: rsmith
Date: Mon Feb 17 21:51:47 2014
New Revision: 201542
URL: http://llvm.org/viewvc/llvm-project?rev=201542&view=rev
Log:
PR18876: The special-case rule that ignores the destruction of a top-level
temporary in a decltype expression only applies if that temporary was created
by a function call, not by a function-style cast or other flavour of
expression.
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p5-cxx0x.cpp
cfe/trunk/test/SemaCXX/decltype.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=201542&r1=201541&r2=201542&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Feb 17 21:51:47 2014
@@ -5082,8 +5082,11 @@ ExprResult Sema::ActOnDecltypeExpression
}
CXXBindTemporaryExpr *TopBind = dyn_cast<CXXBindTemporaryExpr>(E);
- if (TopBind)
- E = TopBind->getSubExpr();
+ CallExpr *TopCall = TopBind ? dyn_cast<CallExpr>(TopBind->getSubExpr()) : 0;
+ if (TopCall)
+ E = TopCall;
+ else
+ TopBind = 0;
// Disable the special decltype handling now.
ExprEvalContexts.back().IsDecltype = false;
@@ -5094,7 +5097,6 @@ ExprResult Sema::ActOnDecltypeExpression
return Owned(E);
// Perform the semantic checks we delayed until this point.
- CallExpr *TopCall = dyn_cast<CallExpr>(E);
for (unsigned I = 0, N = ExprEvalContexts.back().DelayedDecltypeCalls.size();
I != N; ++I) {
CallExpr *Call = ExprEvalContexts.back().DelayedDecltypeCalls[I];
Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p5-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p5-cxx0x.cpp?rev=201542&r1=201541&r2=201542&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p5-cxx0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p5-cxx0x.cpp Mon Feb 17 21:51:47 2014
@@ -30,29 +30,33 @@ struct DD {
typedef int n;
};
+PD pd();
+DD dd();
+
struct A {
- decltype(PD()) s; // ok
- decltype(PD())::n n; // ok
- decltype(DD()) *p = new decltype(DD()); // ok
+ decltype(pd()) s; // ok
+ decltype(pd())::n n; // ok
+ decltype(dd()) *p = new decltype(dd()); // ok
};
+A a();
// Two errors here: one for the decltype, one for the variable.
decltype(
- PD(), // expected-error {{private destructor}}
- PD()) pd1; // expected-error {{private destructor}}
-decltype(DD(), // expected-error {{deleted function}}
- DD()) dd1;
-decltype(A(),
- DD()) dd2; // expected-error {{deleted function}}
+ pd(), // expected-error {{private destructor}}
+ pd()) pd1; // expected-error {{private destructor}}
+decltype(dd(), // expected-error {{deleted function}}
+ dd()) dd1;
+decltype(a(),
+ dd()) dd2; // expected-error {{deleted function}}
decltype(
- PD(), // expected-error {{temporary of type 'PD' has private destructor}}
+ pd(), // expected-error {{temporary of type 'PD' has private destructor}}
0) pd2;
-decltype(((13, ((DD())))))::n dd_parens; // ok
-decltype(((((42)), PD())))::n pd_parens_comma; // ok
+decltype(((13, ((dd())))))::n dd_parens; // ok
+decltype(((((42)), pd())))::n pd_parens_comma; // ok
// Ensure parens aren't stripped from a decltype node.
-extern decltype(PD()) pd_ref; // ok
+extern decltype(pd()) pd_ref; // ok
decltype((pd_ref)) pd_ref3 = pd_ref; // ok, PD &
decltype(pd_ref) pd_ref2 = pd_ref; // expected-error {{private destructor}}
@@ -107,7 +111,7 @@ namespace RequireCompleteType {
namespace Overload {
DD operator+(PD &a, PD &b);
- decltype(PD()) *pd_ptr;
+ decltype(pd()) *pd_ptr;
decltype(*pd_ptr + *pd_ptr) *dd_ptr; // ok
decltype(0, *pd_ptr) pd_ref2 = pd_ref; // ok
Modified: cfe/trunk/test/SemaCXX/decltype.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decltype.cpp?rev=201542&r1=201541&r2=201542&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/decltype.cpp (original)
+++ cfe/trunk/test/SemaCXX/decltype.cpp Mon Feb 17 21:51:47 2014
@@ -45,6 +45,16 @@ namespace PR16529 {
U &r = S<int>::f();
}
+namespace PR18876 {
+ struct A { ~A() = delete; }; // expected-note +{{here}}
+ A f();
+ decltype(f()) *a; // ok, function call
+ decltype(A()) *b; // expected-error {{attempt to use a deleted function}}
+ decltype(0, f()) *c; // ok, function call on RHS of comma
+ decltype(0, A()) *d; // expected-error {{attempt to use a deleted function}}
+ decltype(f(), 0) *e; // expected-error {{attempt to use a deleted function}}
+}
+
template<typename>
class conditional {
};
More information about the cfe-commits
mailing list