[multi index] warning when used in copy constructor: should be explicitly initialized
Using gcc with option -W I get the following warning when using a Boost.MultiIndex container inside a copy constructor: /usr/local/include/boost-1_33_1/boost/multi_index_container.hpp: In copy constructor 'boost::multi_index::multi_index_container<Value, IndexSpecifierList, Allocator>::multi_index_container(const boost::multi_index::multi_index_container<Value, IndexSpecifierList, Allocator>&) [with Value = ListenMonitor::ListenZeile, IndexSpecifierList = boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::identity<ListenMonitor::ListenZeile>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, Allocator = std::allocator<ListenMonitor::ListenZeile>]': liste.hpp:139: instantiated from here /usr/local/include/boost-1_33_1/boost/multi_index_container.hpp:204: warning: base class 'struct boost::multi_index::detail::header_holder<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ListenMonitor::ListenZeile>
, boost::multi_index::multi_index_container<ListenMonitor::ListenZeile, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::identity<ListenMonitor::ListenZeile>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<ListenMonitor::ListenZeile> > >' should be explicitly initialized in the copy constructor
The 'ListenMonitori::Listenzeile' stuff is from me. But the issue does not depend on that. I would assume that copying a multi index is not forbidden and using Is there a way to get rid of that warning? I am trying hard to produce warning free code, and in this case I am not sure if the warning is just ugly or if it is a real problem in the code. [gcc --version: gcc (GCC) 4.1.2 20061115 (prerelease) (SUSE Linux) ] I have attached a trivial example that demonstrates the issue. I have modified the example/basic.cpp: I have added a trivial class XXX that contains employee_set. When copying objects of XXX the above warning is issued by gcc. Best regards Christoph
Hi Christoph, ----- Mensaje original ----- De: Christoph <christoph.duelli@gmx.de> Fecha: Domingo, Febrero 25, 2007 4:48 pm Asunto: [Boost-users] [multi index] warning when used in copy constructor:should be explicitly initialized Para: boost-users@lists.boost.org
Using gcc with option -W I get the following warning when using a Boost.MultiIndex container inside a copy constructor: [...] warning: base class 'struct boost::multi_index::detail::header_holder<...>' should be explicitly initialized in the copy constructor [...] I would assume that copying a multi index is not forbidden and using
Certainly, copying multi_index_containers is allowed.
Is there a way to get rid of that warning? I am trying hard to produce warning free code, and in this case I am not sure if the warning is just ugly or if it is a real problem in the code.
The warning looks spurious to me, the mentioned class is default constructed in the context where the warning is issued, which is the intended behavior. I don't get why GCC requires explicit initialization. I see you're using Boost 1.33.1. Can you try the following? Please download a RC_1_34_0 snapshot from http://engineering.meta-comm.com/boost/snapshot/boost-CVS- RC_1_34_0.tar.bz2 and check whether the warning persists. If so, I can try to eliminate it. Thank you, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Hi Joaquin, "JOAQUIN LOPEZ MU?Z" wrote: Thank you for looking into this.
I see you're using Boost 1.33.1. Can you try the following? Please download a RC_1_34_0 snapshot from Yes, unfortunately the warning does persist.
Best regards, Christoph
----- Mensaje original ----- De: Christoph <christoph.duelli@gmx.de> Fecha: Domingo, Febrero 25, 2007 9:35 pm Asunto: Re: [Boost-users] [multi index] warning when used in copyconstructor:should be explicitly initialized Para: boost-users@lists.boost.org
Hi Joaquin,
"JOAQUIN LOPEZ MU?Z" wrote: Thank you for looking into this.
I see you're using Boost 1.33.1. Can you try the following? Please download a RC_1_34_0 snapshot from Yes, unfortunately the warning does persist.
Please try inserting the following before line 233 of the RC_1_34 version of multi_index_container.hpp: bfm_header(), Warning gone? If so, I can commit this change in time for Boost 1.34. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
"JOAQUIN LOPEZ MU?Z" ha escrito:
----- Mensaje original ----- De: Christoph <christoph.duelli@gmx.de> Fecha: Domingo, Febrero 25, 2007 9:35 pm Asunto: Re: [Boost-users] [multi index] warning when used in copyconstructor:should be explicitly initialized Para: boost-users@lists.boost.org
Hi Joaquin,
"JOAQUIN LOPEZ MU?Z" wrote: Thank you for looking into this.
I see you're using Boost 1.33.1. Can you try the following? Please download a RC_1_34_0 snapshot from Yes, unfortunately the warning does persist.
Please try inserting the following before line 233 of the RC_1_34 version of multi_index_container.hpp:
bfm_header(),
Warning gone? If so, I can commit this change in time for Boost 1.34.
Hello again, I've verified the patch locally and commited the appropriate changes. I'd be so grateful if you could download again a RC_1_34_0 snapshot from http://engineering.meta-comm.com/boost/snapshot/boost-CVS-RC_1_34_0.tar.bz2 and report if your warnings are now gone. Thank you! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Joaquín Mª López Muñoz wrote:
----- Mensaje original ----- Please try inserting the following before line 233 of the RC_1_34 version of multi_index_container.hpp:
bfm_header(),
Warning gone? If so, I can commit this change in time for Boost 1.34.
Hello again, I've verified the patch locally and commited the appropriate changes. I'd be so grateful if you could download again a RC_1_34_0 snapshot from I have tried it. The snapshot works, my applying the the change myself did not. As I could not find a lot of other diffs in multi_index, I am somewhat baffled as to why. But the important thing is that the snapshot does work! Thank you.
I am not sure if the following minor issue is still multi index's fault. I get the following 'used uninitialized' warning for inf$side (which I did not get before): /linuxtools/apps/boost-RC_1_34_0-07-02-26-1906/boost/multi_index/ordered_index.hpp: In member function 'bool boost::multi_index::detail::ordered_index<KeyFromValue, Compare, SuperMeta, TagList, Category>::replace_(typename boost::call_traits<typename boost::multi_index::detail::ordered_index_node<typename SuperMeta::type::node_type>::value_type>::param_type, boost::multi_index::detail::ordered_index_node<typename SuperMeta::type::node_type>*) [with KeyFromValue = boost::multi_index::const_mem_fun<ListenMonitor::ListenZeile, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, &ListenMonitor::ListenZeile::id>, Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, SuperMeta = boost::multi_index::detail::nth_layer<3, ListenMonitor::ListenZeile, boost::multi_index::indexed_by<boost::multi_index::sequenced<boost::multi_index::tag<mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na> >, boost::multi_index::ordered_non_unique<boost::multi_index::identity<ListenMonitor::ListenZeile>, mpl_::na, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::const_mem_fun<ListenMonitor::ListenZeile, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, &ListenMonitor::ListenZeile::id>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<ListenMonitor::ListenZeile> >, TagList = boost::mpl::vector0<mpl_::na>, Category = boost::multi_index::detail::ordered_unique_tag]': /linuxtools/apps/boost-RC_1_34_0-07-02-26-1906/boost/multi_index/ordered_index.hpp:630: warning: 'inf$side' may be used uninitialized in this function /linuxtools/apps/boost-RC_1_34_0-07-02-26-1906/boost/multi_index/ordered_index.hpp: In member function 'bool ListenMonitor::Liste::updateZeile(const ListenMonitor::ListenZeile&)': /linuxtools/apps/boost-RC_1_34_0-07-02-26-1906/boost/multi_index/ordered_index.hpp:551: warning: 'inf$side' may be used uninitialized in this function Christoph
----- Mensaje original ----- De: Christoph <christoph.duelli@gmx.de> Fecha: Lunes, Febrero 26, 2007 9:54 pm Asunto: Re: [Boost-users] [multi index] warning when used in copy constructor: should be explicitly initialized Para: boost-users@lists.boost.org
Joaquín Mª López Muñoz wrote:
----- Mensaje original ----- Please try inserting the following before line 233 of the RC_1_34 version of multi_index_container.hpp:
bfm_header(),
Warning gone? If so, I can commit this change in time for Boost 1.34.
Hello again, I've verified the patch locally and commited the appropriate changes. I'd be so grateful if you could download again a RC_1_34_0 snapshot from I have tried it. The snapshot works, my applying the the change myself did not. As I could not find a lot of other diffs in multi_index, I am somewhat baffled as to why.
Well, the same warning appeared at other places, so in the end it was five different headers that I had to tweak.
But the important thing is that the snapshot does work! Thank you.
I am not sure if the following minor issue is still multi index's fault. I get the following 'used uninitialized' warning for inf$side (which I did not get before): [...]
You didn't get this before because the warned-about code is new wrt to the Boost 1.33.1 version. Could you please try the following: Replace lines 798-802 of ordered_index.hpp struct link_info { ordered_index_side side; ordered_index_node_impl* pos; }; with struct link_info { link_info(){} ordered_index_side side; ordered_index_node_impl* pos; }; Does this improve anything? BTW, the warning, again, does not reflect any actual problem with the code :( Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
You didn't get this before because the warned-about code is new wrt to the Boost 1.33.1 version. Could you please try the following: Replace lines 798-802 of ordered_index.hpp
struct link_info { ordered_index_side side; ordered_index_node_impl* pos; };
with
struct link_info { link_info(){}
ordered_index_side side; ordered_index_node_impl* pos; };
Does this improve anything? BTW, the warning, again, does not reflect any actual problem with the code :( No, no change. Which is not really a surprise, as the constructor does not really initialize anything, right? When I write link_info() : side(to_left) {} the warning is gone.
Best regards, and thank you Christoph
----- Mensaje original ----- De: Christoph <christoph.duelli@gmx.de> Fecha: Lunes, Febrero 26, 2007 11:04 pm Asunto: Re: [Boost-users] [multi index] warning when used in copy constructor: should be explicitly initialized Para: boost-users@lists.boost.org
You didn't get this before because the warned-about code is new wrt to the Boost 1.33.1 version. Could you please try the following: Replace lines 798-802 of ordered_index.hpp
struct link_info { ordered_index_side side; ordered_index_node_impl* pos; };
with
struct link_info { link_info(){}
ordered_index_side side; ordered_index_node_impl* pos; };
Does this improve anything? BTW, the warning, again, does not reflect any actual problem with the code :( No, no change. Which is not really a surprise, as the constructor does not really initialize anything, right?
Well, it was cheap to try :)
When I write link_info() : side(to_left) {} the warning is gone.
I am reluctant to apply this change, because it incurs a potential runtime penalty (minimal as it may be) for the sake of a spurious warning emitted by a too-smart compiler. Can you figure out some way to silence the warning without runtime impact? Is there any GCC-specific way to do it (pragmas, etc.)? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
I am reluctant to apply this change, because it incurs a potential runtime penalty (minimal as it may be) for the sake of a spurious warning emitted by a too-smart compiler. Yes, I understand that. Personally, I prefer warning free code to tiny bits of efficiency, though.
Can you figure out some way to silence the warning without runtime impact? Is there any GCC-specific way to do it (pragmas, etc.)? I don't know such an option (yet) but I will try to find out if there is any.
Christoph
participants (3)
-
"JOAQUIN LOPEZ MU?Z"
-
Christoph
-
Joaquín Mª López Muñoz