On Tue, Nov 03, 2026 at 01:45:03PM -0500, Jason Merrill wrote:
> > @@ -1524,6 +1547,19 @@ structural_comptypes (tree t1, tree t2,
> > /* We don't need or want the attribute comparison. */
> > goto check_alias;
> > + case BITINT_TYPE:
> > + /* Similar to INTEGER_TYPE, just have to compare BITINT_PREC for
> > + dependent bit-precise integers. */
> > + if (TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
> > + return false;
> It doesn't make sense to compare TYPE_CANONICAL in structural_comptypes;
> this is where we do structural comparison, often to verify that
> TYPE_CANONICAL is right.
I was trying to follow what is done for INTEGER_TYPE, which compares
TYPE_CANONICAL.
> And relatedly, it seems that dependent
> redeclarations don't work:
>
> template<int N> struct A { void f(_BitInt(N)); };
> template<int N> void A<N>::f(_BitInt(N)) { } // { dg-bogus "match" }
>
>
> template<int N> struct B { static _BitInt(N) m; };
> template<int N> _BitInt(N) B<N>::m; // { dg-bogus "conflict" }
>
>
> template<int N> void f(_BitInt(N));
> template<int N> void f(_BitInt(N));
> int main() { f<5>(0wb); } // { dg-bogus "ambiguous" }
>
>
> The simplest fix is probably to use SET_TYPE_STRUCTURAL_EQUALITY for
> dependent bitints in finish_bitint?
I thought TYPE_CANONICAL was NULL for the dependent BITINT_TYPEs, but will
double-check tomorrow, debug the above cases and adjust.
> > @@ -5235,7 +5274,8 @@ warn_for_null_address (location_t locati
> > {
> > /* Allow casts to intptr_t to suppress the warning. */
> > tree type = TREE_TYPE (cop);
> > - if (TREE_CODE (type) == INTEGER_TYPE)
> > + if (TREE_CODE (type) == INTEGER_TYPE
> > + || TREE_CODE (type) == BITINT_TYPE)
>
> The comment talks specifically about intptr_t, so it's not clear to me that
> adding BITINT_TYPE is desirable here.
Ok, wasn't sure if _BitInt(PTR_WIDTH) should be treated like that too or
not, guess only doing it for intptr_t which is required not to be
bit-precise is ok.
> > --- a/gcc/cp/call.cc 2026-10-30 17:05:21.676552682 +0100
> > +++ b/gcc/cp/call.cc 2026-10-30 21:48:13.139153037 +0100
> > @@ -564,7 +564,8 @@ null_ptr_cst_p (tree t)
> > /* Core issue 903 says only literal 0 is a null pointer constant.
> > */
> > if (TREE_CODE (t) == INTEGER_CST
> > && !TREE_OVERFLOW (t)
> > - && TREE_CODE (type) == INTEGER_TYPE
> > + && (TREE_CODE (type) == INTEGER_TYPE
> > + || TREE_CODE (type) == BITINT_TYPE)
> > && integer_zerop (t)
> > && !char_type_p (type))
> > return true;
>
> This is surprising, but I guess it does match the proposal.
Yeah, for this I've checked it in the proposal.
> > @@ -7374,7 +7378,8 @@ layout_class_type (tree t, tree *virtual
> > to that width. */
> > && (DECL_SIZE (field) == NULL_TREE
> > || integer_zerop (DECL_SIZE (field)))
> > - && TREE_TYPE (field) != error_mark_node)
> > + && TREE_TYPE (field) != error_mark_node
> > + && DECL_BIT_FIELD (field))
>
> Why is this needed?
Because SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD's checking internally
verifies DECL_BIT_FIELD. And stor-layout.cc has
/* Turn off DECL_BIT_FIELD if we won't need it set. */
if (TYPE_MODE (type) == BLKmode && DECL_MODE (decl) == BLKmode
&& known_align >= TYPE_ALIGN (type)
&& DECL_ALIGN (decl) >= TYPE_ALIGN (type))
DECL_BIT_FIELD (decl) = 0;
>
> > SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
Now, because _BitInt is new, we don't need the ABI warning for
those, so it doesn't matter that we don't set it for those.
Could simply add TREE_CODE (TREE_TYPE (field)) != BITINT_TYPE
to the condition instead.
> > --- a/gcc/testsuite/lib/target-supports.exp 2026-10-30 21:46:29.410733259
> > +0100
> > +++ b/gcc/testsuite/lib/target-supports.exp 2026-10-30 21:48:13.144228230
> > +0100
> > @@ -4649,37 +4649,57 @@ proc check_effective_target_fixed_point
> > # Return 1 if the target supports _BitInt(N), 0 otherwise.
> > proc check_effective_target_bitint { } {
> > + if [check_effective_target_c++] {
> > + set opts "-std=c++29"
> > + } else {
> > + set opts =-std=c23"
>
> Typo = for " breaks C testing.
Yeah, found it the hard way overnight (where bootstrap succeeded but various
tests
failed because of that). Fixed in my copy, additionally added
-Wno-c++29-extensions to a few tests which tested _BitInt in c-c++-common
whenever __BITINT_MAXWIDTH__ was defined.
Thanks for your review, will work on it tomorrow or the day after it.
Jakub