Commit 9ad67cdb authored by James Ge's avatar James Ge

Support clang 4.0 (except UT)

Change-Id: I603bdaca231398e1c45141f36538823354d490cf
parent 42c2712b
......@@ -171,17 +171,21 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
// gcc supports atomic thread fence since 4.8 checkout
// https://gcc.gnu.org/gcc-4.7/cxx0x_status.html and
// https://gcc.gnu.org/gcc-4.8/cxx0x_status.html for more details
#if !defined(__GNUC__) || (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 >= 40800)
#include <atomic>
#if defined(__clang__) || \
!defined(__GNUC__) || \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 >= 40800)
# include <atomic>
#else
#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 >= 40500
# if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 >= 40500
// gcc 4.5 renames cstdatomic to atomic
// (https://gcc.gnu.org/gcc-4.5/changes.html)
#include <atomic>
#else
#include <cstdatomic>
#endif
# include <atomic>
# else
# include <cstdatomic>
# endif
namespace std {
......
......@@ -94,7 +94,7 @@ namespace base {
template <typename _Map, typename _Element> class FlatMapIterator;
template <typename _Map, typename _Element> class SparseFlatMapIterator;
template <typename K, typename T> struct FlatMapElement;
template <typename K, typename T> class FlatMapElement;
struct FlatMapVoid {}; // Replace void which is not constructible.
template <typename K> struct DefaultHasher;
template <typename K> struct DefaultEqualTo;
......@@ -246,6 +246,7 @@ public:
};
private:
friend class FlatMapTest;
template <typename _Map, typename _Element> friend class FlatMapIterator;
template <typename _Map, typename _Element> friend class FlatMapSparseIterator;
// True if buckets need to be resized before holding `size' elements.
......
......@@ -38,7 +38,7 @@ struct StringMapThreadLocalTemp {
if (temp->initialized) {
temp->initialized = false;
std::string* temp_string = (std::string*)temp->buf;
temp_string->std::string::~string();
temp_string->~basic_string();
}
}
......
......@@ -64,7 +64,7 @@ void byteReverse(unsigned char *buf, unsigned longs) {
* the data and converts bytes into longwords for this routine.
*/
void MD5Transform(uint32_t buf[4], const uint32_t in[16]) {
register uint32_t a, b, c, d;
uint32_t a, b, c, d;
a = buf[0];
b = buf[1];
......
......@@ -68,8 +68,11 @@ class BASE_EXPORT RefCountedBase {
private:
mutable int ref_count_;
#if defined(__clang__)
mutable bool ALLOW_UNUSED in_dtor_;
#else
mutable bool in_dtor_;
#endif
DFAKE_MUTEX(add_release_);
DISALLOW_COPY_AND_ASSIGN(RefCountedBase);
......@@ -90,7 +93,11 @@ class BASE_EXPORT RefCountedThreadSafeBase {
private:
mutable AtomicRefCount ref_count_;
#if defined(__clang__)
mutable bool ALLOW_UNUSED in_dtor_;
#else
mutable bool in_dtor_;
#endif
DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafeBase);
};
......
......@@ -12,7 +12,8 @@
namespace base {
template <typename T> struct GetLeakySingleton {
template <typename T> class GetLeakySingleton {
public:
static base::subtle::AtomicWord g_leaky_singleton_untyped;
static pthread_once_t g_create_leaky_singleton_once;
static void create_leaky_singleton();
......
......@@ -27,10 +27,10 @@
namespace dmg_fp {
char *
g_fmt(register char *b, double x)
g_fmt(char *b, double x)
{
register int i, k;
register char *s;
int i, k;
char *s;
int decpt, j, sign;
char *b0, *s0, *se;
......
......@@ -438,8 +438,12 @@ RAPIDJSON_NAMESPACE_END
#ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
#if defined(__clang__)
#define RAPIDJSON_HAS_CXX11_RVALUE_REFS __has_feature(cxx_rvalue_references) && \
# if __has_feature(cxx_rvalue_references) && \
(defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
# define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
# else
# define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
# endif
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
(defined(_MSC_VER) && _MSC_VER >= 1600)
......
......@@ -12,18 +12,12 @@
namespace brpc {
class Server;
class DirService : public dir {
public:
explicit DirService(Server* server) : _server(server) {}
void default_method(::google::protobuf::RpcController* cntl_base,
const ::brpc::DirRequest* request,
::brpc::DirResponse* response,
::google::protobuf::Closure* done);
private:
Server* _server;
};
} // namespace brpc
......
......@@ -254,7 +254,7 @@ static int MakeProfName(ProfilingType type, char* buf, size_t buf_len) {
static void ConsumeWaiters(ProfilingType type, const Controller* cur_cntl,
std::vector<ProfilingWaiter>* waiters) {
waiters->clear();
if (type >= (int)arraysize(g_env)) {
if ((int)type >= (int)arraysize(g_env)) {
LOG(ERROR) << "Invalid type=" << type;
return;
}
......
......@@ -191,7 +191,7 @@ const char* sorttable_js() {
" for (var i=0; i<table.tBodies[0].rows.length; i++) {\n"
" text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]);\n"
" if (text != '') {\n"
" if (text.match(/^-?[$]?[\\d,.]+%?$/)) {\n"
" if (text.match(/^-?[$]?[\\d,.]+%?$/)) {\n"
" return sorttable.sort_numeric;\n"
" }\n"
" // check for a date: dd/mm/yyyy or dd/mm/yy\n"
......
......@@ -64,9 +64,7 @@ typedef unsigned __int64 uint64_t;
namespace brpc {
typedef struct http_parser http_parser;
typedef struct http_parser_settings http_parser_settings;
struct http_parser;
/* Callbacks should return non-zero to indicate an error. The parser will
* then halt execution.
......@@ -201,8 +199,7 @@ enum http_errno {
#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
class http_parser {
public:
struct http_parser {
/** PRIVATE **/
unsigned int type : 2; /* enum http_parser_type */
unsigned int flags : 6; /* F_* values from 'flags' enum; semi-public */
......
......@@ -60,11 +60,11 @@ struct LessThanByName {
static void BuildHttpMethodMaps() {
for (size_t i = 0; i < ARRAY_SIZE(g_method_pairs); ++i) {
if (g_method_pairs[i].method < 0 ||
g_method_pairs[i].method > (int)ARRAY_SIZE(g_method2str_map)) {
int method = (int)g_method_pairs[i].method;
if (method < 0 || method > (int)ARRAY_SIZE(g_method2str_map)) {
abort();
}
g_method2str_map[g_method_pairs[i].method] = g_method_pairs[i].str;
g_method2str_map[method] = g_method_pairs[i].str;
}
std::sort(g_method_pairs, g_method_pairs + ARRAY_SIZE(g_method_pairs),
LessThanByName());
......@@ -82,13 +82,13 @@ static void BuildHttpMethodMaps() {
}
}
const char *HttpMethod2Str(HttpMethod http_method) {
const char *HttpMethod2Str(HttpMethod method) {
pthread_once(&g_init_maps_once, BuildHttpMethodMaps);
if (http_method < 0 ||
http_method >= (int)ARRAY_SIZE(g_method2str_map)) {
if ((int)method < 0 ||
(int)method >= (int)ARRAY_SIZE(g_method2str_map)) {
return "UNKNOWN";
}
const char* s = g_method2str_map[http_method];
const char* s = g_method2str_map[method];
return s ? s : "UNKNOWN";
}
......
......@@ -395,7 +395,11 @@ private:
int _fail_limit;
int _ndone;
int _nchan;
#if defined(__clang__)
int ALLOW_UNUSED _memsize;
#else
int _memsize;
#endif
base::atomic<int> _current_fail;
base::atomic<uint32_t> _current_done;
Controller* _cntl;
......
......@@ -31,7 +31,7 @@ inline const char* ParseErrorToString(ParseError e) {
return "unknown ParseError";
}
struct InputMessageBase;
class InputMessageBase;
// A specialized Maybe<> type to represent a parsing result.
class ParseResult {
......
......@@ -5,7 +5,7 @@
// Date: 2015/06/11 17:46:26
#ifndef BRPC_HASHER_H
#define BAIDU_PPC_HASHER_H
#define BRPC_HASHER_H
#include <stddef.h>
#include <stdint.h>
......
......@@ -45,7 +45,8 @@ void NsheadClosure::DoNotRespond() {
_do_respond = false;
}
struct DeleteNsheadClosure {
class DeleteNsheadClosure {
public:
void operator()(NsheadClosure* done) const {
done->~NsheadClosure();
free(done);
......
......@@ -85,7 +85,6 @@ const char* messagetype2str(uint8_t t) {
// Unchangable constants required by RTMP
static const uint32_t RTMP_INITIAL_CHUNK_SIZE = 128;
static const uint8_t RTMP_DEFAULT_VERSION = 3;
static const uint8_t RTMP_MAX_VERSION = 31;
static const size_t RTMP_HANDSHAKE_SIZE0 = 1;
static const size_t RTMP_HANDSHAKE_SIZE1 = 1536;
static const size_t RTMP_HANDSHAKE_SIZE2 = RTMP_HANDSHAKE_SIZE1;
......
......@@ -229,7 +229,7 @@ class RtmpChunkStream;
// Associated with a RTMP connection.
class RtmpContext : public Destroyable {
friend class RtmpChunkStream;
friend struct RtmpUnsentMessage;
friend class RtmpUnsentMessage;
public:
// States during handshake.
enum State {
......
......@@ -147,8 +147,6 @@ Server::MethodProperty::MethodProperty()
, status(NULL) {
}
static const char* const UNKNOWN_STR = "unknown";
static timeval GetUptime(void* arg/*start_time*/) {
return base::microseconds_to_timeval(base::cpuwide_time_us() - (intptr_t)arg);
}
......@@ -494,7 +492,7 @@ int Server::AddBuiltinServices() {
return -1;
}
if (FLAGS_enable_dir_service &&
AddBuiltinService(new (std::nothrow) DirService(this))) {
AddBuiltinService(new (std::nothrow) DirService)) {
LOG(ERROR) << "Fail to add DirService";
return -1;
}
......
......@@ -509,7 +509,7 @@ friend void DereferenceSocket(Socket*);
// Generic callback for Socket to handle epollout event
static int HandleEpollOut(SocketId socket_id);
struct EpollOutRequest;
class EpollOutRequest;
// Callback to handle epollout event whose request data
// is `EpollOutRequest'
int HandleEpollOutRequest(int error_code, EpollOutRequest* req);
......
......@@ -90,19 +90,19 @@ static const int TS_PMT_NUMBER = 1;
// Program Association Table(see Table 2-25)
static const TsPid TS_PID_PAT = (TsPid)0x00;
// Conditional Access Table (see Table 2-27)
static const TsPid TS_PID_CAT = (TsPid)0x01;
//static const TsPid TS_PID_CAT = (TsPid)0x01;
// Transport Stream Description Table
static const TsPid TS_PID_TSDT = (TsPid)0x02;
static const TsPid TS_PID_RESERVED_START = (TsPid)0x03;
static const TsPid TS_PID_RESERVED_END = (TsPid)0x0f;
//static const TsPid TS_PID_TSDT = (TsPid)0x02;
//static const TsPid TS_PID_RESERVED_START = (TsPid)0x03;
// static const TsPid TS_PID_RESERVED_END = (TsPid)0x0f;
// May be assigned as network_PID; Program_map_PID; elementary_PID; or for
// other purposes
static const TsPid TS_PID_APP_START = (TsPid)0x10;
//static const TsPid TS_PID_APP_START = (TsPid)0x10;
static const TsPid TS_PID_VIDEO_AVC = (TsPid)0x100;
static const TsPid TS_PID_AUDIO_AAC = (TsPid)0x101;
static const TsPid TS_PID_AUDIO_MP3 = (TsPid)0x102;
static const TsPid TS_PID_PMT = (TsPid)0x1001;
static const TsPid TS_PID_APP_END = (TsPid)0x1ffe;
//static const TsPid TS_PID_APP_END = (TsPid)0x1ffe;
static const TsPid TS_PID_NULL = (TsPid)0x01FFF;// null packets (see Table 2-3)
// The sync_byte is a fixed 8-bit field whose value is '0100 0111' (0x47).
......@@ -1185,7 +1185,7 @@ static const uint8_t cont_nalu_header[] = { 0x00, 0x00, 0x01 };
// 8, SP (SP slice)
// 9, SI (SI slice)
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 105.
static const uint8_t aud_nalu_7[] = { 0x09, 0xf0};
//static const uint8_t aud_nalu_7[] = { 0x09, 0xf0};
static const uint8_t fresh_nalu_header_and_aud_nalu_7[] =
{ 0x00, 0x00, 0x00, 0x01, 0x09, 0xf0};
......
......@@ -19,7 +19,7 @@ namespace bthread {
template <typename T> struct ExecutionQueueId;
template <typename T> class ExecutionQueue;
struct TaskNode;
struct ExecutionQueueBase;
class ExecutionQueueBase;
class TaskIteratorBase {
DISALLOW_COPY_AND_ASSIGN(TaskIteratorBase);
......
......@@ -20,7 +20,7 @@ struct TaskStatistics {
int64_t nswitch;
};
struct KeyTable;
class KeyTable;
struct ButexWaiter;
struct LocalStorage {
......
......@@ -527,10 +527,6 @@ public:
RUsageReader::get_field<BVAR_MEMBER_TYPE(&rusage::field), \
offsetof(rusage, field)>, NULL); \
inline std::ostream& operator<<(std::ostream& os, const timeval& tm) {
return os << tm.tv_sec << '.' << std::setw(6) << std::setfill('0') << tm.tv_usec;
}
// ======================================
BVAR_DEFINE_PROC_STAT_FIELD2(pid, "pid");
......@@ -746,3 +742,9 @@ PassiveStatus<std::string> g_work_dir("process_work_dir", get_work_dir, NULL);
#undef BVAR_DEFINE_RUSAGE_FIELD2
} // namespace bvar
// In the same scope where timeval is defined. Required by clang.
inline std::ostream& operator<<(std::ostream& os, const timeval& tm) {
return os << tm.tv_sec << '.' << std::setw(6) << std::setfill('0') << tm.tv_usec;
}
......@@ -23,7 +23,7 @@ inline uint32_t ones32(uint32_t x) {
}
inline uint32_t log2(uint32_t x) {
register int y = (x & (x - 1));
int y = (x & (x - 1));
y |= -y;
y >>= 31;
x |= (x >> 1);
......
......@@ -51,8 +51,6 @@ DEFINE_bool(bvar_log_dumpped, false,
const size_t SUB_MAP_COUNT = 32; // must be power of 2
BAIDU_CASSERT(!(SUB_MAP_COUNT & (SUB_MAP_COUNT - 1)), must_be_power_of_2);
const size_t MAX_CONFLICT_NAME = 128;
class VarEntry {
public:
VarEntry() : var(NULL), display_filter(DISPLAY_ON_ALL) {}
......
......@@ -674,7 +674,7 @@ TEST_F(BuiltinServiceTest, pprof) {
}
TEST_F(BuiltinServiceTest, dir) {
brpc::DirService service(&_server);
brpc::DirService service;
brpc::DirRequest req;
brpc::DirResponse res;
{
......
......@@ -16,16 +16,6 @@ namespace base {
namespace {
//------------------------------------------------------------------------------
// Define our test class.
//------------------------------------------------------------------------------
void CancelHelper(CancellationFlag* flag) {
#if GTEST_HAS_DEATH_TEST
ASSERT_DEBUG_DEATH(flag->Set(), "");
#endif
}
TEST(CancellationFlagTest, SimpleSingleThreadedTest) {
CancellationFlag flag;
ASSERT_FALSE(flag.IsSet());
......
......@@ -191,7 +191,7 @@ TEST_F(ConditionVariableTest, TimeoutTest) {
#if defined(OS_POSIX)
const int kDiscontinuitySeconds = 2;
void BackInTime(Lock* lock) {
void ALLOW_UNUSED BackInTime(Lock* lock) {
AutoLock auto_lock(*lock);
timeval tv;
......
......@@ -25,7 +25,7 @@ namespace {
// Returns true if PathService::Get returns true and sets the path parameter
// to non-empty for the given PathService::DirType enumeration value.
bool ReturnsValidPath(int dir_type) {
bool ALLOW_UNUSED ReturnsValidPath(int dir_type) {
base::FilePath path;
bool result = PathService::Get(dir_type, &path);
......
......@@ -119,7 +119,7 @@ struct test_t {
TEST_F(TempFileTest, save_binary_twice)
{
test_t data = {12, -34, 'B', 'E', 'E', 'F'};
test_t data = {12, -34, {'B', 'E', 'E', 'F'}};
base::TempFile tmp;
ASSERT_EQ(0, tmp.save_bin(&data, sizeof(data)));
......@@ -133,7 +133,7 @@ TEST_F(TempFileTest, save_binary_twice)
ASSERT_EQ(0, memcmp(&data, &act_data, sizeof(data)));
// save twice
test_t data2 = { 89, 1000, 'E', 'C', 'A', 'Z'};
test_t data2 = { 89, 1000, {'E', 'C', 'A', 'Z'}};
ASSERT_EQ(0, tmp.save_bin(&data2, sizeof(data2)));
fp = fopen(tmp.fname(), "r");
......
......@@ -18,7 +18,7 @@ struct BStruct {
int x;
};
class BClass {
int _x;
int ALLOW_UNUSED _x;
};
class Parent {};
......
#include <stdio.h>
int main() {
#if defined(__GNUC__)
#if defined(__clang__)
const int major_v = __GNUC__;
int minor_v = __GNUC_MINOR__;
if (major_v == 4 && minor_v <= 8) {
// Make version of clang >= 4.8 so that it's not rejected by config_brpc.sh
minor_v = 8;
}
printf("%d\n", (major_v * 10000 + minor_v * 100));
#elif defined(__GNUC__)
printf("%d\n", (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__));
#else
printf("0\n");
......
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