summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/rval-references.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fold -Wreturn-stack-address into general initialization lifetimeRichard Smith2018-07-231-3/+2
| | | | | | checking. llvm-svn: 337743
* [Sema] Allow static_cast<T&&>(e) to check explicit conversions for ↵Eric Fiselier2016-11-031-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | non-reference-related types. Summary: [expr.cast.static] states: > 3. A glvalue of type “cv1 T1” can be cast to type “rvalue reference to cv2 T2” if “cv2 T2” is reference-compatible > with “cv1 T1”. The result refers to the object or the specified base class subobject thereof. If T2 is > an inaccessible or ambiguous base class of T1, a program that necessitates such a cast is > ill-formed. > > 4. Otherwise, an expression e can be explicitly converted to a type T using a static_cast of the form static_- > cast<T>(e) if the declaration T t(e); is well-formed, for some invented temporary variable t. [...] Currently when checking p3 Clang will diagnose `static_cast<T&&>(e)` as invalid if the argument is not reference compatible with `T`. However I believe the correct behavior is to also check p4 in those cases. For example: ``` double y = 42; static_cast<int&&>(y); // this should be OK. 'int&& t(y)' is well formed ``` Note that we still don't check p4 for non-reference-compatible types which are reference-related since `T&& t(e);` should never be well formed in those cases. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26231 llvm-svn: 285872
* [Sema] Implement C++14's DR1579: Prefer returning by converting move constructorErik Pilkington2016-06-301-8/+2
| | | | | | | | Fixes PR28096. Differential Revision: http://reviews.llvm.org/D21619 llvm-svn: 274291
* Clarify the error message when the reason the conversion is not viable is ↵Nick Lewycky2015-08-251-1/+1
| | | | | | because the returned value does not match the function return type. llvm-svn: 245979
* Update all tests other than Driver/std.cpp to use -std=c++11 rather thanRichard Smith2011-10-131-1/+1
| | | | | | -std=c++0x. Patch by Ahmed Charles! llvm-svn: 141900
* Move test, so it actually tests what it is supposed to (given that we don't ↵Eli Friedman2011-09-271-8/+0
| | | | | | have an AST verifier). llvm-svn: 140620
* PR11009: Fix a FIXME which was leading to an assertion failure with rvalue ↵Eli Friedman2011-09-271-0/+8
| | | | | | references. llvm-svn: 140594
* Add -fcxx-exceptions to all tests that use C++ exceptions.Anders Carlsson2011-02-281-1/+1
| | | | llvm-svn: 126599
* Pass -fexceptions to all tests that use try/catch/throw.Anders Carlsson2011-02-191-1/+1
| | | | llvm-svn: 126037
* Improve the diagnostic that complains about binding an rvalueDouglas Gregor2011-01-211-2/+2
| | | | | | reference to an lvalue. llvm-svn: 123953
* More work to bring reference binding up to the latest C++0xDouglas Gregor2011-01-211-1/+1
| | | | | | | | | | specification. In particular, an rvalue reference can bind to an initializer expression that is an lvalue if the referent type and the initializer expression type are not reference-related. This is a newer formulation to the previous "rvalue references can never bind to lvalues" rule. llvm-svn: 123952
* Follow through references to catch returned stack addresses, local blocks, ↵Argyrios Kyrtzidis2010-11-301-1/+1
| | | | | | | | | | | | label addresses or references to temporaries, e.g: const int& g2() { int s1; int &s2 = s1; // expected-note {{binding reference variable 's2' here}} return s2; // expected-warning {{reference to stack memory associated with local variable 's1' returned}} } llvm-svn: 120483
* Revert r120331 since it causes spurious warnings and a possible assertion ↵Argyrios Kyrtzidis2010-11-291-1/+1
| | | | | | hit when self-host. llvm-svn: 120351
* Emit warnings if we are returning a reference to a local temporary.Argyrios Kyrtzidis2010-11-291-1/+1
| | | | | | The issue was brought to our attention by Matthieu Monrocq. llvm-svn: 120331
* Make both old and new versions of reference binding use the new ↵Sebastian Redl2010-06-301-0/+7
| | | | | | classification functions, and updated them for N3092. llvm-svn: 107301
* When pretty-printing tag types, only print the tag if we're in C (andJohn McCall2010-03-101-2/+2
| | | | | | | | | | therefore not creating ElaboratedTypes, which are still pretty-printed with the written tag). Most of these testcase changes were done by script, so don't feel too sorry for my fingers. llvm-svn: 98149
* Change the printing of OR_Deleted overload results to print all the candidates,John McCall2010-01-081-1/+1
| | | | | | | | | | | | | | | not just the viable ones. This is reasonable because the most common use of deleted functions is to exclude some implicit conversion during calls; users therefore will want to figure out why some other options were excluded. Started sorting overload results. Right now it just sorts by location in the translation unit (after putting viable functions first), but we can do better than that. Changed bool OnlyViable parameter to PrintOverloadCandidates to an enum for better self-documentation. llvm-svn: 92990
* Improve the diagnostics used to report implicitly-generated class membersJohn McCall2010-01-061-2/+2
| | | | | | | | | as parts of overload sets. Also, refer to constructors as 'constructors' rather than functions. Adjust a lot of tests. llvm-svn: 92832
* Switch the initialization required by return statements over to theDouglas Gregor2009-12-181-9/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | new InitializationSequence. This fixes some bugs (e.g., PR5808), changed some diagnostics, and caused more churn than expected. What's new: - InitializationSequence now has a "C conversion sequence" category and step kind, which falls back to - Changed the diagnostics for returns to always have the result type of the function first and the type of the expression second. CheckSingleAssignmentConstraints to peform checking in C. - Improved ASTs for initialization of return values. The ASTs now capture all of the temporaries we need to create, but intentionally do not bind the tempoary that is actually returned, so that it won't get destroyed twice. - Make sure to perform an (elidable!) copy of the class object that is returned from a class. - Fix copy elision in CodeGen to properly see through the subexpressions that occur with elidable copies. - Give "new" its own entity kind; as with return values and thrown objects, we don't bind the expression so we don't call a destructor for it. Note that, with this patch, I've broken returning move-only types in C++0x. We'll fix it later, when we tackle NRVO. llvm-svn: 91669
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). llvm-svn: 91446
* Reimplement reference initialization (C++ [dcl.init.ref]) using theDouglas Gregor2009-12-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | new notion of an "initialization sequence", which encapsulates the computation of the initialization sequence along with diagnostic information and the capability to turn the computed sequence into an expression. At present, I've only switched one CheckReferenceInit callers over to this new mechanism; more will follow. Aside from (hopefully) being much more true to the standard, the diagnostics provided by this reference-initialization code are a bit better than before. Some examples: p5-var.cpp:54:12: error: non-const lvalue reference to type 'struct Derived' cannot bind to a value of unrelated type 'struct Base' Derived &dr2 = b; // expected-error{{non-const lvalue reference to ... ^ ~ p5-var.cpp:55:9: error: binding of reference to type 'struct Base' to a value of type 'struct Base const' drops qualifiers Base &br3 = bc; // expected-error{{drops qualifiers}} ^ ~~ p5-var.cpp:57:15: error: ambiguous conversion from derived class 'struct Diamond' to base class 'struct Base': struct Diamond -> struct Derived -> struct Base struct Diamond -> struct Derived2 -> struct Base Base &br5 = diamond; // expected-error{{ambiguous conversion from ... ^~~~~~~ p5-var.cpp:59:9: error: non-const lvalue reference to type 'long' cannot bind to a value of unrelated type 'int' long &lr = i; // expected-error{{non-const lvalue reference to type ... ^ ~ p5-var.cpp:74:9: error: non-const lvalue reference to type 'struct Base' cannot bind to a temporary of type 'struct Base' Base &br1 = Base(); // expected-error{{non-const lvalue reference to ... ^ ~~~~~~ p5-var.cpp:102:9: error: non-const reference cannot bind to bit-field 'i' int & ir1 = (ib.i); // expected-error{{non-const reference cannot ... ^ ~~~~~~ p5-var.cpp:98:7: note: bit-field is declared here int i : 17; // expected-note{{bit-field is declared here}} ^ llvm-svn: 90992
* Improve on diagnosing type mismatches because of Fariborz Jahanian2009-11-181-4/+4
| | | | | | lack of viable convesion functions. llvm-svn: 89216
* Parse deleted member functions. Parsing member declarations goes through a ↵Sebastian Redl2009-04-121-0/+37
| | | | | | | | | different code path that I forgot previously. Implement the rvalue reference overload dance for returning local objects. Returning a local object first tries to find a move constructor now. The error message when no move constructor is defined (or is not applicable) and the copy constructor is deleted is quite ugly, though. llvm-svn: 68902
* Reintroduce r67870 (rval ref overloading), since I can't reproduce any test ↵Sebastian Redl2009-03-291-2/+3
| | | | | | failures on i386 or x86_64. If this fails for someone, please contact me. llvm-svn: 67999
* Revert Sebastian's rvalue patch (r67870) since it caused test failures inAnders Carlsson2009-03-281-3/+2
| | | | | | | | SemaCXX//overload-member-call.cpp SemaCXX//overloaded-operator.cpp SemaTemplate//instantiate-method.cpp llvm-svn: 67912
* Better overload resolution for rvalue references.Sebastian Redl2009-03-271-2/+3
| | | | llvm-svn: 67870
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* Disallow catching exceptions by rvalue reference.Sebastian Redl2009-03-221-0/+5
| | | | llvm-svn: 67492
* Implement static_cast from lvalue to rvalue reference.Sebastian Redl2009-03-221-0/+2
| | | | llvm-svn: 67487
* Some minor tweaks and additional tests for rvalue referencesDouglas Gregor2009-03-201-2/+15
| | | | llvm-svn: 67397
* Almost complete implementation of rvalue references. One bug, and a few ↵Sebastian Redl2009-03-161-0/+33
unclear areas. Maybe Doug can shed some light on some of the fixmes. llvm-svn: 67059
OpenPOWER on IntegriCloud