]> granicus.if.org Git - clang/commitdiff
Emit an error when trying to form a pointer-to-member to a bitfield.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 30 Oct 2010 19:52:22 +0000 (19:52 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 30 Oct 2010 19:52:22 +0000 (19:52 +0000)
As a bonus, avoids a crash on the IRGen side due to accepting invalid code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117842 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/SemaCXX/ptrtomember.cpp

index 19b2b5bae99734bec92beb01e9381557c7d8d81a..6829557734f49440c5b2ee9dc91ef8536d306c37 100644 (file)
@@ -1930,6 +1930,11 @@ FieldDecl *Expr::getBitField() {
       if (Field->isBitField())
         return Field;
 
+  if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E))
+    if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl()))
+      if (Field->isBitField())
+        return Field;
+
   if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E))
     if (BinOp->isAssignmentOp() && BinOp->getLHS())
       return BinOp->getLHS()->getBitField();
index fb774d85e3e4882ed21e2155066d4886787bbdfd..e84e931ee80c751604bf49f2b499938b1391b706 100644 (file)
@@ -11,3 +11,8 @@ int foo(int S::* ps, S *s)
     return (s->*ps)(1); // expected-error {{called object type 'int' is not a function or function pointer}}
 }
 
+struct S2 {
+  int bitfield : 1;
+};
+
+int S2::*pf = &S2::bitfield; // expected-error {{address of bit-field requested}}