[cfe-commits] r62245 - in /cfe/trunk: lib/Sema/CMakeLists.txt lib/Sema/IdentifierResolver.h lib/Sema/Sema.h lib/Sema/SemaCXXScopeSpec.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaL

Daniel Dunbar daniel at zuster.org
Fri Jan 16 13:51:12 PST 2009


While I agree with Doug that I love to have a compiler warning for the
"switched on all possible enums" case; in practice I have never found
that this can be done in a way that is (a) portable (without causing
spurious warnings for other compilers, which I regard as unacceptable)
and (b) consistent across build types.

>From my personal experience I have just resorted to losing type
checking and using default: fatal() or assert() etc.

I would love to be proven wrong on this topic! And perhaps there is
some potential for a Support/Compiler.h define which would add the
default: assert(0) case for systems that don't support the stronger
check?

Our current convention seems to be the default: one, though, so above
all I prefer internal consistency (or a transition towards).

 - Daniel

On Fri, Jan 16, 2009 at 1:22 PM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Jan 16, 2009, at 1:15 PM, Chris Lattner wrote:
>
>> On Jan 16, 2009, at 12:50 PM, Douglas Gregor wrote:
>>>>> My complaint about putting a default: in there still stands: it
>>>>> suppresses a useful warning, where we've omitted a case, and
>>>>> turns it into a run-time failure.
>>>>
>>>> Does GCC produce a warning for cases like:
>>>>
>>>> int foo() {
>>>> switch (someenum) {
>>>> case <all possible enums>:
>>>>  return 0;
>>>> }
>>>> // no return
>>>> }
>>>>
>>>> About falling off the end of the function?
>>>
>>> Yeah, it does.
>>
>> That's bad.  Can we just use default: assert(0) in those cases?
>
>
> That turns off the warning in the case where you've done:
>
>        switch (someenum) {
>        case <all possible enums except the new one someone else added>:
>                do something;
>        };
>
>        - Doug
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list