Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: make C++ linter reject template< #20675

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ class QueryWrap : public AsyncWrap {
};


template<typename T>
template <typename T>
Local<Array> AddrTTLToArray(Environment* env,
const T* addrttls,
size_t naddrttls) {
Expand Down
4 changes: 2 additions & 2 deletions src/inspector_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using AsyncAndAgent = std::pair<uv_async_t, Agent*>;
using v8_inspector::StringBuffer;
using v8_inspector::StringView;

template<typename Transport>
template <typename Transport>
using TransportAndIo = std::pair<Transport*, InspectorIo*>;

std::string ScriptPath(uv_loop_t* loop, const std::string& script_name) {
Expand Down Expand Up @@ -284,7 +284,7 @@ void InspectorIo::IoThreadAsyncCb(uv_async_t* async) {
}
}

template<typename Transport>
template <typename Transport>
void InspectorIo::ThreadMain() {
uv_loop_t loop;
loop.data = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void* GetAsyncTask(int64_t asyncId) {
return reinterpret_cast<void*>(asyncId << 1);
}

template<void (Agent::*asyncTaskFn)(void*)>
template <void (Agent::*asyncTaskFn)(void*)>
static void InvokeAsyncTaskFnWithId(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsNumber());
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class ServerSocket {
private:
explicit ServerSocket(InspectorSocketServer* server)
: tcp_socket_(uv_tcp_t()), server_(server), port_(-1) {}
template<typename UvHandle>
template <typename UvHandle>
static ServerSocket* FromTcpSocket(UvHandle* socket) {
return node::ContainerOf(&ServerSocket::tcp_socket_,
reinterpret_cast<uv_tcp_t*>(socket));
Expand Down
2 changes: 1 addition & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ enum ResolveExtensionsOptions {
ONLY_VIA_EXTENSIONS
};

template<ResolveExtensionsOptions options>
template <ResolveExtensionsOptions options>
Maybe<URL> ResolveExtensions(const URL& search) {
if (options == TRY_EXACT_NAME) {
std::string filePath = search.ToFilePath();
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ class ExternalHeader :
vec.len);
}

template<bool may_internalize>
template <bool may_internalize>
static MaybeLocal<String> New(Environment* env, nghttp2_rcbuf* buf) {
if (nghttp2_rcbuf_is_static(buf)) {
auto& static_str_map = env->isolate_data()->http2_static_strs;
Expand Down
2 changes: 1 addition & 1 deletion src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ void URLHost::ParseHost(const char* input,

// Locates the longest sequence of 0 segments in an IPv6 address
// in order to use the :: compression when serializing
template<typename T>
template <typename T>
inline T* FindLongestZeroSequence(T* values, size_t len) {
T* start = values;
T* end = start + len;
Expand Down
6 changes: 3 additions & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ struct OnScopeLeave {
};

// Simple RAII wrapper for contiguous data that uses malloc()/free().
template<typename T>
template <typename T>
struct MallocedBuffer {
T* data;
size_t size;
Expand Down Expand Up @@ -448,10 +448,10 @@ struct MallocedBuffer {
};

// Test whether some value can be called with ().
template<typename T, typename = void>
template <typename T, typename = void>
struct is_callable : std::is_function<T> { };

template<typename T>
template <typename T>
struct is_callable<T, typename std::enable_if<
std::is_same<decltype(void(&T::operator())), void>::value
>::type> : std::true_type { };
Expand Down
12 changes: 6 additions & 6 deletions test/cctest/test_aliased_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ using node::AliasedBuffer;

class AliasBufferTest : public NodeTestFixture {};

template<class NativeT>
template <class NativeT>
void CreateOracleValues(std::vector<NativeT>* buf) {
for (size_t i = 0, j = buf->size(); i < buf->size(); i++, j--) {
(*buf)[i] = static_cast<NativeT>(j);
}
}

template<class NativeT, class V8T>
template <class NativeT, class V8T>
void WriteViaOperator(AliasedBuffer<NativeT, V8T>* aliasedBuffer,
const std::vector<NativeT>& oracle) {
// write through the API
Expand All @@ -23,7 +23,7 @@ void WriteViaOperator(AliasedBuffer<NativeT, V8T>* aliasedBuffer,
}
}

template<class NativeT, class V8T>
template <class NativeT, class V8T>
void WriteViaSetValue(AliasedBuffer<NativeT, V8T>* aliasedBuffer,
const std::vector<NativeT>& oracle) {
// write through the API
Expand All @@ -32,7 +32,7 @@ void WriteViaSetValue(AliasedBuffer<NativeT, V8T>* aliasedBuffer,
}
}

template<class NativeT, class V8T>
template <class NativeT, class V8T>
void ReadAndValidate(v8::Isolate* isolate,
v8::Local<v8::Context> context,
AliasedBuffer<NativeT, V8T>* aliasedBuffer,
Expand Down Expand Up @@ -68,7 +68,7 @@ void ReadAndValidate(v8::Isolate* isolate,
}
}

template<class NativeT, class V8T>
template <class NativeT, class V8T>
void ReadWriteTest(v8::Isolate* isolate) {
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
Expand All @@ -92,7 +92,7 @@ void ReadWriteTest(v8::Isolate* isolate) {
ReadAndValidate(isolate, context, &ab, oracle);
}

template<
template <
class NativeT_A, class V8T_A,
class NativeT_B, class V8T_B,
class NativeT_C, class V8T_C>
Expand Down
4 changes: 4 additions & 0 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4230,6 +4230,10 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
error(filename, linenum, 'whitespace/tab', 1,
'Tab found; better to use spaces')

if line.find('template<') != -1:
error(filename, linenum, 'whitespace/template', 1,
'Leave a single space after template, as in `template <...>`')

# One or three blank spaces at the beginning of the line is weird; it's
# hard to reconcile that with 2-space indents.
# NOTE: here are the conditions rob pike used for his tests. Mine aren't
Expand Down