Boost C++ Libraries: Ticket #3563: Warnings using g++ 4.4.0 on date_time/posix_time/conversion.hpp https://svn.boost.org/trac10/ticket/3563 <p> On MinGW with version 4.4.0 of "g++ -Wall -Wextra -O2": </p> <p> C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp: In function 'tm boost::posix_time::to_tm(const boost::posix_time::time_duration&amp;)': C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_sec' C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_min' C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_hour' C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_mday' C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_mon' C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_year' C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_wday' C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_yday' C:/Boost/include/boost-1_40/boost/date_time/posix_time/conversion.hpp:45: warning: missing initializer for member 'tm::tm_isdst' </p> <p> Can't we explicitly initialize the tm members that should be zero'ed instead of using "timetm = {}" to get rid of this annoying warning? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3563 Trac 1.4.3 anonymous Sat, 06 Feb 2010 17:44:19 GMT version changed https://svn.boost.org/trac10/ticket/3563#comment:1 https://svn.boost.org/trac10/ticket/3563#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.40.0</span> → <span class="trac-field-new">Boost 1.42.0</span> </li> </ul> <p> This is also happening on my Ubuntu-9.10 distribution with g++-4.3.2. I have boost-1.42 installed. I cannot build any code using this header (even indirectly) with -W and -Werror enabled. </p> <p> This bug reproduces with the minimal source included below. Compile it with -Werror and -W: </p> <pre class="wiki">// threadtest.cpp #include &lt;boost/thread.hpp&gt; int main(int, char **) { return -1; } </pre><p> Build with </p> <pre class="wiki">g++ -c threadtest.cpp -Werror -W -I$HOME/programs/boost-1.42/include Compilation started at Sat Feb 6 17:29:17 g++ -c threadtest.cpp -Werror -W -I$HOME/programs/boost-1.42/include cc1plus: warnings being treated as errors In file included from /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:17\ , from /home/logic/programs/boost-1.42/include/boost/thread/xtime.hpp:15, from /home/logic/programs/boost-1.42/include/boost/thread/pthread/mutex.hpp:13, from /home/logic/programs/boost-1.42/include/boost/thread/mutex.hpp:16, from /home/logic/programs/boost-1.42/include/boost/thread/pthread/thread_data.hpp:12, from /home/logic/programs/boost-1.42/include/boost/thread/thread.hpp:17, from /home/logic/programs/boost-1.42/include/boost/thread.hpp:13, from threadtest.cpp:1: /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp: In function 'tm boost::g\ regorian::to_tm(const boost::gregorian::date&amp;)': /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_sec' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_min' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_hour' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_mday' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_mon' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_year' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_wday' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_yday' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_isdst' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_gmtoff' /home/logic/programs/boost-1.42/include/boost/date_time/gregorian/conversion.hpp:44: error: missing initia\ lizer for member 'tm::tm_zone' In file included from /home/logic/programs/boost-1.42/include/boost/thread/xtime.hpp:15, from /home/logic/programs/boost-1.42/include/boost/thread/pthread/mutex.hpp:13, from /home/logic/programs/boost-1.42/include/boost/thread/mutex.hpp:16, from /home/logic/programs/boost-1.42/include/boost/thread/pthread/thread_data.hpp:12, from /home/logic/programs/boost-1.42/include/boost/thread/thread.hpp:17, from /home/logic/programs/boost-1.42/include/boost/thread.hpp:13, from threadtest.cpp:1: /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp: In function 'tm boost::\ posix_time::to_tm(const boost::posix_time::time_duration&amp;)': /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_sec' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_min' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_hour' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_mday' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_mon' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_year' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_wday' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_yday' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_isdst' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_gmtoff' /home/logic/programs/boost-1.42/include/boost/date_time/posix_time/conversion.hpp:46: error: missing initi\ alizer for member 'tm::tm_zone' Compilation exited abnormally with code 1 at Sat Feb 6 17:29:20 </pre> Ticket Justin Randall <logicle@…> Sat, 06 Feb 2010 20:41:21 GMT <link>https://svn.boost.org/trac10/ticket/3563#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3563#comment:2</guid> <description> <p> Explicit initialization isn't really a portable option, since some platforms don't define tm::tm_gmtoff or tm::tm_zone. std::memset from cstring would do the trick, and it's something used elsewhere in the boost libraries. </p> <p> I have a local change from boost-trunk that fixes g++ warnings. This might not be the best fix, but it has me up and running locally without suppressing g++ warnings for my own code. </p> <pre class="wiki">Index: posix_time/conversion.hpp =================================================================== --- posix_time/conversion.hpp (revision 59528) +++ posix_time/conversion.hpp (working copy) @@ -8,7 +8,7 @@ * Author: Jeff Garland, Bart Garst * $Date$ */ - +#include &lt;cstring&gt; #include &lt;boost/date_time/posix_time/ptime.hpp&gt; #include &lt;boost/date_time/posix_time/posix_time_duration.hpp&gt; #include &lt;boost/date_time/filetime_functions.hpp&gt; @@ -43,7 +43,8 @@ //! Convert a time_duration to a tm structure truncating any fractional seconds and zeroing fields for date components inline std::tm to_tm(const boost::posix_time::time_duration&amp; td) { - std::tm timetm = {}; + std::tm timetm; + std::memset(&amp;timetm, 0, sizeof(timetm)); timetm.tm_hour = date_time::absolute_value(td.hours()); timetm.tm_min = date_time::absolute_value(td.minutes()); timetm.tm_sec = date_time::absolute_value(td.seconds()); Index: gregorian/conversion.hpp =================================================================== --- gregorian/conversion.hpp (revision 59528) +++ gregorian/conversion.hpp (working copy) @@ -9,6 +9,7 @@ * $Date$ */ +#include &lt;cstring&gt; #include &lt;string&gt; #include &lt;stdexcept&gt; #include &lt;boost/throw_exception.hpp&gt; @@ -41,7 +42,8 @@ boost::throw_exception(std::out_of_range(s)); } - std::tm datetm = {}; // zero initialization is needed for extension members, like tm_zone + std::tm datetm; + std::memset(&amp;datetm, 0, sizeof(datetm)); boost::gregorian::date::ymd_type ymd = d.year_month_day(); datetm.tm_year = ymd.year - 1900; datetm.tm_mon = ymd.month - 1; </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Wed, 09 Jun 2010 18:09:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3563#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3563#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/62681" title="Silence silly GCC warnings. Refs #3563. ">[62681]</a>) Silence silly GCC warnings. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3563" title="#3563: Patches: Warnings using g++ 4.4.0 on date_time/posix_time/conversion.hpp (closed: fixed)">#3563</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Wed, 09 Jun 2010 18:10:15 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3563#comment:4 https://svn.boost.org/trac10/ticket/3563#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/62682" title="Silence silly GCC warnings. Fixes #3563. ">[62682]</a>) Silence silly GCC warnings. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3563" title="#3563: Patches: Warnings using g++ 4.4.0 on date_time/posix_time/conversion.hpp (closed: fixed)">#3563</a>. </p> Ticket anonymous Wed, 07 Jul 2010 22:30:40 GMT status, version changed; resolution deleted https://svn.boost.org/trac10/ticket/3563#comment:5 https://svn.boost.org/trac10/ticket/3563#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.42.0</span> → <span class="trac-field-new">Boost 1.43.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Better to zero-initialize with: std::tm timetm = std::tm(); </p> Ticket Andrey Semashev Thu, 08 Jul 2010 07:47:32 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3563#comment:6 https://svn.boost.org/trac10/ticket/3563#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> There is no conceptual difference. And the problem is fixed. </p> Ticket