Turns on -Wshadow (by Preston Jackson).

This commit is contained in:
zhanyong.wan 2009-12-16 19:54:05 +00:00
parent 3508784108
commit d56773b492
13 changed files with 90 additions and 85 deletions

View File

@ -56,15 +56,15 @@ class TestPartResult {
// C'tor. TestPartResult does NOT have a default constructor.
// Always use this constructor (with parameters) to create a
// TestPartResult object.
TestPartResult(Type type,
const char* file_name,
int line_number,
const char* message)
: type_(type),
file_name_(file_name),
line_number_(line_number),
summary_(ExtractSummary(message)),
message_(message) {
TestPartResult(Type a_type,
const char* a_file_name,
int a_line_number,
const char* a_message)
: type_(a_type),
file_name_(a_file_name),
line_number_(a_line_number),
summary_(ExtractSummary(a_message)),
message_(a_message) {
}
// Gets the outcome of the test part.

View File

@ -457,8 +457,8 @@ class TestProperty {
// C'tor. TestProperty does NOT have a default constructor.
// Always use this constructor (with parameters) to create a
// TestProperty object.
TestProperty(const char* key, const char* value) :
key_(key), value_(value) {
TestProperty(const char* a_key, const char* a_value) :
key_(a_key), value_(a_value) {
}
// Gets the user supplied key.

View File

@ -189,11 +189,12 @@ bool ExitedUnsuccessfully(int exit_status);
// RUN_ALL_TESTS was called.
class InternalRunDeathTestFlag {
public:
InternalRunDeathTestFlag(const String& file,
int line,
int index,
int write_fd)
: file_(file), line_(line), index_(index), write_fd_(write_fd) {}
InternalRunDeathTestFlag(const String& a_file,
int a_line,
int an_index,
int a_write_fd)
: file_(a_file), line_(a_line), index_(an_index),
write_fd_(a_write_fd) {}
~InternalRunDeathTestFlag() {
if (write_fd_ >= 0)

View File

@ -544,12 +544,12 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
// LocalTestInfo structure keeps information about a single test registered
// with TEST_P macro.
struct TestInfo {
TestInfo(const char* test_case_base_name,
const char* test_base_name,
TestMetaFactoryBase<ParamType>* test_meta_factory) :
test_case_base_name(test_case_base_name),
test_base_name(test_base_name),
test_meta_factory(test_meta_factory) {}
TestInfo(const char* a_test_case_base_name,
const char* a_test_base_name,
TestMetaFactoryBase<ParamType>* a_test_meta_factory) :
test_case_base_name(a_test_case_base_name),
test_base_name(a_test_base_name),
test_meta_factory(a_test_meta_factory) {}
const String test_case_base_name;
const String test_base_name;

View File

@ -190,12 +190,12 @@ class String {
String() : c_str_(NULL), length_(0) {}
// Constructs a String by cloning a 0-terminated C string.
String(const char* c_str) { // NOLINT
if (c_str == NULL) {
String(const char* a_c_str) { // NOLINT
if (a_c_str == NULL) {
c_str_ = NULL;
length_ = 0;
} else {
ConstructNonNull(c_str, strlen(c_str));
ConstructNonNull(a_c_str, strlen(a_c_str));
}
}
@ -203,8 +203,8 @@ class String {
// buffer. E.g. String("hello", 3) creates the string "hel",
// String("a\0bcd", 4) creates "a\0bc", String(NULL, 0) creates "",
// and String(NULL, 1) results in access violation.
String(const char* buffer, size_t length) {
ConstructNonNull(buffer, length);
String(const char* buffer, size_t a_length) {
ConstructNonNull(buffer, a_length);
}
// The copy c'tor creates a new copy of the string. The two
@ -247,7 +247,7 @@ class String {
// Returns true iff this String equals the given C string. A NULL
// string and a non-NULL string are considered not equal.
bool operator==(const char* c_str) const { return Compare(c_str) == 0; }
bool operator==(const char* a_c_str) const { return Compare(a_c_str) == 0; }
// Returns true iff this String is less than the given String. A
// NULL string is considered less than "".
@ -255,7 +255,7 @@ class String {
// Returns true iff this String doesn't equal the given C string. A NULL
// string and a non-NULL string are considered not equal.
bool operator!=(const char* c_str) const { return !(*this == c_str); }
bool operator!=(const char* a_c_str) const { return !(*this == a_c_str); }
// Returns true iff this String ends with the given suffix. *Any*
// String is considered to end with a NULL or empty suffix.
@ -275,7 +275,9 @@ class String {
const char* c_str() const { return c_str_; }
// Assigns a C string to this object. Self-assignment works.
const String& operator=(const char* c_str) { return *this = String(c_str); }
const String& operator=(const char* a_c_str) {
return *this = String(a_c_str);
}
// Assigns a String object to this object. Self-assignment works.
const String& operator=(const String& rhs) {
@ -297,12 +299,12 @@ class String {
// function can only be called when data_ has not been allocated.
// ConstructNonNull(NULL, 0) results in an empty string ("").
// ConstructNonNull(NULL, non_zero) is undefined behavior.
void ConstructNonNull(const char* buffer, size_t length) {
char* const str = new char[length + 1];
memcpy(str, buffer, length);
str[length] = '\0';
void ConstructNonNull(const char* buffer, size_t a_length) {
char* const str = new char[a_length + 1];
memcpy(str, buffer, a_length);
str[a_length] = '\0';
c_str_ = str;
length_ = length;
length_ = a_length;
}
const char* c_str_;

View File

@ -193,6 +193,7 @@ class SConstructHelper:
env.Append(CCFLAGS=['-fno-exceptions',
'-Wall',
'-Werror',
'-Wshadow',
])
if optimized:
env.Append(CCFLAGS=['-O2'], CPPDEFINES=['NDEBUG', '_NDEBUG'])

View File

@ -308,9 +308,9 @@ String DeathTest::last_death_test_message_;
// Provides cross platform implementation for some death functionality.
class DeathTestImpl : public DeathTest {
protected:
DeathTestImpl(const char* statement, const RE* regex)
: statement_(statement),
regex_(regex),
DeathTestImpl(const char* a_statement, const RE* a_regex)
: statement_(a_statement),
regex_(a_regex),
spawned_(false),
status_(-1),
outcome_(IN_PROGRESS),
@ -326,11 +326,11 @@ class DeathTestImpl : public DeathTest {
const char* statement() const { return statement_; }
const RE* regex() const { return regex_; }
bool spawned() const { return spawned_; }
void set_spawned(bool spawned) { spawned_ = spawned; }
void set_spawned(bool is_spawned) { spawned_ = is_spawned; }
int status() const { return status_; }
void set_status(int status) { status_ = status; }
void set_status(int a_status) { status_ = a_status; }
DeathTestOutcome outcome() const { return outcome_; }
void set_outcome(DeathTestOutcome outcome) { outcome_ = outcome; }
void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; }
int read_fd() const { return read_fd_; }
void set_read_fd(int fd) { read_fd_ = fd; }
int write_fd() const { return write_fd_; }
@ -705,8 +705,8 @@ class ForkingDeathTest : public DeathTestImpl {
};
// Constructs a ForkingDeathTest.
ForkingDeathTest::ForkingDeathTest(const char* statement, const RE* regex)
: DeathTestImpl(statement, regex),
ForkingDeathTest::ForkingDeathTest(const char* a_statement, const RE* a_regex)
: DeathTestImpl(a_statement, a_regex),
child_pid_(-1) {}
// Waits for the child in a death test to exit, returning its exit
@ -718,18 +718,18 @@ int ForkingDeathTest::Wait() {
ReadAndInterpretStatusByte();
int status;
GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status, 0));
set_status(status);
return status;
int status_value;
GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_value, 0));
set_status(status_value);
return status_value;
}
// A concrete death test class that forks, then immediately runs the test
// in the child process.
class NoExecDeathTest : public ForkingDeathTest {
public:
NoExecDeathTest(const char* statement, const RE* regex) :
ForkingDeathTest(statement, regex) { }
NoExecDeathTest(const char* a_statement, const RE* a_regex) :
ForkingDeathTest(a_statement, a_regex) { }
virtual TestRole AssumeRole();
};
@ -782,9 +782,9 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
// only this specific death test to be run.
class ExecDeathTest : public ForkingDeathTest {
public:
ExecDeathTest(const char* statement, const RE* regex,
ExecDeathTest(const char* a_statement, const RE* a_regex,
const char* file, int line) :
ForkingDeathTest(statement, regex), file_(file), line_(line) { }
ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
virtual TestRole AssumeRole();
private:
// The name of the file in which the death test is located.

View File

@ -902,15 +902,15 @@ class UnitTestImpl {
#endif // GTEST_HAS_PARAM_TEST
// Sets the TestCase object for the test that's currently running.
void set_current_test_case(TestCase* current_test_case) {
current_test_case_ = current_test_case;
void set_current_test_case(TestCase* a_current_test_case) {
current_test_case_ = a_current_test_case;
}
// Sets the TestInfo object for the test that's currently running. If
// current_test_info is NULL, the assertion results will be stored in
// ad_hoc_test_result_.
void set_current_test_info(TestInfo* current_test_info) {
current_test_info_ = current_test_info;
void set_current_test_info(TestInfo* a_current_test_info) {
current_test_info_ = a_current_test_info;
}
// Registers all parameterized tests defined using TEST_P and

View File

@ -2123,14 +2123,14 @@ bool Test::HasNonfatalFailure() {
// Constructs a TestInfo object. It assumes ownership of the test factory
// object via impl_.
TestInfo::TestInfo(const char* test_case_name,
const char* name,
const char* test_case_comment,
const char* comment,
TestInfo::TestInfo(const char* a_test_case_name,
const char* a_name,
const char* a_test_case_comment,
const char* a_comment,
internal::TypeId fixture_class_id,
internal::TestFactoryBase* factory) {
impl_ = new internal::TestInfoImpl(this, test_case_name, name,
test_case_comment, comment,
impl_ = new internal::TestInfoImpl(this, a_test_case_name, a_name,
a_test_case_comment, a_comment,
fixture_class_id, factory);
}
@ -2368,11 +2368,11 @@ int TestCase::total_test_count() const {
// name: name of the test case
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
TestCase::TestCase(const char* name, const char* comment,
TestCase::TestCase(const char* a_name, const char* a_comment,
Test::SetUpTestCaseFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc)
: name_(name),
comment_(comment),
: name_(a_name),
comment_(a_comment),
test_info_list_(new internal::Vector<TestInfo*>),
test_indices_(new internal::Vector<int>),
set_up_tc_(set_up_tc),
@ -4022,8 +4022,9 @@ int UnitTestImpl::RunAllTests() {
// Runs the tests only if there was no fatal failure during global
// set-up.
if (!Test::HasFatalFailure()) {
for (int i = 0; i < total_test_case_count(); i++) {
GetMutableTestCase(i)->Run();
for (int test_index = 0; test_index < total_test_case_count();
test_index++) {
GetMutableTestCase(test_index)->Run();
}
}
@ -4297,18 +4298,18 @@ void UnitTestImpl::UnshuffleTests() {
// TestInfoImpl constructor. The new instance assumes ownership of the test
// factory object.
TestInfoImpl::TestInfoImpl(TestInfo* parent,
const char* test_case_name,
const char* name,
const char* test_case_comment,
const char* comment,
TypeId fixture_class_id,
const char* a_test_case_name,
const char* a_name,
const char* a_test_case_comment,
const char* a_comment,
TypeId a_fixture_class_id,
internal::TestFactoryBase* factory) :
parent_(parent),
test_case_name_(String(test_case_name)),
name_(String(name)),
test_case_comment_(String(test_case_comment)),
comment_(String(comment)),
fixture_class_id_(fixture_class_id),
test_case_name_(String(a_test_case_name)),
name_(String(a_name)),
test_case_comment_(String(a_test_case_comment)),
comment_(String(a_comment)),
fixture_class_id_(a_fixture_class_id),
should_run_(false),
is_disabled_(false),
matches_filter_(false),

View File

@ -205,7 +205,7 @@ TEST(RangeTest, IntRangeWithCustomStepOverUpperBound) {
// copy constructor, operator=(), operator+(), and operator<().
class DogAdder {
public:
explicit DogAdder(const char* value) : value_(value) {}
explicit DogAdder(const char* a_value) : value_(a_value) {}
DogAdder(const DogAdder& other) : value_(other.value_.c_str()) {}
DogAdder operator=(const DogAdder& other) {
@ -243,7 +243,7 @@ TEST(RangeTest, WorksWithACustomType) {
class IntWrapper {
public:
explicit IntWrapper(int value) : value_(value) {}
explicit IntWrapper(int a_value) : value_(a_value) {}
IntWrapper(const IntWrapper& other) : value_(other.value_) {}
IntWrapper operator=(const IntWrapper& other) {

View File

@ -4009,7 +4009,7 @@ TEST(AssertionTest, NonFixtureSubroutine) {
// An uncopyable class.
class Uncopyable {
public:
explicit Uncopyable(int value) : value_(value) {}
explicit Uncopyable(int a_value) : value_(a_value) {}
int value() const { return value_; }
bool operator==(const Uncopyable& rhs) const {
@ -5095,7 +5095,7 @@ TEST(AssertionResultTest, StreamingWorks) {
// both in the global namespace.
class Base {
public:
explicit Base(int x) : x_(x) {}
explicit Base(int an_x) : x_(an_x) {}
int x() const { return x_; }
private:
int x_;
@ -5122,7 +5122,7 @@ TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
namespace {
class MyTypeInUnnamedNameSpace : public Base {
public:
explicit MyTypeInUnnamedNameSpace(int x): Base(x) {}
explicit MyTypeInUnnamedNameSpace(int an_x): Base(an_x) {}
};
std::ostream& operator<<(std::ostream& os,
const MyTypeInUnnamedNameSpace& val) {
@ -5147,7 +5147,7 @@ TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
namespace namespace1 {
class MyTypeInNameSpace1 : public Base {
public:
explicit MyTypeInNameSpace1(int x): Base(x) {}
explicit MyTypeInNameSpace1(int an_x): Base(an_x) {}
};
std::ostream& operator<<(std::ostream& os,
const MyTypeInNameSpace1& val) {
@ -5172,7 +5172,7 @@ TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
namespace namespace2 {
class MyTypeInNameSpace2 : public ::Base {
public:
explicit MyTypeInNameSpace2(int x): Base(x) {}
explicit MyTypeInNameSpace2(int an_x): Base(an_x) {}
};
} // namespace namespace2
std::ostream& operator<<(std::ostream& os,

View File

@ -48,7 +48,7 @@ class PrivateCode {
int x() const { return x_; }
private:
void set_x(int x) { x_ = x; }
void set_x(int an_x) { x_ = an_x; }
int x_;
};

View File

@ -17,7 +17,7 @@ ZERO_LINK = NO
PREBINDING = NO
// Strictest warning policy
WARNING_CFLAGS = -Wall -Werror -Wendif-labels -Wnewline-eof -Wno-sign-compare
WARNING_CFLAGS = -Wall -Werror -Wendif-labels -Wnewline-eof -Wno-sign-compare -Wshadow
// Work around Xcode bugs by using external strip. See:
// http://lists.apple.com/archives/Xcode-users/2006/Feb/msg00050.html