Skip to content

Commit

Permalink
linux: build with -Wextra
Browse files Browse the repository at this point in the history
95% of this is removing "const" from return types, but turning this
on found one bug!  (A "for" loop that expected its iterator to go negative but
which was using an unsigned type.)

BUG=34160

Review URL: http://codereview.chromium.org/570012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38266 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
evan@chromium.org committed Feb 5, 2010
1 parent f3f0c05 commit 225c8f5
Show file tree
Hide file tree
Showing 44 changed files with 125 additions and 89 deletions.
8 changes: 7 additions & 1 deletion base/base.gypi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -607,6 +607,9 @@
'cflags': [
'-Wno-sign-compare',
],
'cflags!': [
'-Wextra',
],
'sources': [
'third_party/symbolize/symbolize.cc',
'third_party/symbolize/demangle.cc',
Expand All @@ -615,6 +618,9 @@
{
'target_name': 'xdg_mime',
'type': '<(library)',
'cflags!': [
'-Wextra',
],
'sources': [
'third_party/xdg_mime/xdgmime.c',
'third_party/xdg_mime/xdgmime.h',
Expand Down
4 changes: 2 additions & 2 deletions base/stack_container.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -72,7 +72,7 @@ class StackAllocator : public std::allocator<T> {

// For the straight up copy c-tor, we can share storage.
StackAllocator(const StackAllocator<T, stack_capacity>& rhs)
: source_(rhs.source_) {
: std::allocator<T>(), source_(rhs.source_) {
}

// ISO C++ requires the following constructor to be defined,
Expand Down
20 changes: 19 additions & 1 deletion base/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,24 @@ struct IntToStringT {
}
};

// This set of templates is very similar to the above templates, but
// for testing whether an integer is negative.
template <typename INT2, bool NEG2>
struct TestNegT { };
template <typename INT2>
struct TestNegT<INT2, false> {
static bool TestNeg(INT2 value) {
// value is unsigned, and can never be negative.
return false;
}
};
template <typename INT2>
struct TestNegT<INT2, true> {
static bool TestNeg(INT2 value) {
return value < 0;
}
};

static STR IntToString(INT value) {
// log10(2) ~= 0.3 bytes needed per bit or per byte log10(2**8) ~= 2.4.
// So round up to allocate 3 output characters per byte, plus 1 for '-'.
Expand All @@ -1191,7 +1209,7 @@ struct IntToStringT {
// then return the substr of what we ended up using.
STR outbuf(kOutputBufSize, 0);

bool is_neg = value < 0;
bool is_neg = TestNegT<INT, NEG>::TestNeg(value);
// Even though is_neg will never be true when INT is parameterized as
// unsigned, even the presence of the unary operation causes a warning.
UINT res = ToUnsignedT<INT, UINT, NEG>::ToUnsigned(value);
Expand Down
8 changes: 7 additions & 1 deletion build/common.gypi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -602,6 +602,12 @@
'-pthread',
'-fno-exceptions',
'-Wall',
# TODO(evan): turn this back on once the v8 change lands.
#'-Wextra',
# Don't warn about unused function params. We use those everywhere.
'-Wno-unused-parameter',
# Don't warn about the "struct foo f = {0};" initialization pattern.
'-Wno-missing-field-initializers',
'-D_FILE_OFFSET_BITS=64',
# Don't export any symbols (for example, to plugins we dlopen()).
# Note: this is *required* to make some plugins work.
Expand Down
3 changes: 2 additions & 1 deletion build/external_code.gypi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand All @@ -8,6 +8,7 @@
'target_defaults': {
'cflags!': [
'-Wall',
'-Wextra',
'-Werror',
],
},
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/autocomplete/autocomplete.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -233,19 +233,19 @@ class AutocompleteInput {
const GURL& canonicalized_url() const { return canonicalized_url_; }

// Returns whether inline autocompletion should be prevented.
const bool prevent_inline_autocomplete() const {
bool prevent_inline_autocomplete() const {
return prevent_inline_autocomplete_;
}

// Returns whether, given an input string consisting solely of a substituting
// keyword, we should score it like a non-substituting keyword.
const bool prefer_keyword() const { return prefer_keyword_; }
bool prefer_keyword() const { return prefer_keyword_; }

// Returns whether providers should avoid scheduling asynchronous work. If
// this is true, providers should stop after returning all the
// synchronously-available matches. This also means any in-progress
// asynchronous work should be canceled, so no later callbacks are fired.
const bool synchronous_only() const { return synchronous_only_; }
bool synchronous_only() const { return synchronous_only_; }

// operator==() by another name.
bool Equals(const AutocompleteInput& other) const;
Expand Down Expand Up @@ -778,7 +778,7 @@ class AutocompleteController : public ACProviderListener {
// This next is temporary and should go away when
// AutocompletePopup::URLsForCurrentSelection() moves to the controller.
const AutocompleteResult& latest_result() const { return latest_result_; }
const bool done() const { return done_ && !update_delay_timer_.IsRunning(); }
bool done() const { return done_ && !update_delay_timer_.IsRunning(); }

// From AutocompleteProvider::Listener
virtual void OnProviderUpdate(bool updated_matches);
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/autofill/address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ void Address::set_line2(const string16& line2) {
}

Address::Address(const Address& address)
: line1_tokens_(address.line1_tokens_),
: FormGroup(),
line1_tokens_(address.line1_tokens_),
line2_tokens_(address.line2_tokens_),
line1_(address.line1_),
line2_(address.line2_),
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/autofill/address_field.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -161,7 +161,8 @@ AddressField::AddressField()
}

AddressField::AddressField(const AddressField& field)
: address1_(field.address1_),
: FormField(),
address1_(field.address1_),
address2_(field.address2_),
city_(field.city_),
state_(field.state_),
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/autofill/autofill_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ AutoFillProfile::AutoFillProfile()
use_billing_address_(true) {
}

AutoFillProfile::AutoFillProfile(const AutoFillProfile& source) {
AutoFillProfile::AutoFillProfile(const AutoFillProfile& source)
: FormGroup() {
operator=(source);
}

Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/autofill/contact_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ string16 ContactInfo::MiddleInitial() const {
}

ContactInfo::ContactInfo(const ContactInfo& contact_info)
: first_tokens_(contact_info.first_tokens_),
: FormGroup(),
first_tokens_(contact_info.first_tokens_),
middle_tokens_(contact_info.middle_tokens_),
last_tokens_(contact_info.last_tokens_),
first_(contact_info.first_),
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/autofill/credit_card.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CreditCard::CreditCard(const string16& label, int unique_id)
unique_id_(unique_id) {
}

CreditCard::CreditCard(const CreditCard& card) {
CreditCard::CreditCard(const CreditCard& card) : FormGroup() {
operator=(card);
}

Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/autofill/credit_card_field.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -153,7 +153,8 @@ CreditCardField::CreditCardField()
}

CreditCardField::CreditCardField(const CreditCardField& field)
: cardholder_(field.cardholder_),
: FormField(),
cardholder_(field.cardholder_),
cardholder_last_(field.cardholder_last_),
type_(field.type_),
number_(field.number_),
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/autofill/name_field.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -152,7 +152,8 @@ FirstLastNameField::FirstLastNameField()
}

FirstLastNameField::FirstLastNameField(const FirstLastNameField& field)
: first_name_(field.first_name_),
: NameField(),
first_name_(field.first_name_),
middle_name_(field.middle_name_),
last_name_(field.last_name_),
middle_initial_(field.middle_initial_) {
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/autofill/phone_number.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ void PhoneNumber::set_number(const string16& number) {
}

PhoneNumber::PhoneNumber(const PhoneNumber& phone_number)
: country_code_(phone_number.country_code_),
: FormGroup(),
country_code_(phone_number.country_code_),
city_code_(phone_number.city_code_),
number_(phone_number.number_),
extension_(phone_number.extension_) {
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/browser_theme_pack.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -171,7 +171,7 @@ PersistingImagesTable kPersistingImages[] = {
{ 59, IDR_LOCATIONBG, NULL }
};

const int GetPersistentIDByName(const std::string& key) {
int GetPersistentIDByName(const std::string& key) {
for (size_t i = 0; i < arraysize(kPersistingImages); ++i) {
if (kPersistingImages[i].key != NULL &&
base::strcasecmp(key.c_str(), kPersistingImages[i].key) == 0) {
Expand All @@ -182,7 +182,7 @@ const int GetPersistentIDByName(const std::string& key) {
return -1;
}

const int GetPersistentIDByIDR(int idr) {
int GetPersistentIDByIDR(int idr) {
for (size_t i = 0; i < arraysize(kPersistingImages); ++i) {
if (kPersistingImages[i].idr_id == idr) {
return kPersistingImages[i].persistent_id;
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/character_encoding.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -112,12 +112,11 @@ class CanonicalEncodingMap {
const IdToCanonicalEncodingNameMapType* GetIdToCanonicalEncodingNameMapData();
const CanonicalEncodingNameToIdMapType* GetCanonicalEncodingNameToIdMapData();
const CanonicalNameDisplayNameMapType* GetCanonicalNameDisplayNameMapData();
std::vector<int>* const locale_dependent_encoding_ids() {
std::vector<int>* locale_dependent_encoding_ids() {
return &locale_dependent_encoding_ids_;
}

std::vector<CharacterEncoding::EncodingInfo>* const
current_display_encodings() {
std::vector<CharacterEncoding::EncodingInfo>* current_display_encodings() {
return &current_display_encodings_;
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/debugger/devtools_remote_message.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -48,7 +48,7 @@ class DevToolsRemoteMessage {
return content_;
}

const int content_length() const {
int content_length() const {
return content_.size();
}

Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/dom_ui/dom_ui.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -89,11 +89,11 @@ class DOMUI {

// Returns the transition type that should be used for link clicks on this
// DOM UI. This will default to LINK but may be overridden.
const PageTransition::Type link_transition_type() const {
PageTransition::Type link_transition_type() const {
return link_transition_type_;
}

const int bindings() const {
int bindings() const {
return bindings_;
}

Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/dom_ui/most_visited_handler.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -264,8 +264,8 @@ void MostVisitedHandler::RemovePinnedURL(const GURL& url) {
// Don't call HandleGetMostVisited. Let the client call this as needed.
}

const bool MostVisitedHandler::GetPinnedURLAtIndex(const int index,
MostVisitedPage* page) {
bool MostVisitedHandler::GetPinnedURLAtIndex(int index,
MostVisitedPage* page) {
// This iterates over all the pinned URLs. It might seem like it is worth
// having a map from the index to the item but the number of items is limited
// to the number of items the most visited section is showing on the NTP so
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/dom_ui/most_visited_handler.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -86,7 +86,7 @@ class MostVisitedHandler : public DOMMessageHandler,

// Gets the page data for a pinned URL at a given index. This returns
// true if found.
const bool GetPinnedURLAtIndex(const int index, MostVisitedPage* page);
bool GetPinnedURLAtIndex(int index, MostVisitedPage* page);

void AddPinnedURL(const MostVisitedPage& page, int index);
void RemovePinnedURL(const GURL& url);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/dom_ui/new_tab_ui.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -47,7 +47,7 @@ class NewTabUI : public DOMUI,
const GURL& gurl);

// The current preference version.
static const int current_pref_version() { return current_pref_version_; }
static int current_pref_version() { return current_pref_version_; }

class NewTabHTMLSource : public ChromeURLDataManager::DataSource {
public:
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/notifications/balloon_collection.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -121,9 +121,8 @@ BalloonCollectionImpl::Layout::Layout() {
RefreshSystemMetrics();
}

const void BalloonCollectionImpl::Layout::GetMaxLinearSize(
int* max_balloon_size,
int* total_size) const {
void BalloonCollectionImpl::Layout::GetMaxLinearSize(int* max_balloon_size,
int* total_size) const {
DCHECK(max_balloon_size && total_size);

switch (placement_) {
Expand Down
Loading

0 comments on commit 225c8f5

Please sign in to comment.