Commit 9d3f5c8f by Ben Clayton

clang: Enable -Weverything, fix all warnings

This change fixes the following warnings: ``` -Wc++98-compat-extra-semi -Wc++98-compat-local-type-template-args -Wc++98-compat-pedantic -Wc++98-compat -Wcomma -Wdeprecated-copy-dtor -Wexit-time-destructors -Wextra-semi-stmt -Wextra-semi -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral -Wglobal-constructors -Winconsistent-missing-destructor-override -Wnon-virtual-dtor -Wold-style-cast -Wpadded -Wreturn-std-move-in-c++11 -Wshadow-field-in-constructor -Wshadow-uncaptured-local -Wshift-sign-overflow -Wsign-conversion -Wundef -Wunreachable-code-return -Wused-but-marked-unused -Wweak-vtables -Wzero-as-null-pointer-constant ```
parent bb3dbcd2
...@@ -78,6 +78,7 @@ set(CPPDAP_LIST ...@@ -78,6 +78,7 @@ set(CPPDAP_LIST
${CPPDAP_SRC_DIR}/protocol_types.cpp ${CPPDAP_SRC_DIR}/protocol_types.cpp
${CPPDAP_SRC_DIR}/session.cpp ${CPPDAP_SRC_DIR}/session.cpp
${CPPDAP_SRC_DIR}/socket.cpp ${CPPDAP_SRC_DIR}/socket.cpp
${CPPDAP_SRC_DIR}/typeinfo.cpp
${CPPDAP_SRC_DIR}/typeof.cpp ${CPPDAP_SRC_DIR}/typeof.cpp
) )
......
...@@ -89,7 +89,7 @@ class future { ...@@ -89,7 +89,7 @@ class future {
}; };
template <typename T> template <typename T>
future<T>::future(const std::shared_ptr<State>& state) : state(state) {} future<T>::future(const std::shared_ptr<State>& s) : state(s) {}
template <typename T> template <typename T>
bool future<T>::valid() const { bool future<T>::valid() const {
......
...@@ -38,6 +38,8 @@ struct Field { ...@@ -38,6 +38,8 @@ struct Field {
// Methods that return a bool use this to indicate success. // Methods that return a bool use this to indicate success.
class Deserializer { class Deserializer {
public: public:
virtual ~Deserializer() = default;
// deserialization methods for simple data types. // deserialization methods for simple data types.
// If the stored object is not of the correct type, then these function will // If the stored object is not of the correct type, then these function will
// return false. // return false.
...@@ -104,7 +106,7 @@ bool Deserializer::deserialize(dap::optional<T>* opt) const { ...@@ -104,7 +106,7 @@ bool Deserializer::deserialize(dap::optional<T>* opt) const {
T v; T v;
if (deserialize(&v)) { if (deserialize(&v)) {
*opt = v; *opt = v;
}; }
return true; return true;
} }
...@@ -132,6 +134,8 @@ class FieldSerializer; ...@@ -132,6 +134,8 @@ class FieldSerializer;
// Methods that return a bool use this to indicate success. // Methods that return a bool use this to indicate success.
class Serializer { class Serializer {
public: public:
virtual ~Serializer() = default;
// serialization methods for simple data types. // serialization methods for simple data types.
virtual bool serialize(boolean) = 0; virtual bool serialize(boolean) = 0;
virtual bool serialize(integer) = 0; virtual bool serialize(integer) = 0;
...@@ -215,6 +219,8 @@ class FieldSerializer { ...@@ -215,6 +219,8 @@ class FieldSerializer {
template <typename T> template <typename T>
using IsSerializeFunc = std::is_convertible<T, SerializeFunc>; using IsSerializeFunc = std::is_convertible<T, SerializeFunc>;
virtual ~FieldSerializer() = default;
// field() encodes a field to the struct object referenced by this Serializer. // field() encodes a field to the struct object referenced by this Serializer.
// The SerializeFunc will be called with a Serializer used to encode the // The SerializeFunc will be called with a Serializer used to encode the
// field's data. // field's data.
......
...@@ -98,14 +98,13 @@ struct ResponseOrError { ...@@ -98,14 +98,13 @@ struct ResponseOrError {
}; };
template <typename T> template <typename T>
ResponseOrError<T>::ResponseOrError(const T& response) : response(response) {} ResponseOrError<T>::ResponseOrError(const T& resp) : response(resp) {}
template <typename T> template <typename T>
ResponseOrError<T>::ResponseOrError(T&& response) ResponseOrError<T>::ResponseOrError(T&& resp) : response(std::move(resp)) {}
: response(std::move(response)) {}
template <typename T> template <typename T>
ResponseOrError<T>::ResponseOrError(const Error& error) : error(error) {} ResponseOrError<T>::ResponseOrError(const Error& err) : error(err) {}
template <typename T> template <typename T>
ResponseOrError<T>::ResponseOrError(Error&& error) : error(std::move(error)) {} ResponseOrError<T>::ResponseOrError(Error&& err) : error(std::move(err)) {}
template <typename T> template <typename T>
ResponseOrError<T>::ResponseOrError(const ResponseOrError& other) ResponseOrError<T>::ResponseOrError(const ResponseOrError& other)
: response(other.response), error(other.error) {} : response(other.response), error(other.error) {}
...@@ -148,7 +147,7 @@ class Session { ...@@ -148,7 +147,7 @@ class Session {
using ArgTy = typename detail::ArgTy<F>::type; using ArgTy = typename detail::ArgTy<F>::type;
public: public:
virtual ~Session() = default; virtual ~Session();
// ErrorHandler is the type of callback function used for reporting protocol // ErrorHandler is the type of callback function used for reporting protocol
// errors. // errors.
......
...@@ -28,6 +28,7 @@ class Serializer; ...@@ -28,6 +28,7 @@ class Serializer;
// types. TypeInfo is used by the serialization system to encode and decode DAP // types. TypeInfo is used by the serialization system to encode and decode DAP
// requests, responses, events and structs. // requests, responses, events and structs.
struct TypeInfo { struct TypeInfo {
virtual ~TypeInfo();
virtual std::string name() const = 0; virtual std::string name() const = 0;
virtual size_t size() const = 0; virtual size_t size() const = 0;
virtual size_t alignment() const = 0; virtual size_t alignment() const = 0;
......
...@@ -26,7 +26,7 @@ namespace dap { ...@@ -26,7 +26,7 @@ namespace dap {
// template type T. // template type T.
template <typename T> template <typename T>
struct BasicTypeInfo : public TypeInfo { struct BasicTypeInfo : public TypeInfo {
BasicTypeInfo(const std::string& name) : name_(name) {} constexpr BasicTypeInfo(std::string&& name) : name_(std::move(name)) {}
// TypeInfo compliance // TypeInfo compliance
inline std::string name() const { return name_; } inline std::string name() const { return name_; }
...@@ -88,6 +88,15 @@ struct TypeOf<null> { ...@@ -88,6 +88,15 @@ struct TypeOf<null> {
static const TypeInfo* type(); static const TypeInfo* type();
}; };
// TypeOf for template types requires dynamic generation of type information,
// triggering the clang -Wexit-time-destructors warning.
// TODO(bclayton): See if there's a way to avoid this, without requiring manual
// instantiation of each type.
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif // __clang__
template <typename T> template <typename T>
struct TypeOf<array<T>> { struct TypeOf<array<T>> {
static inline const TypeInfo* type() { static inline const TypeInfo* type() {
...@@ -114,6 +123,10 @@ struct TypeOf<optional<T>> { ...@@ -114,6 +123,10 @@ struct TypeOf<optional<T>> {
} }
}; };
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
// DAP_OFFSETOF() macro is a generalization of the offsetof() macro defined in // DAP_OFFSETOF() macro is a generalization of the offsetof() macro defined in
// <cstddef>. It evaluates to the offset of the given field, with fewer // <cstddef>. It evaluates to the offset of the given field, with fewer
// restrictions than offsetof(). We cast the address '32' and subtract it again, // restrictions than offsetof(). We cast the address '32' and subtract it again,
......
...@@ -72,7 +72,7 @@ variant<T0, Types...>::variant() : value(T0()) {} ...@@ -72,7 +72,7 @@ variant<T0, Types...>::variant() : value(T0()) {}
template <typename T0, typename... Types> template <typename T0, typename... Types>
template <typename T> template <typename T>
variant<T0, Types...>::variant(const T& value) : value(value) { variant<T0, Types...>::variant(const T& v) : value(v) {
static_assert(accepts<T>(), "variant does not accept template type T"); static_assert(accepts<T>(), "variant does not accept template type T");
} }
......
...@@ -21,53 +21,37 @@ ...@@ -21,53 +21,37 @@
namespace dap { namespace dap {
BreakpointEvent::BreakpointEvent() = default;
BreakpointEvent::~BreakpointEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(BreakpointEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(BreakpointEvent,
"breakpoint", "breakpoint",
DAP_FIELD(breakpoint, "breakpoint"), DAP_FIELD(breakpoint, "breakpoint"),
DAP_FIELD(reason, "reason")); DAP_FIELD(reason, "reason"));
CapabilitiesEvent::CapabilitiesEvent() = default;
CapabilitiesEvent::~CapabilitiesEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(CapabilitiesEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(CapabilitiesEvent,
"capabilities", "capabilities",
DAP_FIELD(capabilities, "capabilities")); DAP_FIELD(capabilities, "capabilities"));
ContinuedEvent::ContinuedEvent() = default;
ContinuedEvent::~ContinuedEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(ContinuedEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(ContinuedEvent,
"continued", "continued",
DAP_FIELD(allThreadsContinued, DAP_FIELD(allThreadsContinued,
"allThreadsContinued"), "allThreadsContinued"),
DAP_FIELD(threadId, "threadId")); DAP_FIELD(threadId, "threadId"));
ExitedEvent::ExitedEvent() = default;
ExitedEvent::~ExitedEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(ExitedEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(ExitedEvent,
"exited", "exited",
DAP_FIELD(exitCode, "exitCode")); DAP_FIELD(exitCode, "exitCode"));
InitializedEvent::InitializedEvent() = default;
InitializedEvent::~InitializedEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(InitializedEvent, "initialized"); DAP_IMPLEMENT_STRUCT_TYPEINFO(InitializedEvent, "initialized");
LoadedSourceEvent::LoadedSourceEvent() = default;
LoadedSourceEvent::~LoadedSourceEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(LoadedSourceEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(LoadedSourceEvent,
"loadedSource", "loadedSource",
DAP_FIELD(reason, "reason"), DAP_FIELD(reason, "reason"),
DAP_FIELD(source, "source")); DAP_FIELD(source, "source"));
ModuleEvent::ModuleEvent() = default;
ModuleEvent::~ModuleEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(ModuleEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(ModuleEvent,
"module", "module",
DAP_FIELD(module, "module"), DAP_FIELD(module, "module"),
DAP_FIELD(reason, "reason")); DAP_FIELD(reason, "reason"));
OutputEvent::OutputEvent() = default;
OutputEvent::~OutputEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(OutputEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(OutputEvent,
"output", "output",
DAP_FIELD(category, "category"), DAP_FIELD(category, "category"),
...@@ -80,8 +64,6 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(OutputEvent, ...@@ -80,8 +64,6 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(OutputEvent,
DAP_FIELD(variablesReference, DAP_FIELD(variablesReference,
"variablesReference")); "variablesReference"));
ProcessEvent::ProcessEvent() = default;
ProcessEvent::~ProcessEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(ProcessEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(ProcessEvent,
"process", "process",
DAP_FIELD(isLocalProcess, "isLocalProcess"), DAP_FIELD(isLocalProcess, "isLocalProcess"),
...@@ -90,15 +72,11 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(ProcessEvent, ...@@ -90,15 +72,11 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(ProcessEvent,
DAP_FIELD(startMethod, "startMethod"), DAP_FIELD(startMethod, "startMethod"),
DAP_FIELD(systemProcessId, "systemProcessId")); DAP_FIELD(systemProcessId, "systemProcessId"));
ProgressEndEvent::ProgressEndEvent() = default;
ProgressEndEvent::~ProgressEndEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(ProgressEndEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(ProgressEndEvent,
"progressEnd", "progressEnd",
DAP_FIELD(message, "message"), DAP_FIELD(message, "message"),
DAP_FIELD(progressId, "progressId")); DAP_FIELD(progressId, "progressId"));
ProgressStartEvent::ProgressStartEvent() = default;
ProgressStartEvent::~ProgressStartEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(ProgressStartEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(ProgressStartEvent,
"progressStart", "progressStart",
DAP_FIELD(cancellable, "cancellable"), DAP_FIELD(cancellable, "cancellable"),
...@@ -108,16 +86,12 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(ProgressStartEvent, ...@@ -108,16 +86,12 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(ProgressStartEvent,
DAP_FIELD(requestId, "requestId"), DAP_FIELD(requestId, "requestId"),
DAP_FIELD(title, "title")); DAP_FIELD(title, "title"));
ProgressUpdateEvent::ProgressUpdateEvent() = default;
ProgressUpdateEvent::~ProgressUpdateEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(ProgressUpdateEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(ProgressUpdateEvent,
"progressUpdate", "progressUpdate",
DAP_FIELD(message, "message"), DAP_FIELD(message, "message"),
DAP_FIELD(percentage, "percentage"), DAP_FIELD(percentage, "percentage"),
DAP_FIELD(progressId, "progressId")); DAP_FIELD(progressId, "progressId"));
StoppedEvent::StoppedEvent() = default;
StoppedEvent::~StoppedEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(StoppedEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(StoppedEvent,
"stopped", "stopped",
DAP_FIELD(allThreadsStopped, "allThreadsStopped"), DAP_FIELD(allThreadsStopped, "allThreadsStopped"),
...@@ -127,14 +101,10 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(StoppedEvent, ...@@ -127,14 +101,10 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(StoppedEvent,
DAP_FIELD(text, "text"), DAP_FIELD(text, "text"),
DAP_FIELD(threadId, "threadId")); DAP_FIELD(threadId, "threadId"));
TerminatedEvent::TerminatedEvent() = default;
TerminatedEvent::~TerminatedEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(TerminatedEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(TerminatedEvent,
"terminated", "terminated",
DAP_FIELD(restart, "restart")); DAP_FIELD(restart, "restart"));
ThreadEvent::ThreadEvent() = default;
ThreadEvent::~ThreadEvent() = default;
DAP_IMPLEMENT_STRUCT_TYPEINFO(ThreadEvent, DAP_IMPLEMENT_STRUCT_TYPEINFO(ThreadEvent,
"thread", "thread",
DAP_FIELD(reason, "reason"), DAP_FIELD(reason, "reason"),
......
...@@ -481,6 +481,8 @@ Error::Error(const char* msg, ...) { ...@@ -481,6 +481,8 @@ Error::Error(const char* msg, ...) {
message = buf; message = buf;
} }
Session::~Session() = default;
std::unique_ptr<Session> Session::create() { std::unique_ptr<Session> Session::create() {
return std::unique_ptr<Session>(new Impl()); return std::unique_ptr<Session>(new Impl());
} }
......
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dap/typeinfo.h"
namespace dap {
TypeInfo::~TypeInfo() = default;
} // namespace dap
...@@ -313,16 +313,6 @@ func (s *cppStruct) writeHeader(w io.Writer) { ...@@ -313,16 +313,6 @@ func (s *cppStruct) writeHeader(w io.Writer) {
io.WriteString(w, ";") io.WriteString(w, ";")
} }
// constructor
io.WriteString(w, "\n\n ")
io.WriteString(w, s.name)
io.WriteString(w, "();")
// destructor
io.WriteString(w, "\n ~")
io.WriteString(w, s.name)
io.WriteString(w, "();\n")
for _, f := range s.fields { for _, f := range s.fields {
if f.desc != "" { if f.desc != "" {
io.WriteString(w, "\n // ") io.WriteString(w, "\n // ")
...@@ -353,18 +343,6 @@ func (s *cppStruct) writeHeader(w io.Writer) { ...@@ -353,18 +343,6 @@ func (s *cppStruct) writeHeader(w io.Writer) {
} }
func (s *cppStruct) writeCPP(w io.Writer) { func (s *cppStruct) writeCPP(w io.Writer) {
// constructor
io.WriteString(w, s.name)
io.WriteString(w, "::")
io.WriteString(w, s.name)
io.WriteString(w, "() = default;\n")
// destructor
io.WriteString(w, s.name)
io.WriteString(w, "::~")
io.WriteString(w, s.name)
io.WriteString(w, "() = default;\n")
// typeinfo // typeinfo
io.WriteString(w, "DAP_IMPLEMENT_STRUCT_TYPEINFO(") io.WriteString(w, "DAP_IMPLEMENT_STRUCT_TYPEINFO(")
io.WriteString(w, s.name) io.WriteString(w, s.name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment