Problem 1238

Summary: G4RootAnalysisManager.cc fails to compile (vdata not STL compliant)
Product: Geant4 Reporter: Michael Kelsey <kelsey>
Component: configAssignee: Gabriele Cosmo <Gabriele.Cosmo>
Status: RESOLVED FIXED    
Severity: minor    
Priority: P3    
Version: 9.4   
Hardware: Apple   
OS: Mac OS X   

Description Michael Kelsey 2011-08-03 18:32:46 CEST
[ NOTE:  There is no "analysis" component in the Bugzilla menu. ]

During compilation on MacOSX 10.5.8, GCC 4.0.1, the build of "analysis" fails:

 Compiling G4RootAnalysisManager.cc ...
 include/tools/wroot/../vdata: In function 'const T* tools::vec_data(const std::vector<T, std::allocator<_CharT> >&) [with T = double]':

 include/tools/wroot/named:164:   instantiated from 'bool tools::wroot::Array_stream(tools::wroot::buffer&, const std::vector<T, std::allocator<_CharT> >&) [with T = double]'
 include/tools/wroot/streamers:81:   instantiated from here
 include/tools/wroot/../vdata:17: error: 'const class std::vector<double, std::allocator<double> >' has no member named 'data'
 include/tools/wroot/../vdata: In function 'const T* tools::vec_data(const std::vector<T, std::allocator<_CharT> >&) [with T = float]':
 include/tools/wroot/named:164:   instantiated from 'bool tools::wroot::Array_stream(tools::wroot::buffer&, const std::vector<T, std::allocator<_CharT> >&) [with T = float]'
 include/tools/wroot/streamers:207:   instantiated from here
 include/tools/wroot/../vdata:17: error: 'const class std::vector<float, std::allocator<float> >' has no member named 'data'
 include/tools/wroot/../vdata: In function 'const T* tools::vec_data(const std::vector<T, std::allocator<_CharT> >&) [with T = int]':
 include/tools/wroot/named:164:   instantiated from 'bool tools::wroot::Array_stream(tools::wroot::buffer&, const std::vector<T, std::allocator<_CharT> >&) [with T = int]'
 include/tools/wroot/tree:66:   instantiated from here
 include/tools/wroot/../vdata:17: error: 'const class std::vector<int, std::allocator<int> >' has no member named 'data'
 gmake[1]: *** [/Users/kelsey/geant4/g4_SVN/geant4/tmp/Darwin-g++/G4analysis/G4RootAnalysisManager.o] Error 1

The error occurs because analysis/include/tools/vdata is using a non-standard construction, std::vector<>::data().

This problem has been seen and discussed elsewhere, for example

http://gcc.gnu.org/ml/gcc-bugs/2008-10/msg02113.html
http://lists.cs.uiuc.edu/pipermail/lldb-dev/2010-July/000165.html

The fix is to eliminate the #if block in vdata, and use &(vector<>::front()) on all platforms.

std::vector<>::data() is apparently part of "C++0x," which is the upcoming C++ new standard, but is not yet deployed consistently:

http://stackoverflow.com/questions/6212572/whats-the-status-of-stdvectordata
Comment 1 Michael Kelsey 2011-08-03 20:35:35 CEST
On further investigation, GCC and Intel compilers define the macro __GXX_EXPERIMENTAL_CXX0X__ in order to use new C++0x language features, such as std::vector<>::data().  

The code in analysis/include/tools/vdata should be rewritten to respect this macro:

  template <class T>
  inline const T* vec_data(const std::vector<T>& a_vec) {
  #ifdef __GXX_EXPERIMENTAL_CXX0X__
    return a_vec.data();
  #else
    return &(a_vec.front());
  #endif
  }
Comment 2 Gabriele Cosmo 2011-08-04 09:49:56 CEST
Fix now included in tag "analysis-V09-04-05".