[cfe-commits] r81808 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/conditional-expr.cpp

Anders Carlsson andersca at mac.com
Mon Sep 14 16:15:26 PDT 2009


Author: andersca
Date: Mon Sep 14 18:15:26 2009
New Revision: 81808

URL: http://llvm.org/viewvc/llvm-project?rev=81808&view=rev
Log:
Diagnose taking the address of a bit-field inside a conditional operator.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/conditional-expr.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 14 18:15:26 2009
@@ -5062,6 +5062,10 @@
     Diag(OpLoc, diag::err_typecheck_address_of)
       << "property expression" << op->getSourceRange();
     return QualType();
+  } else if (ConditionalOperator *CO = dyn_cast<ConditionalOperator>(op)) {
+    // FIXME: Can LHS ever be null here?
+    if (!CheckAddressOfOperand(CO->getLHS(), OpLoc).isNull())
+      return CheckAddressOfOperand(CO->getRHS(), OpLoc);
   } else if (dcl) { // C99 6.5.3.2p1
     // We have an lvalue with a decl. Make sure the decl is not declared
     // with the register storage-class specifier.

Modified: cfe/trunk/test/SemaCXX/conditional-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conditional-expr.cpp?rev=81808&r1=81807&r2=81808&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/conditional-expr.cpp (original)
+++ cfe/trunk/test/SemaCXX/conditional-expr.cpp Mon Sep 14 18:15:26 2009
@@ -174,7 +174,9 @@
   // Conversion of primitives does not result in an lvalue.
   &(i1 ? i1 : d1); // expected-error {{address expression must be an lvalue or a function designator}}
 
-
+  (void)&(i1 ? flds.b1 : flds.i1); // expected-error {{address of bit-field requested}}
+  (void)&(i1 ? flds.i1 : flds.b1); // expected-error {{address of bit-field requested}}
+  
   // Note the thing that this does not test: since DR446, various situations
   // *must* create a separate temporary copy of class objects. This can only
   // be properly tested at runtime, though.





More information about the cfe-commits mailing list