@@ -3174,10 +3174,12 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
31743174 if (dsym.semanticRun >= PASS .semanticdone)
31753175 return ;
31763176
3177- if (dsym.isAnonymous() && dsym._init)
3177+ const bool isAnonymous = dsym.isAnonymous();
3178+ if (isAnonymous && dsym._init)
31783179 {
31793180 .error(dsym.loc, " anonymous bitfield cannot have default initializer" );
31803181 dsym._init = null ;
3182+ dsym.errors = true ;
31813183 }
31823184
31833185 visit(cast (VarDeclaration)dsym);
@@ -3201,18 +3203,22 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
32013203 if (! dsym.type.isIntegral())
32023204 {
32033205 // C11 6.7.2.1-5
3204- error(dsym.loc, " bitfield type `%s` is not an integer type" , dsym.type.toChars());
3206+ if (isAnonymous)
3207+ error(dsym.loc, " anonymous bitfield cannot be of non-integral type `%s`" , dsym.type.toChars());
3208+ else
3209+ error(dsym.loc, " bitfield `%s` cannot be of non-integral type `%s`" , dsym.toChars(), dsym.type.toChars());
32053210 dsym.errors = true ;
3211+ return ;
32063212 }
32073213 if (! width.isIntegerExp())
32083214 {
32093215 error(width.loc, " bitfield width `%s` is not an integer constant" , dsym.width.toChars());
32103216 dsym.errors = true ;
32113217 }
32123218 const uwidth = width.toInteger(); // uwidth is unsigned
3213- if (uwidth == 0 && ! dsym. isAnonymous() )
3219+ if (uwidth == 0 && ! isAnonymous)
32143220 {
3215- error(width .loc, " bitfield `%s` has zero width" , dsym.toChars());
3221+ error(dsym .loc, " bitfield `%s` cannot have zero width" , dsym.toChars());
32163222 dsym.errors = true ;
32173223 }
32183224 const sz = dsym.type.size();
@@ -3221,7 +3227,10 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
32213227 const max_width = sz * 8 ;
32223228 if (uwidth > max_width)
32233229 {
3224- error(width.loc, " width `%lld` of bitfield `%s` does not fit in type `%s`" , cast (long )uwidth, dsym.toChars(), dsym.type.toChars());
3230+ if (isAnonymous)
3231+ error(width.loc, " width `%lld` of anonymous bitfield does not fit in type `%s`" , cast (long )uwidth, dsym.type.toChars());
3232+ else
3233+ error(width.loc, " width `%lld` of bitfield `%s` does not fit in type `%s`" , cast (long )uwidth, dsym.toChars(), dsym.type.toChars());
32253234 dsym.errors = true ;
32263235 }
32273236 dsym.fieldWidth = cast (uint )uwidth;
@@ -7046,10 +7055,20 @@ bool determineFields(AggregateDeclaration ad)
70467055 {
70477056 if (ad == tvs.sym)
70487057 {
7058+ if (ad.type.ty == Terror || ad.errors)
7059+ return 1 ; // failed already
7060+
70497061 const (char )* psz = (v.type.toBasetype().ty == Tsarray) ? " static array of " : " " ;
7050- .error(ad.loc, " %s `%s` cannot have field `%s` with %ssame struct type" , ad.kind, ad.toPrettyChars, v.toChars(), psz);
7051- ad.type = Type.terror;
7052- ad.errors = true ;
7062+ if (! v.isAnonymous())
7063+ .error(v.loc, " %s `%s` cannot have field `%s` with %ssame struct type" , ad.kind, ad.toPrettyChars, v.toChars(), psz);
7064+ else
7065+ .error(v.loc, " %s `%s` cannot have anonymous field with %ssame struct type" , ad.kind, ad.toPrettyChars, psz);
7066+ // Don't cache errors from speculative semantic
7067+ if (! global.gag)
7068+ {
7069+ ad.type = Type.terror;
7070+ ad.errors = true ;
7071+ }
70537072 return 1 ;
70547073 }
70557074 }
@@ -8439,10 +8458,9 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
84398458 uint memalignsize = target.fieldalign(t); // size of member for alignment purposes
84408459 if (log) printf(" memsize: %u memalignsize: %u\n " , memsize, memalignsize);
84418460
8442- if (bfd.fieldWidth == 0 && ! anon)
8443- error(bfd.loc, " named bit fields cannot have 0 width" );
8444- if (bfd.fieldWidth > memsize * 8 )
8445- error(bfd.loc, " bit field width %d is larger than type" , bfd.fieldWidth);
8461+ // Handled in dsymbolSemantic as errors
8462+ assert (bfd.fieldWidth != 0 || anon, " named bit fields cannot have 0 width" );
8463+ assert (bfd.fieldWidth <= memsize * 8 , " bit field width is larger than type" );
84468464
84478465 const style = target.c.bitFieldStyle;
84488466 if (style != TargetC.BitFieldStyle.MS && style != TargetC.BitFieldStyle.Gcc_Clang)
0 commit comments