Makes all samples compile with -Wall -Wshadow -Werror.

This commit is contained in:
vladlosev 2010-02-27 08:21:11 +00:00
parent 70eceaf8e7
commit fe78760959
7 changed files with 49 additions and 49 deletions

View File

@ -36,12 +36,12 @@ find_package(Threads)
# Defines the compiler/linker flags used to build gtest. You can
# tweak these definitions to suit your need.
if (MSVC)
set(cxx_base "${CMAKE_CXX_FLAGS} -GS -W4 -WX -wd4275 -nologo -J
-Zi -D_UNICODE -DUNICODE -DWIN32 -D_WIN32 -DSTRICT
set(cxx_base "${CMAKE_CXX_FLAGS} -GS -W4 -WX -wd4275 -nologo -J -Zi
-D_UNICODE -DUNICODE -DWIN32 -D_WIN32 -DSTRICT
-DWIN32_LEAN_AND_MEAN")
set(cxx_default "${cxx_base} -EHsc -D_HAS_EXCEPTIONS=1")
else()
set(cxx_base "${CMAKE_CXX_FLAGS}")
set(cxx_base "${CMAKE_CXX_FLAGS} -Wall -Werror -Wshadow")
if (CMAKE_USE_PTHREADS_INIT) # The pthreads library is available.
set(cxx_base "${cxx_base} -DGTEST_HAS_PTHREAD=1")

View File

@ -36,21 +36,21 @@
#include <string.h>
// Clones a 0-terminated C string, allocating memory using new.
const char * MyString::CloneCString(const char * c_string) {
if (c_string == NULL) return NULL;
const char* MyString::CloneCString(const char* a_c_string) {
if (a_c_string == NULL) return NULL;
const size_t len = strlen(c_string);
const size_t len = strlen(a_c_string);
char* const clone = new char[ len + 1 ];
memcpy(clone, c_string, len + 1);
memcpy(clone, a_c_string, len + 1);
return clone;
}
// Sets the 0-terminated C string this MyString object
// represents.
void MyString::Set(const char * c_string) {
void MyString::Set(const char* a_c_string) {
// Makes sure this works when c_string == c_string_
const char * const temp = MyString::CloneCString(c_string);
const char* const temp = MyString::CloneCString(a_c_string);
delete[] c_string_;
c_string_ = temp;
}

View File

@ -46,7 +46,7 @@ class MyString {
public:
// Clones a 0-terminated C string, allocating memory using new.
static const char * CloneCString(const char * c_string);
static const char* CloneCString(const char* a_c_string);
////////////////////////////////////////////////////////////
//
@ -56,8 +56,8 @@ class MyString {
MyString() : c_string_(NULL) {}
// Constructs a MyString by cloning a 0-terminated C string.
explicit MyString(const char * c_string) : c_string_(NULL) {
Set(c_string);
explicit MyString(const char* a_c_string) : c_string_(NULL) {
Set(a_c_string);
}
// Copy c'tor

View File

@ -71,7 +71,7 @@ TEST(MyString, DefaultConstructor) {
// </TechnicalDetails>
EXPECT_STREQ(NULL, s.c_string());
EXPECT_EQ(0, s.Length());
EXPECT_EQ(0u, s.Length());
}
const char kHelloString[] = "Hello, world!";

View File

@ -60,7 +60,7 @@ class QueueNode {
private:
// Creates a node with a given element value. The next pointer is
// set to NULL.
QueueNode(const E & element) : element_(element), next_(NULL) {}
QueueNode(const E& an_element) : element_(an_element), next_(NULL) {}
// We disable the default assignment operator and copy c'tor.
const QueueNode& operator = (const QueueNode&);

View File

@ -122,7 +122,7 @@ class QueueTest : public testing::Test {
// Tests the default c'tor.
TEST_F(QueueTest, DefaultConstructor) {
// You can access data in the test fixture here.
EXPECT_EQ(0, q0_.Size());
EXPECT_EQ(0u, q0_.Size());
}
// Tests Dequeue().
@ -133,13 +133,13 @@ TEST_F(QueueTest, Dequeue) {
n = q1_.Dequeue();
ASSERT_TRUE(n != NULL);
EXPECT_EQ(1, *n);
EXPECT_EQ(0, q1_.Size());
EXPECT_EQ(0u, q1_.Size());
delete n;
n = q2_.Dequeue();
ASSERT_TRUE(n != NULL);
EXPECT_EQ(2, *n);
EXPECT_EQ(1, q2_.Size());
EXPECT_EQ(1u, q2_.Size());
delete n;
}

View File

@ -171,7 +171,7 @@ class QueueTest : public QuickTest {
// Tests the default constructor.
TEST_F(QueueTest, DefaultConstructor) {
EXPECT_EQ(0, q0_.Size());
EXPECT_EQ(0u, q0_.Size());
}
// Tests Dequeue().
@ -182,13 +182,13 @@ TEST_F(QueueTest, Dequeue) {
n = q1_.Dequeue();
EXPECT_TRUE(n != NULL);
EXPECT_EQ(1, *n);
EXPECT_EQ(0, q1_.Size());
EXPECT_EQ(0u, q1_.Size());
delete n;
n = q2_.Dequeue();
EXPECT_TRUE(n != NULL);
EXPECT_EQ(2, *n);
EXPECT_EQ(1, q2_.Size());
EXPECT_EQ(1u, q2_.Size());
delete n;
}