[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/SemaLookup.cpp test/Parser/cxx-using-directive.cpp test/SemaCXX/qualified-id-lookup.cpp
Douglas Gregor
dgregor at apple.com
Fri Jan 16 12:50:23 PST 2009
On Jan 16, 2009, at 12:02 PM, Chris Lattner wrote:
>
> On Jan 15, 2009, at 9:05 AM, Douglas Gregor wrote:
>
>>
>> On Jan 14, 2009, at 11:41 PM, Chris Lattner wrote:
>>
>>> On Jan 14, 2009, at 3:24 PM, Douglas Gregor wrote:
>>>>>> +/// @brief Determine the result of name lookup.
>>>>>> +Sema::LookupResult::LookupKind Sema::LookupResult::getKind()
>>>>>> const {
>>>>>> + switch (StoredKind) {
>>>>>> + case SingleDecl:
>>>>>> + return (reinterpret_cast<Decl *>(First) != 0)? Found :
>>>>>> NotFound;
>>>>>> +
>>>>>> + case OverloadedDeclFromIdResolver:
>>>>>> + case OverloadedDeclFromDeclContext:
>>>>>> + return FoundOverloaded;
>>>>>> +
>>>>>> + case AmbiguousLookup:
>>>>>> + return Ambiguous;
>>>>>> + }
>>>>>> +
>>>>>> + // We can't get here, but GCC complains nonetheless.
>>>>>> + return Ambiguous;
>>>>>> +}
>>>>>>
>>>>>
>>>>> I believe our standard way of handling this is by having a default
>>>>> case
>>>>> that asserts.
>>>>>
>>>>> switch (StoredKind) {
>>>>> default: assert(false && "Bad StoredKind");
>>>>
>>>> IIRC, I was getting bogus "function does not return a value"
>>>> warnings
>>>> from GCC when I've done this.
>>>
>>> Make sure the default case is at the start of the switch (Before
>>> the first case) not at the end.
>>
>>
>> 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.
- Doug
More information about the cfe-commits
mailing list