]> granicus.if.org Git - clang/commitdiff
Template instantiation for compound assignment operators.
authorDouglas Gregor <dgregor@apple.com>
Tue, 19 May 2009 20:02:01 +0000 (20:02 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 19 May 2009 20:02:01 +0000 (20:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72126 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateExpr.cpp
test/SemaTemplate/instantiate-expr-3.cpp

index e5ad0cd3042c6498328160d702d69fbfd2defdd1..9dda383342cf159bc4b94d6e21e38bca3fe6e37d 100644 (file)
@@ -50,6 +50,7 @@ namespace {
     // FIXME: VisitMemberExpr
     // FIXME: CompoundLiteralExpr
     OwningExprResult VisitBinaryOperator(BinaryOperator *E);
+    OwningExprResult VisitCompoundAssignOperator(CompoundAssignOperator *E);
     OwningExprResult VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
     OwningExprResult VisitCXXConditionDeclExpr(CXXConditionDeclExpr *E);
     OwningExprResult VisitConditionalOperator(ConditionalOperator *E);
@@ -283,6 +284,12 @@ TemplateExprInstantiator::VisitBinaryOperator(BinaryOperator *E) {
   return move(Result);
 }
 
+Sema::OwningExprResult 
+TemplateExprInstantiator::VisitCompoundAssignOperator(
+                                                 CompoundAssignOperator *E) {
+  return VisitBinaryOperator(E);
+}
+
 Sema::OwningExprResult 
 TemplateExprInstantiator::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
   Sema::OwningExprResult First = Visit(E->getArg(0));
index cf6139d0cec7c7f8b440dcb62bfea6517d0eaa26..892f649ef7a6911d16f3253ffa8951076188b1a2 100644 (file)
@@ -9,3 +9,32 @@ struct ImaginaryLiteral0 {
 
 template struct ImaginaryLiteral0<_Complex float>;
 template struct ImaginaryLiteral0<int*>; // expected-note{{instantiation}}
+
+namespace N1 {
+  struct X { };
+
+  int& operator+=(X&, int); // expected-note{{candidate}}
+}
+
+namespace N2 {
+  long& operator+=(N1::X&, long); // expected-note{{candidate}}
+
+  template<typename T, typename U, typename Result>
+  struct PlusEquals0 {
+    void f(T t, U u) {
+      Result r = t += u; // expected-error{{ambiguous}}
+    }
+  };
+}
+
+namespace N3 {
+  struct Y : public N1::X {
+    short& operator+=(long); // expected-note{{candidate}}
+  };
+}
+
+template struct N2::PlusEquals0<N1::X, int, int&>;
+template struct N2::PlusEquals0<N1::X, long, long&>;
+template struct N2::PlusEquals0<N3::Y, long, short&>;
+template struct N2::PlusEquals0<int, int, int&>;
+template struct N2::PlusEquals0<N3::Y, int, short&>; // expected-note{{instantiation}}