Skip to content
Snippets Groups Projects

Fix deduction of property return values.

Merged Scott Snyder requested to merge ssnyder/Gaudi:propRetVal-20180315 into master
  1. Mar 15, 2018
    • scott snyder's avatar
      Fix deduction of property return values. · 5b1679c6
      scott snyder authored
      Fixes gcc8 compilation error with
      
      prop["foo"]
      
      where prop is a Property<std::map<std::string, std::string> >.
      
      One gets an error like this (trimmed for brevity):
      
      Control/AthenaExamples/AthExHelloWorld/src/HelloAlg.cxx: In constructor 'HelloAlg::HelloAlg(const string&, ISvcLocator*)':
      Control/AthenaExamples/AthExHelloWorld/src/HelloAlg.cxx:26:11: error: no match for 'operator[]' (operand types are 'Gaudi::Property<std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > >' and 'const char [8]')
         m_myDict["Bonjour"]      = "Guten Tag";
                 ^
      In file included from /home/sss/atlas/extern/Gaudi/current/GaudiKernel/GaudiKernel/GaudiHandle.h:7,
                       from /home/sss/atlas/extern/Gaudi/current/GaudiKernel/GaudiKernel/ToolHandle.h:5,
                       from Control/AthenaExamples/AthExHelloWorld/src/HelloAlg.h:10,
                       from Control/AthenaExamples/AthExHelloWorld/src/HelloAlg.cxx:9:
      /home/sss/atlas/extern/Gaudi/current/GaudiKernel/GaudiKernel/Property.h:544:49: note: candidate: 'template<class ARG, class T> decltype (declval<T>()[ARG{}]) Gaudi::Property<TYPE, VERIFIER, HANDLERS>::operator[](const ARG&) [with ARG = ARG; T = T; TYPE = std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >; VERIFIER = Gaudi::Details::Property::NullVerifier; HANDLERS = Gaudi::Details::Property::UpdateHandler]'
           inline decltype( std::declval<T>()[ARG{}] ) operator[]( const ARG& arg )
                                                       ^~~~~~~~
      /home/sss/atlas/extern/Gaudi/current/GaudiKernel/GaudiKernel/Property.h:544:49: note:   template argument deduction/substitution failed:
      /home/sss/atlas/extern/Gaudi/current/GaudiKernel/GaudiKernel/Property.h: In substitution of 'template<class ARG, class T> decltype (declval<T>()[ARG{}]) Gaudi::Property<std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > >::operator[]<ARG, T>(const ARG&) [with ARG = char [8]; T = std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >]':
      Control/AthenaExamples/AthExHelloWorld/src/HelloAlg.cxx:26:21:   required from here
      /home/sss/atlas/extern/Gaudi/current/GaudiKernel/GaudiKernel/Property.h:544:39: error: taking address of temporary array
           inline decltype( std::declval<T>()[ARG{}] ) operator[]( const ARG& arg )
                            ~~~~~~~~~~~~~~~~~^
      
      
      Easiest fix seems to be to use decltype(auto) for the return types.
      5b1679c6
Loading