r174261 - Correctly classify T{} as an array temporary if T is an array of class type with nontrivial destructor.
Richard Smith
richard-llvm at metafoo.co.uk
Fri Feb 1 18:11:37 PST 2013
Author: rsmith
Date: Fri Feb 1 20:11:36 2013
New Revision: 174261
URL: http://llvm.org/viewvc/llvm-project?rev=174261&view=rev
Log:
Correctly classify T{} as an array temporary if T is an array of class type with nontrivial destructor.
Modified:
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/test/SemaCXX/address-of-temporary.cpp
Modified: cfe/trunk/lib/AST/ExprClassification.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprClassification.cpp?rev=174261&r1=174260&r2=174261&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprClassification.cpp (original)
+++ cfe/trunk/lib/AST/ExprClassification.cpp Fri Feb 1 20:11:36 2013
@@ -34,21 +34,6 @@ static Cl::Kinds ClassifyConditional(AST
static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E,
Cl::Kinds Kind, SourceLocation &Loc);
-static Cl::Kinds ClassifyExprValueKind(const LangOptions &Lang,
- const Expr *E,
- ExprValueKind Kind) {
- switch (Kind) {
- case VK_RValue:
- return Lang.CPlusPlus && E->getType()->isRecordType() ?
- Cl::CL_ClassTemporary : Cl::CL_PRValue;
- case VK_LValue:
- return Cl::CL_LValue;
- case VK_XValue:
- return Cl::CL_XValue;
- }
- llvm_unreachable("Invalid value category of implicit cast.");
-}
-
Cl Expr::ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const {
assert(!TR->isReferenceType() && "Expressions can't have reference type.");
@@ -100,6 +85,20 @@ static Cl::Kinds ClassifyTemporary(QualT
return Cl::CL_PRValue;
}
+static Cl::Kinds ClassifyExprValueKind(const LangOptions &Lang,
+ const Expr *E,
+ ExprValueKind Kind) {
+ switch (Kind) {
+ case VK_RValue:
+ return Lang.CPlusPlus ? ClassifyTemporary(E->getType()) : Cl::CL_PRValue;
+ case VK_LValue:
+ return Cl::CL_LValue;
+ case VK_XValue:
+ return Cl::CL_XValue;
+ }
+ llvm_unreachable("Invalid value category of implicit cast.");
+}
+
static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) {
// This function takes the first stab at classifying expressions.
const LangOptions &Lang = Ctx.getLangOpts();
Modified: cfe/trunk/test/SemaCXX/address-of-temporary.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/address-of-temporary.cpp?rev=174261&r1=174260&r2=174261&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/address-of-temporary.cpp (original)
+++ cfe/trunk/test/SemaCXX/address-of-temporary.cpp Fri Feb 1 20:11:36 2013
@@ -15,8 +15,13 @@ namespace PointerToArrayDecay {
struct Y {
int a[4];
};
+ struct Z {
+ int n;
+ ~Z();
+ };
typedef int A[4];
+ typedef Z AZ[4];
template<typename T> void consume(T);
struct S { int *p; };
@@ -25,11 +30,13 @@ namespace PointerToArrayDecay {
void g1() { int *p = Y{}.a; } // expected-warning{{pointer is initialized by a temporary array}}
void g2() { int *p = A{}; } // expected-warning{{pointer is initialized by a temporary array}}
void g3() { int *p = (A){}; } // expected-warning{{pointer is initialized by a temporary array}}
+ void g4() { Z *p = AZ{}; } // expected-warning{{pointer is initialized by a temporary array}}
void h0() { consume(Y().a); }
void h1() { consume(Y{}.a); }
void h2() { consume(A{}); }
void h3() { consume((A){}); }
+ void h4() { consume(AZ{}); }
void i0() { S s = { Y().a }; } // expected-warning{{pointer is initialized by a temporary array}}
void i1() { S s = { Y{}.a }; } // expected-warning{{pointer is initialized by a temporary array}}
More information about the cfe-commits
mailing list