]> granicus.if.org Git - clang/commitdiff
Some minor tweaks and additional tests for rvalue references
authorDouglas Gregor <dgregor@apple.com>
Fri, 20 Mar 2009 20:21:37 +0000 (20:21 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 20 Mar 2009 20:21:37 +0000 (20:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67397 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclCXX.cpp
test/Parser/cxx0x-rvalue-reference.cpp
test/SemaCXX/rval-references.cpp

index a3c7997c6ddfab9bfb23c72e9c65dc8db7c77d1a..5e9b0cd9f458d1aaadce6608f829acf4ad8c0dbb 100644 (file)
@@ -104,7 +104,7 @@ bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context) const {
     QualType ArgType = FnType->getArgType(0);
     if (const LValueReferenceType *Ref = ArgType->getAsLValueReferenceType()) {
       ArgType = Ref->getPointeeType();
-      // Is it a non-const reference?
+      // Is it a non-const lvalue reference?
       if (!ArgType.isConstQualified())
         AcceptsConst = false;
     }
index 36432332722d403ee9d9ab322a527d7b0c8ad8ae..5736b79ff76ffac87b861a4ac4331d7960293fb1 100644 (file)
@@ -3,4 +3,7 @@
 int && r1(int &&a);
 
 typedef int && R;
-void r2(const R a);
+void r2(const R a) {
+  int & &&ar = a; // expected-error{{'ar' declared as a reference to a reference}}
+}
+
index ae2644919a7133e4ebe11cb64eec39e7ccd9e9a8..aafb334b849e90e2a80f7010689f3eb8d565ee72 100644 (file)
@@ -14,11 +14,17 @@ struct not_int {};
 int over(int&);
 not_int over(int&&);
 
+int over2(const int&);
+not_int over2(int&&);
+
+struct conv_to_not_int_rvalue {
+  operator not_int &&();
+};
+
 void f() {
   int &&virr1; // expected-error {{declaration of reference variable 'virr1' requires an initializer}}
   int &&virr2 = 0;
-  // FIXME: named rvalue references are lvalues!
-  //int &&virr3 = virr1; // xpected-error {{rvalue reference cannot bind to lvalue}}
+  int &&virr3 = virr2; // expected-error {{rvalue reference cannot bind to lvalue}}
   int i1 = 0;
   int &&virr4 = i1; // expected-error {{rvalue reference cannot bind to lvalue}}
   int &&virr5 = ret_irr();
@@ -28,6 +34,13 @@ void f() {
   int i3 = over(virr2);
   not_int ni2 = over(ret_irr());
 
+  int i4 = over2(i1);
+  // not_int ni3 = over2(0); FIXME: this should be well-formed.
+
   ilr_c1 vilr1 = i1;
   ilr_c2 vilr2 = i1;
+
+  conv_to_not_int_rvalue cnir;
+  not_int &&ni4 = cnir;
+  not_int &ni5 = cnir; // expected-error{{non-const lvalue reference to type 'struct not_int' cannot be initialized with a value of type 'struct conv_to_not_int_rvalue'}}
 }