]> granicus.if.org Git - clang/commitdiff
Make sure isCopyAssignment is only true for actual copy assignment operators,
authorEli Friedman <eli.friedman@gmail.com>
Sat, 7 Nov 2009 00:02:45 +0000 (00:02 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 7 Nov 2009 00:02:45 +0000 (00:02 +0000)
instead of all assignment operators.  The mistake messes up IRGen because
it ends up assuming that the assignment operator is actually the implicit
copy assignment operator, and therefore tries to emit the RHS as an lvalue.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86307 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/assign-operator.cpp [new file with mode: 0644]

index b4c0c59733e53087a8fa5abc24bf023a78aaad0c..e325a25c76278e7114309483951b4fd4bd3262c4 100644 (file)
@@ -280,6 +280,9 @@ void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context,
     return;
 
   // This is a copy assignment operator.
+  // Note on the decl that it is a copy assignment operator.
+  OpDecl->setCopyAssignment(true);
+
   // Suppress the implicit declaration of a copy constructor.
   UserDeclaredCopyAssignment = true;
 
index f3561bfa0f4d48774197a9b267f776baeda4bca6..c7fd5ccd1e6f67865a6f2bc8dd8db470054a8141 100644 (file)
@@ -4183,7 +4183,6 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
     assert(isa<CXXMethodDecl>(FnDecl) &&
       "Overloaded = not member, but not filtered.");
     CXXMethodDecl *Method = cast<CXXMethodDecl>(FnDecl);
-    Method->setCopyAssignment(true);
     Method->getParent()->addedAssignmentOperator(Context, Method);
   }
 
diff --git a/test/CodeGenCXX/assign-operator.cpp b/test/CodeGenCXX/assign-operator.cpp
new file mode 100644 (file)
index 0000000..3e0be45
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: clang-cc %s -emit-llvm-only -verify
+
+class x {
+int operator=(int);
+};
+void a() {
+  x a;
+  a = 1u;
+}