[cfe-commits] r72058 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-expr-3.cpp
Douglas Gregor
dgregor at apple.com
Mon May 18 15:38:39 PDT 2009
Author: dgregor
Date: Mon May 18 17:38:38 2009
New Revision: 72058
URL: http://llvm.org/viewvc/llvm-project?rev=72058&view=rev
Log:
Template instantiation for imaginary literals, because they were next in Expr.h
Added:
cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=72058&r1=72057&r2=72058&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon May 18 17:38:38 2009
@@ -523,6 +523,8 @@
Expr *getSubExpr() { return cast<Expr>(Val); }
void setSubExpr(Expr *E) { Val = E; }
+ ImaginaryLiteral* Clone(ASTContext &C) const;
+
virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
static bool classof(const Stmt *T) {
return T->getStmtClass() == ImaginaryLiteralClass;
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=72058&r1=72057&r2=72058&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon May 18 17:38:38 2009
@@ -44,6 +44,16 @@
return new (C) FloatingLiteral(Value, &exact, getType(), Loc);
}
+ImaginaryLiteral* ImaginaryLiteral::Clone(ASTContext &C) const {
+ // FIXME: Use virtual Clone(), once it is available
+ Expr *ClonedVal = 0;
+ if (const IntegerLiteral *IntLit = dyn_cast<IntegerLiteral>(Val))
+ ClonedVal = IntLit->Clone(C);
+ else
+ ClonedVal = cast<FloatingLiteral>(Val)->Clone(C);
+ return new (C) ImaginaryLiteral(ClonedVal, getType());
+}
+
GNUNullExpr* GNUNullExpr::Clone(ASTContext &C) const {
return new (C) GNUNullExpr(getType(), TokenLoc);
}
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=72058&r1=72057&r2=72058&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Mon May 18 17:38:38 2009
@@ -41,6 +41,7 @@
OwningExprResult VisitFloatingLiteral(FloatingLiteral *E);
OwningExprResult VisitStringLiteral(StringLiteral *E);
OwningExprResult VisitCharacterLiteral(CharacterLiteral *E);
+ OwningExprResult VisitImaginaryLiteral(ImaginaryLiteral *E);
OwningExprResult VisitDeclRefExpr(DeclRefExpr *E);
OwningExprResult VisitParenExpr(ParenExpr *E);
OwningExprResult VisitUnaryOperator(UnaryOperator *E);
@@ -91,6 +92,11 @@
return SemaRef.Clone(E);
}
+Sema::OwningExprResult
+TemplateExprInstantiator::VisitImaginaryLiteral(ImaginaryLiteral *E) {
+ return SemaRef.Clone(E);
+}
+
Sema::OwningExprResult
TemplateExprInstantiator::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
return SemaRef.Clone(E);
Added: cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp?rev=72058&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp Mon May 18 17:38:38 2009
@@ -0,0 +1,11 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<typename T>
+struct ImaginaryLiteral0 {
+ void f(T &x) {
+ x = 3.0I; // expected-error{{incompatible type}}
+ }
+};
+
+template struct ImaginaryLiteral0<_Complex float>;
+template struct ImaginaryLiteral0<int*>; // expected-note{{instantiation}}
More information about the cfe-commits
mailing list