[clang] 8156074 - Ensure that the "value" of an unnamed bit-field isn't taken into

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 21 18:52:10 PDT 2020


Author: Richard Smith
Date: 2020-10-21T18:51:55-07:00
New Revision: 81560743527e127ff8e47384db5dd60c7c40f153

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

LOG: Ensure that the "value" of an unnamed bit-field isn't taken into
account when determining the identity of a class NTTP.

Added: 
    

Modified: 
    clang/lib/AST/ExprConstant.cpp
    clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 00f9d4205581..e978a190a195 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9607,7 +9607,7 @@ static bool HandleClassZeroInitialization(EvalInfo &Info, const Expr *E,
 
   for (const auto *I : RD->fields()) {
     // -- if T is a reference type, no initialization is performed.
-    if (I->getType()->isReferenceType())
+    if (I->isUnnamedBitfield() || I->getType()->isReferenceType())
       continue;
 
     LValue Subobject = This;

diff  --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
index 1d9fefb6cbe5..75428a44eb32 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -201,3 +201,22 @@ namespace CTADPartialOrder {
   template<typename T, A<0> a> struct X<T, T, a> { static constexpr int n = 4; };
   static_assert(X<float, float, a>::n == 4);
 }
+
+namespace UnnamedBitfield {
+  struct A {
+    int : 16;
+  };
+  // Make sure we don't distinguish between the unnamed bit-field being
+  // uninitialized and it being zeroed. Those are not distinct states
+  // according to [temp.type]p2.
+  //
+  // FIXME: We shouldn't track a value for unnamed bit-fields, nor number
+  // them when computing field indexes.
+  template <A> struct X {};
+  constexpr A a;
+  using T = X<a>;
+  using T = X<A{}>;
+  using T = X<(A())>;
+  // Once we support bit-casts involving bit-fields, this should be valid too.
+  using T = X<__builtin_bit_cast(A, (unsigned short)0)>; // expected-error {{constant}} expected-note {{not yet supported}}
+}


        


More information about the cfe-commits mailing list