summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/conditional-expr.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-04-02 18:24:57 +0000
committerDouglas Gregor <dgregor@apple.com>2010-04-02 18:24:57 +0000
commit45cf7e3d2a524e751c2d5c35f2761a8cfbc47fdd (patch)
tree758fe66ff8493c68ce04d93ab2ca1c9709f311b2 /clang/test/SemaCXX/conditional-expr.cpp
parent4b82a8876434e76921f15f4b395440179515b7b5 (diff)
downloadbcm5719-llvm-45cf7e3d2a524e751c2d5c35f2761a8cfbc47fdd.tar.gz
bcm5719-llvm-45cf7e3d2a524e751c2d5c35f2761a8cfbc47fdd.zip
Rework our handling of copy construction of temporaries, which was a
poor (and wrong) approximation of the actual rules governing when to build a copy and when it can be elided. The correct implementation is actually simpler than the approximation. When we only enumerate constructors as part of initialization (e.g., for direct initialization or when we're copying from a class type or one of its derived classes), we don't create a copy. When we enumerate all conversion functions, we do create a copy. Before, we created some extra copies and missed some others. The new test copy-initialization.cpp shows a case where we missed creating a (required, non-elidable) copy as part of a user-defined conversion, which resulted in a miscompile. This commit also fixes PR6757, where the missing copy made us reject well-formed code in the ternary operator. This commit also cleans up our handling of copy elision in the case where we create an extra copy of a temporary object, which became necessary now that we produce the right copies. The code that seeks to find the temporary object being copied has moved into Expr::getTemporaryObject(); it used to have two different not-quite-the-same implementations, one in Sema and one in CodeGen. Note that we still do not attempt to perform the named return value optimization, so we miss copy elisions for return values and throw expressions. llvm-svn: 100196
Diffstat (limited to 'clang/test/SemaCXX/conditional-expr.cpp')
-rw-r--r--clang/test/SemaCXX/conditional-expr.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp
index e2a966bdd95..49bcd99fb69 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -213,3 +213,30 @@ namespace PR6595 {
(void)(Cond? a : S);
}
}
+
+namespace PR6757 {
+ struct Foo1 {
+ Foo1();
+ Foo1(const Foo1&);
+ };
+
+ struct Foo2 { };
+
+ struct Foo3 {
+ Foo3();
+ Foo3(Foo3&);
+ };
+
+ struct Bar {
+ operator const Foo1&() const;
+ operator const Foo2&() const;
+ operator const Foo3&() const;
+ };
+
+ void f() {
+ (void)(true ? Bar() : Foo1()); // okay
+ (void)(true ? Bar() : Foo2()); // okay
+ // FIXME: Diagnostic below could be improved
+ (void)(true ? Bar() : Foo3()); // expected-error{{incompatible operand types ('PR6757::Bar' and 'PR6757::Foo3')}}
+ }
+}
OpenPOWER on IntegriCloud