Clean up some -Wcovered-switch-default default labels

This commit is contained in:
Fangrui Song 2018-02-13 13:01:55 -08:00
parent a1e1d115bf
commit 0c4d82667f
5 changed files with 36 additions and 7 deletions

View File

@ -163,9 +163,6 @@ StorageClass GetStorageClass(CX_StorageClass storage) {
return StorageClass::Auto;
case CX_SC_Register:
return StorageClass::Register;
default:
assert(0);
return StorageClass::Invalid;
}
}

View File

@ -96,11 +96,9 @@ const char* IpcIdToString(IpcId id) {
return "$cquery/indexFile";
case IpcId::CqueryWait:
return "$cquery/wait";
default:
assert(false && "missing IpcId string name");
exit(1);
}
CQUERY_UNREACHABLE("missing IpcId string name");
}
BaseIpcMessage::BaseIpcMessage(IpcId method_id) : method_id(method_id) {}

View File

@ -126,6 +126,7 @@ struct TextDocumentDefinitionHandler
lsLocation result;
result.uri = lsDocumentUri::FromPath(include.resolved_path);
out.result.push_back(result);
has_symbol = true;
break;
}
}
@ -135,6 +136,9 @@ struct TextDocumentDefinitionHandler
const std::string& buffer = working_file->buffer_content;
std::string query = LexWordAroundPos(position, buffer);
// For symbols whose detailed names contain |query| as a substring,
// we use the tuple <length difference, not in the same file, line
// distance> to find the best match.
std::tuple<int, bool, int> best_score = {INT_MAX, true, 0};
int best_i = -1;
for (int i = 0; i < (int)db->symbols.size(); ++i) {

10
src/port.cc Normal file
View File

@ -0,0 +1,10 @@
#include "port.h"
#include <stdio.h>
#include <stdlib.h>
void cquery_unreachable_internal(const char* msg, const char* file, int line) {
fprintf(stderr, "unreachable %s:%d %s\n", file, line, msg);
CQUERY_BUILTIN_UNREACHABLE;
abort();
}

View File

@ -1,7 +1,27 @@
#pragma once
#ifndef __has_builtin
# define __has_builtin(x) 0
#endif
#if defined(__GNUC__)
#define ATTRIBUTE_UNUSED __attribute__((unused))
#else
#define ATTRIBUTE_UNUSED
#endif
// TODO GCC
#if __has_builtin(__builtin_unreachable)
#define CQUERY_BUILTIN_UNREACHABLE __builtin_unreachable()
#elif defined(_MSC_VER)
#define CQUERY_BUILTIN_UNREACHABLE __assume(false)
#else
#define CQUERY_BUILTIN_UNREACHABLE
#endif
void cquery_unreachable_internal(const char* msg, const char* file, int line);
#ifndef NDEBUG
#define CQUERY_UNREACHABLE(msg) cquery_unreachable_internal(msg, __FILE__, __LINE__)
#else
#define CQUERY_UNREACHABLE(msg)
#endif