Author: Elizabeth Andrews
Date: 2020-02-12T13:31:41-08:00
New Revision: a58017e5cae5be948fd1913b68d46553e87aa622

URL: 
https://github.com/llvm/llvm-project/commit/a58017e5cae5be948fd1913b68d46553e87aa622
DIFF: 
https://github.com/llvm/llvm-project/commit/a58017e5cae5be948fd1913b68d46553e87aa622.diff

LOG: Fix type-dependency of bitfields in templates

This patch is a follow up to 878a24ee244a24. Name of bitfields
with value-dependent width should be set as type-dependent. This
patch adds the required value-dependency check and sets the
type-dependency accordingly.

Patch fixes PR44886

Differential revision: https://reviews.llvm.org/D72242

Added: 
    clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp

Modified: 
    clang/lib/AST/Expr.cpp
    clang/test/SemaTemplate/enum-argument.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index d9291616c66a..7e8808f84ead 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1680,6 +1680,11 @@ MemberExpr *MemberExpr::Create(
     CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
     if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC))
       E->setTypeDependent(T->isDependentType());
+
+    // Bitfield with value-dependent width is type-dependent.
+    FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl);
+    if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent())
+      E->setTypeDependent(true);
   }
 
   if (HasQualOrFound) {

diff  --git a/clang/test/SemaTemplate/enum-argument.cpp 
b/clang/test/SemaTemplate/enum-argument.cpp
index a79ed8403e9f..7ff419613990 100644
--- a/clang/test/SemaTemplate/enum-argument.cpp
+++ b/clang/test/SemaTemplate/enum-argument.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
 
 enum Enum { val = 1 };
 template <Enum v> struct C {
@@ -30,7 +31,7 @@ namespace rdar8020920 {
     unsigned long long bitfield : e0;
 
     void f(int j) {
-      bitfield + j; // expected-warning {{expression result unused}}
+      bitfield + j;
     }
   };
 }

diff  --git a/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp 
b/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
new file mode 100644
index 000000000000..873e4d48e837
--- /dev/null
+++ b/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template <int b>
+class A {
+  int c : b;
+
+public:
+  void f() {
+    if (c)
+      ;
+  }
+};


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to