]> granicus.if.org Git - clang/commitdiff
Template instantiation for imaginary literals, because they were next in Expr.h
authorDouglas Gregor <dgregor@apple.com>
Mon, 18 May 2009 22:38:38 +0000 (22:38 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 18 May 2009 22:38:38 +0000 (22:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72058 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/Sema/SemaTemplateInstantiateExpr.cpp
test/SemaTemplate/instantiate-expr-3.cpp [new file with mode: 0644]

index c7dfffce9f1242dbc709eac274328a575de12b2a..0c5f63b5099d35c56d9458fa6a855021b3115cc7 100644 (file)
@@ -523,6 +523,8 @@ public:
   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; 
index 19ab835707beb091e8caf2ea7f482f68b440b65d..6bafdf278d82481a1164d404b4e29c41938238ce 100644 (file)
@@ -44,6 +44,16 @@ FloatingLiteral* FloatingLiteral::Clone(ASTContext &C) const {
   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);
 }
index 3c3fb7e98ea2c62f8a34e6b75f22454878043fff..c6ce6f469381a38ff29966e068ba9911233082da 100644 (file)
@@ -41,6 +41,7 @@ namespace {
     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 @@ TemplateExprInstantiator::VisitCharacterLiteral(CharacterLiteral *E) {
   return SemaRef.Clone(E);
 }
 
+Sema::OwningExprResult 
+TemplateExprInstantiator::VisitImaginaryLiteral(ImaginaryLiteral *E) {
+  return SemaRef.Clone(E);
+}
+
 Sema::OwningExprResult
 TemplateExprInstantiator::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
   return SemaRef.Clone(E);
diff --git a/test/SemaTemplate/instantiate-expr-3.cpp b/test/SemaTemplate/instantiate-expr-3.cpp
new file mode 100644 (file)
index 0000000..cf6139d
--- /dev/null
@@ -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}}