[cfe-commits] r72183 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/AST/ExprCXX.cpp lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-expr-4.cpp
Douglas Gregor
dgregor at apple.com
Wed May 20 14:38:11 PDT 2009
Author: dgregor
Date: Wed May 20 16:38:11 2009
New Revision: 72183
URL: http://llvm.org/viewvc/llvm-project?rev=72183&view=rev
Log:
Template instantiation for the various kinds of AST nodes that occur
due to C++ type construction of the form T(a1, a2, ..., aN).
Added:
cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=72183&r1=72182&r2=72183&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Wed May 20 16:38:11 2009
@@ -431,8 +431,11 @@
void Destroy(ASTContext &C);
- const VarDecl* getVarDecl() const { return VD; }
- const CXXConstructorDecl* getConstructor() const { return Constructor; }
+ VarDecl* getVarDecl() const { return VD; }
+ CXXConstructorDecl* getConstructor() const { return Constructor; }
+
+ /// \brief Whether this construction is elidable.
+ bool isElidable() const { return Elidable; }
typedef ExprIterator arg_iterator;
typedef ConstExprIterator const_arg_iterator;
@@ -537,7 +540,7 @@
public:
CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
SourceLocation rParenLoc ) :
- Expr(CXXZeroInitValueExprClass, ty),
+ Expr(CXXZeroInitValueExprClass, ty, false, false),
TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
@@ -553,6 +556,8 @@
return SourceRange(TyBeginLoc, RParenLoc);
}
+ CXXZeroInitValueExpr* Clone(ASTContext &C) const;
+
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXZeroInitValueExprClass;
}
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=72183&r1=72182&r2=72183&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Wed May 20 16:38:11 2009
@@ -365,3 +365,7 @@
CXXNullPtrLiteralExpr* CXXNullPtrLiteralExpr::Clone(ASTContext &C) const {
return new (C) CXXNullPtrLiteralExpr(getType(), Loc);
}
+
+CXXZeroInitValueExpr* CXXZeroInitValueExpr::Clone(ASTContext &C) const {
+ return new (C) CXXZeroInitValueExpr(getType(), TyBeginLoc, RParenLoc);
+}
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=72183&r1=72182&r2=72183&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Wed May 20 16:38:11 2009
@@ -85,9 +85,9 @@
// FIXME: CXXTypeIdExpr
// FIXME: CXXThrowExpr
// FIXME: CXXDefaultArgExpr
- // FIXME: CXXConstructExpr
- // FIXME: CXXFunctionalCastExpr
- // FIXME: CXXZeroInitValueExpr
+ OwningExprResult VisitCXXConstructExpr(CXXConstructExpr *E);
+ OwningExprResult VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
+ OwningExprResult VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
// FIXME: CXXNewExpr
// FIXME: CXXDeleteExpr
// FIXME: UnaryTypeTraitExpr
@@ -836,6 +836,87 @@
}
Sema::OwningExprResult
+TemplateExprInstantiator::VisitCXXConstructExpr(CXXConstructExpr *E) {
+ assert(!cast<CXXRecordDecl>(E->getConstructor()->getDeclContext())
+ ->isDependentType() && "Dependent constructor shouldn't be here");
+
+ QualType T = SemaRef.InstantiateType(E->getType(), TemplateArgs,
+ /*FIXME*/E->getSourceRange().getBegin(),
+ DeclarationName());
+ if (T.isNull())
+ return SemaRef.ExprError();
+
+ bool Invalid = false;
+ llvm::SmallVector<Expr *, 8> Args;
+ for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
+ ArgEnd = E->arg_end();
+ Arg != ArgEnd; ++Arg) {
+ OwningExprResult ArgInst = Visit(*Arg);
+ if (ArgInst.isInvalid()) {
+ Invalid = true;
+ break;
+ }
+
+ Args.push_back(ArgInst.takeAs<Expr>());
+ }
+
+
+ VarDecl *Var = 0;
+ if (!Invalid) {
+ Var = cast_or_null<VarDecl>(SemaRef.InstantiateDecl(E->getVarDecl(),
+ SemaRef.CurContext,
+ TemplateArgs));
+ if (!Var)
+ Invalid = true;
+ }
+
+ if (Invalid) {
+ for (unsigned I = 0, N = Args.size(); I != N; ++I)
+ Args[I]->Destroy(SemaRef.Context);
+
+ return SemaRef.ExprError();
+ }
+
+ return SemaRef.Owned(CXXConstructExpr::Create(SemaRef.Context, Var, T,
+ E->getConstructor(),
+ E->isElidable(),
+ &Args.front(), Args.size()));
+}
+
+Sema::OwningExprResult
+TemplateExprInstantiator::VisitCXXFunctionalCastExpr(
+ CXXFunctionalCastExpr *E) {
+ // Instantiate the type that we're casting to.
+ QualType ExplicitTy = SemaRef.InstantiateType(E->getTypeAsWritten(),
+ TemplateArgs,
+ E->getTypeBeginLoc(),
+ DeclarationName());
+ if (ExplicitTy.isNull())
+ return SemaRef.ExprError();
+
+ // Instantiate the subexpression.
+ OwningExprResult SubExpr = Visit(E->getSubExpr());
+ if (SubExpr.isInvalid())
+ return SemaRef.ExprError();
+
+ // FIXME: The end of the type's source range is wrong
+ Expr *Sub = SubExpr.takeAs<Expr>();
+ return SemaRef.ActOnCXXTypeConstructExpr(SourceRange(E->getTypeBeginLoc()),
+ ExplicitTy.getAsOpaquePtr(),
+ /*FIXME:*/E->getTypeBeginLoc(),
+ Sema::MultiExprArg(SemaRef,
+ (void **)&Sub,
+ 1),
+ 0,
+ E->getRParenLoc());
+}
+
+Sema::OwningExprResult
+TemplateExprInstantiator::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+ return SemaRef.Clone(E);
+}
+
+Sema::OwningExprResult
TemplateExprInstantiator::VisitCXXUnresolvedConstructExpr(
CXXUnresolvedConstructExpr *E) {
QualType T = SemaRef.InstantiateType(E->getTypeAsWritten(), TemplateArgs,
Added: cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp?rev=72183&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp Wed May 20 16:38:11 2009
@@ -0,0 +1,35 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+// ---------------------------------------------------------------------
+// C++ Functional Casts
+// ---------------------------------------------------------------------
+template<int N>
+struct ValueInit0 {
+ int f() {
+ return int();
+ }
+};
+
+template struct ValueInit0<5>;
+
+template<int N>
+struct FunctionalCast0 {
+ int f() {
+ return int(N);
+ }
+};
+
+template struct FunctionalCast0<5>;
+
+struct X {
+ X(int, int);
+};
+
+template<int N, int M>
+struct BuildTemporary0 {
+ X f() {
+ return X(N, M);
+ }
+};
+
+template struct BuildTemporary0<5, 7>;
More information about the cfe-commits
mailing list