This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -Wextra and unsigned template parameters

Joe Buck <Joe.Buck@synopsys.COM> writes:

| Aliesha Finkel <> writes:
| > | Hi, I'm using -Wextra (-W) to compile my code, one
| > | feature of which is throwing a warning when an
| > | unsigned type is checked for >= 0 since it's always
| > | true.  In general I find this to be very helpful, but
| > | it throws this error even for templated types...
| > | 
| > | template <typename T>
| > | struct foo {    
| > |   foo(T bar) { if (bar >= 0) bar = 1; }
| > | };
| On Wed, May 10, 2006 at 01:38:29PM +0200, Gabriel Dos Reis wrote:
| > This is an issue as well for gcjx -- it can be annoying.
| I think that the warning is useful if the comparison is *always* true for
| any call of foo<anything>.  But here, whether the test is redundant or not
| depends on the type of bar.


| Possibly there's a way to determine that the
| type of bar is a template argument and suppress the warning in that case.
| But then I just thought of another case:
| template <typename Container>
| struct foo {    
|    foo(const Container& bar) { if (bar.size() >= 0) use(bar); }
| };
| For any STL-compliant container the test is redundant.  But if
| we put in a rule saying to suppress the warning if the type
| depends on a template, we lose the warning in this case as well;
| after all, nothing stops someone from writing

The issue is not simple, as you note.  Still, part of the noise from
bulding gcjx is irritating when one looks at the source code and
realizes "oh, but the compiler should know that warning is not
interesting" :-)  The tricky bit is in defining "interesting".

-- Gaby

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]