[cfe-commits] r72212 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/copy-assignment.cpp test/SemaCXX/namespace.cpp test/SemaCXX/overloaded-builtin-operators.cpp test/SemaTemplate/qualified-names-diag.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Thu May 21 04:51:00 PDT 2009
Author: cornedbee
Date: Thu May 21 06:50:50 2009
New Revision: 72212
URL: http://llvm.org/viewvc/llvm-project?rev=72212&view=rev
Log:
Avoid using the built-in type checker for assignment in C++ when classes are involved. Patch by Vyacheslav Kononenko.
Added:
cfe/trunk/test/SemaCXX/copy-assignment.cpp (with props)
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/namespace.cpp
cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp
cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=72212&r1=72211&r2=72212&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu May 21 06:50:50 2009
@@ -4020,6 +4020,15 @@
}
case OR_No_Viable_Function:
+ // For class as left operand for assignment or compound assigment operator
+ // do not fall through to handling in built-in, but report that no overloaded
+ // assignment operator found
+ if (LHS->getType()->isRecordType() && Opc >= BinaryOperator::Assign && Opc <= BinaryOperator::OrAssign) {
+ Diag(OpLoc, diag::err_ovl_no_viable_oper)
+ << BinaryOperator::getOpcodeStr(Opc)
+ << LHS->getSourceRange() << RHS->getSourceRange();
+ return ExprError();
+ }
// No viable function; fall through to handling this as a
// built-in operator, which will produce an error message for us.
break;
Added: cfe/trunk/test/SemaCXX/copy-assignment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/copy-assignment.cpp?rev=72212&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/copy-assignment.cpp (added)
+++ cfe/trunk/test/SemaCXX/copy-assignment.cpp Thu May 21 06:50:50 2009
@@ -0,0 +1,99 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+struct A {
+};
+
+struct ConvertibleToA {
+ operator A();
+};
+
+struct ConvertibleToConstA {
+ operator const A();
+};
+
+struct B {
+ B& operator=(B&);
+};
+
+struct ConvertibleToB {
+ operator B();
+};
+
+struct ConvertibleToBref {
+ operator B&();
+};
+
+struct ConvertibleToConstB {
+ operator const B();
+};
+
+struct ConvertibleToConstBref {
+ operator const B&();
+};
+
+struct C {
+ int operator=(int); // expected-note{{candidate function}}
+ long operator=(long); // expected-note{{candidate function}}
+ int operator+=(int); // expected-note{{candidate function}}
+ int operator+=(long); // expected-note{{candidate function}}
+};
+
+struct D {
+ D& operator+=(const D &);
+};
+
+struct ConvertibleToInt {
+ operator int();
+};
+
+void test() {
+ A a, na;
+ const A constA;
+ ConvertibleToA convertibleToA;
+ ConvertibleToConstA convertibleToConstA;
+
+ B b, nb;
+ const B constB;
+ ConvertibleToB convertibleToB;
+ ConvertibleToBref convertibleToBref;
+ ConvertibleToConstB convertibleToConstB;
+ ConvertibleToConstBref convertibleToConstBref;
+
+ C c, nc;
+ const C constC;
+
+ D d, nd;
+ const D constD;
+
+ ConvertibleToInt convertibleToInt;
+
+ na = a;
+ na = constA;
+ na = convertibleToA;
+ na = convertibleToConstA;
+ na += a; // expected-error{{no viable overloaded '+='}}
+
+ nb = b;
+ nb = constB; // expected-error{{no viable overloaded '='}}
+ nb = convertibleToB; // expected-error{{no viable overloaded '='}}
+ nb = convertibleToBref;
+ nb = convertibleToConstB; // expected-error{{no viable overloaded '='}}
+ nb = convertibleToConstBref; // expected-error{{no viable overloaded '='}}
+
+ nc = c;
+ nc = constC;
+ nc = 1;
+ nc = 1L;
+ nc = 1.0; // expected-error{{use of overloaded operator '=' is ambiguous}}
+ nc += 1;
+ nc += 1L;
+ nc += 1.0; // expected-error{{use of overloaded operator '+=' is ambiguous}}
+
+ nd = d;
+ nd += d;
+ nd += constD;
+
+ int i;
+ i = convertibleToInt;
+ i = a; // expected-error{{incompatible type assigning 'struct A', expected 'int'}}
+}
+
Propchange: cfe/trunk/test/SemaCXX/copy-assignment.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/SemaCXX/copy-assignment.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/SemaCXX/copy-assignment.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cfe/trunk/test/SemaCXX/namespace.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/namespace.cpp?rev=72212&r1=72211&r2=72212&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/namespace.cpp (original)
+++ cfe/trunk/test/SemaCXX/namespace.cpp Thu May 21 06:50:50 2009
@@ -37,7 +37,7 @@
namespace S3 {
void f() {
- x = 0; // expected-error {{incompatible type assigning 'int', expected 'class B'}}
+ x = 0; // expected-error {{no viable overloaded '='}}
}
}
Modified: cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp?rev=72212&r1=72211&r2=72212&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp (original)
+++ cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp Thu May 21 06:50:50 2009
@@ -118,5 +118,5 @@
// C++ [over.match.open]p4
void test_assign_restrictions(ShortRef& sr) {
- sr = (short)0; // expected-error{{incompatible type assigning 'short', expected 'struct ShortRef'}}
+ sr = (short)0; // expected-error{{no viable overloaded '='}}
}
Modified: cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp?rev=72212&r1=72211&r2=72212&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp (original)
+++ cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp Thu May 21 06:50:50 2009
@@ -12,5 +12,5 @@
std::vector<INT> v1;
vector<Real> v2;
- v1 = v2; // expected-error{{incompatible type assigning 'vector<Real>', expected 'std::vector<INT>'}}
+ v1 = v2; // expected-error{{no viable overloaded '='}}
}
More information about the cfe-commits
mailing list