[cfe-commits] r39953 - in /cfe/trunk: AST/Expr.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h test/Sema/cxx-references.cpp

Bill Wendling isanbard at gmail.com
Mon Jul 16 20:52:32 PDT 2007


Author: void
Date: Mon Jul 16 22:52:31 2007
New Revision: 39953

URL: http://llvm.org/viewvc/llvm-project?rev=39953&view=rev
Log:
Fix references:
    According to the spec (C++ 5p6[expr]), we need to adjust "T&" to
    "T" before further analysis. We do this via the "implicit cast"
    thingy.

Added:
    cfe/trunk/test/Sema/cxx-references.cpp
Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=39953&r1=39952&r2=39953&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Mon Jul 16 22:52:31 2007
@@ -191,6 +191,7 @@
 ///  - e->name
 ///  - *e, the type of e cannot be a function type
 ///  - string-constant
+///  - reference type [C++ [expr]]
 ///
 Expr::isLvalueResult Expr::isLvalue() const {
   // first, check the type (C99 6.3.2.1)
@@ -199,7 +200,10 @@
 
   if (TR->isIncompleteType() && TR->isVoidType())
     return LV_IncompleteVoidType;
-    
+
+  if (isa<ReferenceType>(TR.getCanonicalType())) // C++ [expr]
+    return LV_Valid;
+
   // the type looks fine, now check the expression
   switch (getStmtClass()) {
   case StringLiteralClass: // C99 6.5.1p4

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=39953&r1=39952&r2=39953&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Mon Jul 16 22:52:31 2007
@@ -596,7 +596,9 @@
 void Sema::DefaultFunctionArrayConversion(Expr *&e) {
   QualType t = e->getType();
   assert(!t.isNull() && "DefaultFunctionArrayConversion - missing type");
-  
+
+  if (const ReferenceType *ref = dyn_cast<ReferenceType>(t.getCanonicalType()))
+    t = promoteExprToType(e, ref->getReferenceeType()); // C++ [expr]
   if (t->isFunctionType())
     promoteExprToType(e, Context.getPointerType(t));
   else if (const ArrayType *ary = dyn_cast<ArrayType>(t.getCanonicalType()))
@@ -612,6 +614,8 @@
   QualType t = expr->getType();
   assert(!t.isNull() && "UsualUnaryConversions - missing type");
   
+  if (const ReferenceType *ref = dyn_cast<ReferenceType>(t.getCanonicalType()))
+    t = promoteExprToType(expr, ref->getReferenceeType()); // C++ [expr]
   if (t->isPromotableIntegerType()) // C99 6.3.1.1p2
     promoteExprToType(expr, Context.IntTy);
   else

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=39953&r1=39952&r2=39953&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Jul 16 22:52:31 2007
@@ -61,6 +61,7 @@
   ///  - e->name
   ///  - *e, the type of e cannot be a function type
   ///  - string-constant
+  ///  - reference type [C++ [expr]]
   ///
   enum isLvalueResult {
     LV_Valid,

Added: cfe/trunk/test/Sema/cxx-references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/cxx-references.cpp?rev=39953&view=auto

==============================================================================
--- cfe/trunk/test/Sema/cxx-references.cpp (added)
+++ cfe/trunk/test/Sema/cxx-references.cpp Mon Jul 16 22:52:31 2007
@@ -0,0 +1,18 @@
+// RUN: clang -fsyntax-only %s
+int g(int);
+
+void f() {
+  int i;
+  int &r = i;
+  r = 1;
+  int *p = &r;
+  int &rr = r;
+  int (&rg)(int) = g;
+  rg(i);
+  int a[3];
+  int (&ra)[3] = a;
+  ra[1] = i;
+  int *Q;
+  int *& P = Q;
+  P[1] = 1;
+}





More information about the cfe-commits mailing list