[cfe-dev] __is_empty type trait patch
Eli Friedman
eli.friedman at gmail.com
Sun Aug 2 22:26:02 PDT 2009
On Sun, Aug 2, 2009 at 7:45 PM, Sean Hunt<rideau3 at gmail.com> wrote:
> Hello,
>
> I'm a new coder hoping to help out with the C++ implementation on clang.
> After fiddling around with several things I discovered were all being
> worked on already, someone recommended I implement the __is_empty type
> trait, so that is what I did. I was told to send a message here now;
> I've attached a patch.
Cool.
> A few notes about this:
>
> I put tests in test/SemaCXX/type-traits.cpp. There are a bunch of tests
> I added to __is_pod and __is_empty, mainly for testing purposes. I was
> going to remove them, but then I figured there's no sense removing tests
> - more is better.
Yeah, having a bunch of tests is good. It's generally not a good idea
to put in commented-out tests, though; if it gives an error, use an
expected-error marking, and put a comment that the error isn't
correct. (If it crashes, of course, it's better to leave it commented
out.)
> I also encountered, while doing checks for zero-width bit-fields, an
> error "bit-field i has zero width". I added the word "named" to the
> diagnostic so that it's clear what the error really is. This change is
> unrelated but is minor so I included it anyways.
I committed this separately.
bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
- QualType FieldTy, const Expr *BitWidth) {
-
+ QualType FieldTy, const Expr *BitWidth,
bool *ZeroWidth) {
+ // Default to true; that shouldn't confuse checks for emptiness
+ if (ZeroWidth)
+ *ZeroWidth = true;
This looks suspicious; is it really supposed to default to true? (At
first glance, it looks like it will misclassify a struct with only
bitfields.)
Otherwise, looks fine.
-Eli
More information about the cfe-dev
mailing list