summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/Expr.h2
-rw-r--r--clang/lib/AST/Expr.cpp10
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateExpr.cpp6
-rw-r--r--clang/test/SemaTemplate/instantiate-expr-3.cpp11
4 files changed, 29 insertions, 0 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index c7dfffce9f1..0c5f63b5099 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -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;
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 19ab835707b..6bafdf278d8 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -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);
}
diff --git a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp
index 3c3fb7e98ea..c6ce6f46938 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -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/clang/test/SemaTemplate/instantiate-expr-3.cpp b/clang/test/SemaTemplate/instantiate-expr-3.cpp
new file mode 100644
index 00000000000..cf6139d0cec
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-expr-3.cpp
@@ -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}}
OpenPOWER on IntegriCloud