This revision was not accepted when it landed; it landed in state "Needs Review". This revision was automatically updated to reflect the committed changes. Closed by commit rGa58017e5cae5: Fix type-dependency of bitfields in templates (authored by eandrews). Herald added a project: clang.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D72242/new/ https://reviews.llvm.org/D72242 Files: clang/lib/AST/Expr.cpp clang/test/SemaTemplate/enum-argument.cpp clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp =================================================================== --- /dev/null +++ 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) + ; + } +}; Index: clang/test/SemaTemplate/enum-argument.cpp =================================================================== --- clang/test/SemaTemplate/enum-argument.cpp +++ 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 @@ unsigned long long bitfield : e0; void f(int j) { - bitfield + j; // expected-warning {{expression result unused}} + bitfield + j; } }; } Index: clang/lib/AST/Expr.cpp =================================================================== --- clang/lib/AST/Expr.cpp +++ clang/lib/AST/Expr.cpp @@ -1680,6 +1680,11 @@ 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) {
Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp =================================================================== --- /dev/null +++ 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) + ; + } +}; Index: clang/test/SemaTemplate/enum-argument.cpp =================================================================== --- clang/test/SemaTemplate/enum-argument.cpp +++ 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 @@ unsigned long long bitfield : e0; void f(int j) { - bitfield + j; // expected-warning {{expression result unused}} + bitfield + j; } }; } Index: clang/lib/AST/Expr.cpp =================================================================== --- clang/lib/AST/Expr.cpp +++ clang/lib/AST/Expr.cpp @@ -1680,6 +1680,11 @@ 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) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits