[cfe-commits] [PATCH] [libcxx] cleanup a few more compile warnings emitted by GCC
Saleem Abdulrasool
compnerd at compnerd.org
Thu Dec 27 15:03:11 PST 2012
- missing field initializers
Use GCC specific pragmas to mirror the clang pragmas to ignore missing field
initializers as this is the most concinse, portable manner to
zero-initialize the aggregates.
- explicit instantiation of base class
Use GCC specific pragma to ignore the -Wextra warning during the constructor
as the base class constructor will be invoked implicitly if it is missing in
the initializer list in the most derived class for virtual inheritance, or
by the appropriate class in the non-virtual inheritance case.
Furthermore, make the sysconf error checking 32-bit clean by checking the return
value as per the man page. The error code returned by the sysconf call is -1
for any type of error, with errno providing details of the error code.
http://llvm-reviews.chandlerc.com/D247
Files:
src/locale.cpp
src/thread.cpp
Index: src/locale.cpp
===================================================================
--- src/locale.cpp
+++ src/locale.cpp
@@ -224,6 +224,10 @@
#endif // _LIBCPP_NO_EXCEPTIONS
}
+// NOTE(saleem) avoid the `base class should be explicitly initialized in the
+// copy constructor` warning emitted by GCC
+#pragma GCC diagnostic ignored "-Wextra"
+
locale::__imp::__imp(const __imp& other)
: facets_(max<size_t>(N, other.facets_.size())),
name_(other.name_)
@@ -234,6 +238,8 @@
facets_[i]->__add_shared();
}
+#pragma GCC diagnostic pop
+
locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
: facets_(N),
name_("*")
@@ -4601,7 +4607,9 @@
string
__time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
{
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
tm t = {0};
+#pragma GCC diagnostic pop
t.tm_sec = 59;
t.tm_min = 55;
t.tm_hour = 23;
@@ -4747,7 +4755,9 @@
wstring
__time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
{
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
tm t = {0};
+#pragma GCC diagnositc pop
t.tm_sec = 59;
t.tm_min = 55;
t.tm_hour = 23;
@@ -4901,7 +4911,9 @@
void
__time_get_storage<char>::init(const ctype<char>& ct)
{
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
tm t = {0};
+#pragma GCC diagnostic pop
char buf[100];
// __weeks_
for (int i = 0; i < 7; ++i)
@@ -4938,11 +4950,15 @@
void
__time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
{
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
tm t = {0};
+#pragma GCC diagnostic pop
char buf[100];
wchar_t wbuf[100];
wchar_t* wbe;
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
mbstate_t mb = {0};
+#pragma GCC diagnostic pop
// __weeks_
for (int i = 0; i < 7; ++i)
{
@@ -5296,7 +5312,9 @@
char __nar[100];
char* __ne = __nar + 100;
__do_put(__nar, __ne, __tm, __fmt, __mod);
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
mbstate_t mb = {0};
+#pragma GCC diagnostic pop
const char* __nb = __nar;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
size_t j = mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
@@ -5821,7 +5839,9 @@
__thousands_sep_ = base::do_thousands_sep();
__grouping_ = lc->mon_grouping;
wchar_t wbuf[100];
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
mbstate_t mb = {0};
+#pragma GCC diagnostic pop
const char* bb = lc->currency_symbol;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
@@ -5904,7 +5924,9 @@
__thousands_sep_ = base::do_thousands_sep();
__grouping_ = lc->mon_grouping;
wchar_t wbuf[100];
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
mbstate_t mb = {0};
+#pragma GCC diagnostic pop
const char* bb = lc->int_curr_symbol;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
Index: src/thread.cpp
===================================================================
--- src/thread.cpp
+++ src/thread.cpp
@@ -67,8 +67,10 @@
return n;
#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && defined(_SC_NPROCESSORS_ONLN)
long result = sysconf(_SC_NPROCESSORS_ONLN);
- if (result < 0 || result > UINT_MAX)
- result = 0;
+ // sysconf returns -1 if the name is invalid, the option does not exist or
+ // does not have a definite limit.
+ if (result == -1)
+ return 0;
return result;
#else // defined(CTL_HW) && defined(HW_NCPU)
// TODO: grovel through /proc or check cpuid on x86 and similar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D247.1.patch
Type: text/x-patch
Size: 3807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121227/e69d10c0/attachment.bin>
More information about the cfe-commits
mailing list