I have minimized the reproducible example as far as I was able to. In it, I loop over all edges in the boost graph and get a warning that I don't understand. Please explain to me why I am getting this warning, and perhaps also why it only appears in certain optimization levels.
/*
* reproducing the warning about maybe uninitialized edge iterator
*/
#include <vector>
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
typedef boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::directedS> traits;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property,
boost::property<boost::edge_capacity_t, long>> graph;
typedef traits::vertex_descriptor vertex_desc;
typedef traits::edge_descriptor edge_desc;
typedef boost::graph_traits<graph>::edge_iterator edge_iterator;
int main(){
// build a graph
graph G(10);
// get its capacity map
auto c_map = boost::get(boost::edge_capacity, G);
// get a handle to the first vertex
vertex_desc source = boost::vertex(0, G);
// add an edge, with a capacity of 1
edge_desc e = boost::add_edge(boost::vertex(0, G), boost::vertex(1, G), G).first;
c_map[e] = 1;
// loop over all edges in the graph
std::pair<edge_iterator, edge_iterator> eip = boost::edges(G);
for (edge_iterator eit = eip.first; eit != eip.second; eit++){
edge_desc e = *eit;
vertex_desc a = boost::source(e, G);
vertex_desc b = boost::target(e, G);
bool source_involved = ((a == source) || (b == source));
std::cout << (source_involved ? "yes" : "no") << std::endl;
}
}
Compiled with -O0 or -O1, there are no warnings:
g++ -std=c++14 -Wall -Wextra -O0 repro.cpp -o repro.exe
Compiled with -O2 I get this warning:
# g++ -std=c++14 -Wall -Wextra -O2 repro.cpp -o repro.exe
repro.cpp: In function 'int main()':
repro.cpp:28:24: warning: '*((void*)& eit +48)' may be used uninitialized in this function [-Wmaybe-uninitialized]
for (edge_iterator eit = eip.first; eit != eip.second; eit++){
^~~
And compiled with -O3, -O4, -O5 I get a similar warning, but in ugly:
# g++ -std=c++14 -Wall -Wextra -O3 repro.cpp -o repro.exe
repro.cpp: In function 'int main()':
repro.cpp:28:24: warning: '*((void*)(& eit)+32).__gnu_cxx::__normal_iterator<boost::detail::stored_edge_property<long unsigned int, boost::property<boost::edge_capacity_t, long int> >*, std::vector<boost::detail::stored_edge_property<long unsigned int, boost::property<boost::edge_capacity_t, long int> >, std::allocator<boost::detail::stored_edge_property<long unsigned int, boost::property<boost::edge_capacity_t, long int> > > > >::_M_current' may be used uninitialized in this function [-Wmaybe-uninitialized]
for (edge_iterator eit = eip.first; eit != eip.second; eit++){
My g++ --version is
g++ (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0
And I'm running in docker
# uname -a
Linux 88157d45c773 5.4.0-58-generic #64~18.04.1-Ubuntu SMP Wed Dec 9 17:11:11 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
The warning does appear in -std=c++11 and -std=c++14 but not in -std=c++17, it seems.
What is this warning telling me? What is the issue?
