2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2009-06-26 06:40:36 +08:00
|
|
|
|
2010-04-15 08:00:53 +08:00
|
|
|
class Base { // expected-error {{cannot define the implicit default assignment operator for 'Base', because non-static reference member 'ref' can't use default assignment operator}} \
|
Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators.
Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.
This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:
- For a class subobject, call the appropriate copy-assignment
operator, after overload resolution has determined what that is.
- For an array of scalar types or an array of class types that have
trivial copy assignment operators, construct a call to
__builtin_memcpy.
- For an array of class types with non-trivial copy assignment
operators, synthesize a (possibly nested!) for loop whose inner
statement calls the copy constructor.
- For a scalar type, use built-in assignment.
This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.
Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.
llvm-svn: 102853
2010-05-02 04:49:11 +08:00
|
|
|
// expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}} \
|
|
|
|
// expected-note {{synthesized method is first required here}}
|
2010-04-23 10:20:12 +08:00
|
|
|
int &ref; // expected-note {{declared here}} \
|
2010-04-15 08:00:53 +08:00
|
|
|
// expected-note{{reference member 'ref' will never be initialized}}
|
2009-06-26 06:40:36 +08:00
|
|
|
};
|
|
|
|
|
Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators.
Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.
This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:
- For a class subobject, call the appropriate copy-assignment
operator, after overload resolution has determined what that is.
- For an array of scalar types or an array of class types that have
trivial copy assignment operators, construct a call to
__builtin_memcpy.
- For an array of class types with non-trivial copy assignment
operators, synthesize a (possibly nested!) for loop whose inner
statement calls the copy constructor.
- For a scalar type, use built-in assignment.
This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.
Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.
llvm-svn: 102853
2010-05-02 04:49:11 +08:00
|
|
|
class X : Base { // // expected-error {{cannot define the implicit default assignment operator for 'X', because non-static const member 'cint' can't use default assignment operator}} \
|
|
|
|
// expected-note {{synthesized method is first required here}}
|
2009-06-26 06:40:36 +08:00
|
|
|
public:
|
|
|
|
X();
|
2010-04-23 10:20:12 +08:00
|
|
|
const int cint; // expected-note {{declared here}}
|
2009-06-26 06:40:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Y : X {
|
|
|
|
Y();
|
|
|
|
Y& operator=(const Y&);
|
|
|
|
Y& operator=(volatile Y&);
|
|
|
|
Y& operator=(const volatile Y&);
|
|
|
|
Y& operator=(Y&);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Z : Y {};
|
|
|
|
|
|
|
|
Z z1;
|
|
|
|
Z z2;
|
|
|
|
|
|
|
|
// Test1
|
|
|
|
void f(X x, const X cx) {
|
Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators.
Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.
This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:
- For a class subobject, call the appropriate copy-assignment
operator, after overload resolution has determined what that is.
- For an array of scalar types or an array of class types that have
trivial copy assignment operators, construct a call to
__builtin_memcpy.
- For an array of class types with non-trivial copy assignment
operators, synthesize a (possibly nested!) for loop whose inner
statement calls the copy constructor.
- For a scalar type, use built-in assignment.
This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.
Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.
llvm-svn: 102853
2010-05-02 04:49:11 +08:00
|
|
|
x = cx;
|
2009-06-26 06:40:36 +08:00
|
|
|
x = cx;
|
|
|
|
z1 = z2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test2
|
|
|
|
class T {};
|
|
|
|
T t1;
|
|
|
|
T t2;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void g() {
|
2009-06-26 06:40:36 +08:00
|
|
|
t1 = t2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test3
|
|
|
|
class V {
|
|
|
|
public:
|
|
|
|
V();
|
|
|
|
V &operator = (V &b);
|
|
|
|
};
|
|
|
|
|
|
|
|
class W : V {};
|
|
|
|
W w1, w2;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void h() {
|
2009-06-26 06:40:36 +08:00
|
|
|
w1 = w2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test4
|
|
|
|
|
|
|
|
class B1 {
|
|
|
|
public:
|
|
|
|
B1();
|
|
|
|
B1 &operator = (B1 b);
|
|
|
|
};
|
|
|
|
|
|
|
|
class D1 : B1 {};
|
|
|
|
D1 d1, d2;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void i() {
|
|
|
|
d1 = d2;
|
2009-06-26 06:40:36 +08:00
|
|
|
}
|
|
|
|
|
2009-07-10 01:47:25 +08:00
|
|
|
// Test5
|
|
|
|
|
Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators.
Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.
This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:
- For a class subobject, call the appropriate copy-assignment
operator, after overload resolution has determined what that is.
- For an array of scalar types or an array of class types that have
trivial copy assignment operators, construct a call to
__builtin_memcpy.
- For an array of class types with non-trivial copy assignment
operators, synthesize a (possibly nested!) for loop whose inner
statement calls the copy constructor.
- For a scalar type, use built-in assignment.
This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.
Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.
llvm-svn: 102853
2010-05-02 04:49:11 +08:00
|
|
|
class E1 { // expected-error{{cannot define the implicit default assignment operator for 'E1', because non-static const member 'a' can't use default assignment operator}} \
|
|
|
|
// expected-note {{synthesized method is first required here}}
|
|
|
|
|
2009-07-10 01:47:25 +08:00
|
|
|
public:
|
2010-04-23 10:20:12 +08:00
|
|
|
const int a; // expected-note{{declared here}}
|
2009-07-10 01:47:25 +08:00
|
|
|
E1() : a(0) {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
E1 e1, e2;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void j() {
|
Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators.
Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.
This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:
- For a class subobject, call the appropriate copy-assignment
operator, after overload resolution has determined what that is.
- For an array of scalar types or an array of class types that have
trivial copy assignment operators, construct a call to
__builtin_memcpy.
- For an array of class types with non-trivial copy assignment
operators, synthesize a (possibly nested!) for loop whose inner
statement calls the copy constructor.
- For a scalar type, use built-in assignment.
This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.
Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.
llvm-svn: 102853
2010-05-02 04:49:11 +08:00
|
|
|
e1 = e2;
|
2009-07-10 01:47:25 +08:00
|
|
|
}
|
|
|
|
|
2010-05-04 23:20:55 +08:00
|
|
|
namespace ProtectedCheck {
|
|
|
|
struct X {
|
|
|
|
protected:
|
|
|
|
X &operator=(const X&); // expected-note{{declared protected here}}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Y : public X { };
|
|
|
|
|
|
|
|
void f(Y y) { y = y; }
|
|
|
|
|
|
|
|
struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}}
|
|
|
|
X x;
|
|
|
|
};
|
|
|
|
|
|
|
|
void f(Z z) { z = z; } //
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MultiplePaths {
|
|
|
|
struct X0 {
|
|
|
|
X0 &operator=(const X0&);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct X1 : public virtual X0 { };
|
|
|
|
|
|
|
|
struct X2 : X0, X1 { };
|
|
|
|
|
|
|
|
void f(X2 x2) { x2 = x2; }
|
|
|
|
}
|