Thread: c++11 compilation errors on RHEL 7 with respect to STL insert

  1. #1
    Registered User
    Join Date
    Mar 2019
    Posts
    2

    c++11 compilation errors on RHEL 7 with respect to STL insert

    Hi,

    Below function calls are resulting in compilation errors in RHEL 7.6 with c++11 compiler option. But compiles successfully with RHEL 6. Please let me know what's the issue. Whether STL function definitions and templates has changed between RHEL 7.6 and RHEL 6 .Also please suggest how to resolve this compilation errors.

    1. Funcation call:
    -----------------
    Code:
    outputSimArgMap->insert(std::make_pair($1, (SimArgList*) NULL));
    Compilation error :
    -------------------
    Code:
    error: no matching function for call to ‘CommHandler::SimArgMap::insert(std::pair<char*, CommHandler::SimArgList*>)’
            outputSimArgMap->insert(std::make_pair($1, (SimArgList*) NULL));
                                                                                       ^
    /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:74:83: note: candidates are:
    In file included from /usr/include/c++/4.8.2/map:61:0,
                     from /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/include/SimArgs.h:8,
                     from /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:2:
    /usr/include/c++/4.8.2/bits/stl_map.h:594:7: note: std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::basic_string<char>; _Tp = std::shared_ptr<CommHandler::SimArgList>; _Compare = ci_compare; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >; typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >; std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> >]
           insert(const value_type& __x)
           ^
    /usr/include/c++/4.8.2/bits/stl_map.h:594:7: note:   no known conversion for argument 1 from ‘std::pair<char*, CommHandler::SimArgList*>’ to ‘const value_type& {aka const std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> >&}’
    /usr/include/c++/4.8.2/bits/stl_map.h:602:9: note: template<class _Pair, class> std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(_Pair&&) [with _Pair = _Pair; <template-parameter-2-2> = <template-parameter-1-2>; _Key = std::basic_string<char>; _Tp = std::shared_ptr<CommHandler::SimArgList>; _Compare = ci_compare; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >]
             insert(_Pair&& __x)
             ^
    /usr/include/c++/4.8.2/bits/stl_map.h:602:9: note:   template argument deduction/substitution failed:
    /usr/include/c++/4.8.2/bits/stl_map.h:598:32: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
           template<typename _Pair, typename = typename
                                    ^
    /usr/include/c++/4.8.2/bits/stl_map.h:615:7: note: void std::map<_Key, _Tp, _Compare, _Alloc>::insert(std::initializer_list<std::pair<const _Key, _Tp> >) [with _Key = std::basic_string<char>; _Tp = std::shared_ptr<CommHandler::SimArgList>; _Compare = ci_compare; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >]
           insert(std::initializer_list<value_type> __list)
           ^
    /usr/include/c++/4.8.2/bits/stl_map.h:615:7: note:   no known conversion for argument 1 from ‘std::pair<char*, CommHandler::SimArgList*>’ to ‘std::initializer_list<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >’
    /usr/include/c++/4.8.2/bits/stl_map.h:644:7: note: std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::insert(std::map<_Key, _Tp, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::basic_string<char>; _Tp = std::shared_ptr<CommHandler::SimArgList>; _Compare = ci_compare; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >; std::map<_Key, _Tp, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >; std::map<_Key, _Tp, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >; std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> >]
           insert(const_iterator __position, const value_type& __x)
           ^
    /usr/include/c++/4.8.2/bits/stl_map.h:644:7: note:   candidate expects 2 arguments, 1 provided
    /usr/include/c++/4.8.2/bits/stl_map.h:655:9: note: template<class _Pair, class> std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::insert(std::map<_Key, _Tp, _Compare, _Alloc>::const_iterator, _Pair&&) [with _Pair = _Pair; <template-parameter-2-2> = <template-parameter-1-2>; _Key = std::basic_string<char>; _Tp = std::shared_ptr<CommHandler::SimArgList>; _Compare = ci_compare; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >]
             insert(const_iterator __position, _Pair&& __x)
             ^
    /usr/include/c++/4.8.2/bits/stl_map.h:655:9: note:   template argument deduction/substitution failed:
    /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:74:83: note:   cannot convert ‘std::make_pair<char*&, CommHandler::SimArgList*>((* & yyvsp->YYSTYPE::name), (* &0u))’ (type ‘std::pair<char*, CommHandler::SimArgList*>’) to type ‘std::map<std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList>, ci_compare>::const_iterator {aka std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >}’
            outputSimArgMap->insert(std::make_pair($1, (SimArgList*) NULL));
                                                                                       ^
    In file included from /usr/include/c++/4.8.2/map:61:0,
                     from /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/include/SimArgs.h:8,
                     from /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:2:
    /usr/include/c++/4.8.2/bits/stl_map.h:670:9: note: template<class _InputIterator> void std::map<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::basic_string<char>; _Tp = std::shared_ptr<CommHandler::SimArgList>; _Compare = ci_compare; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::shared_ptr<CommHandler::SimArgList> > >]
             insert(_InputIterator __first, _InputIterator __last)
             ^
    /usr/include/c++/4.8.2/bits/stl_map.h:670:9: note:   template argument deduction/substitution failed:
    /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:74:83: note:   candidate expects 2 arguments, 1 provided
            outputSimArgMap->insert(std::make_pair($1, (SimArgList*) NULL));
    2.)

    Function call:
    ----------------

    File CliParser.y ->

    Code:
    GetIntegralHelper SimArgMap::getArgument(const std::string& varName, bool mandatory, bool eraseElem)
    {
        auto it = find(varName);
        if(it != end())
        {
            if(it->second == NULL)
                throw std::invalid_argument(varName+": value not provided");
            try
            {
                if(eraseElem)
                {
                    std::string ret = std::move(it->second->getElemValue().getArgString());
                    erase(it);
    Line 263 ->     return ret;
                }
    File SimArgs.h ->

    Code:
    class GetIntegralHelper
           {
                std::string     m_str;
    Line 53 ->  GetIntegralHelper(std::string&& str) : m_str(str) {}
    Compilation Error :
    ----------------------

    Code:
    In member function ‘CommHandler::GetIntegralHelper CommHandler::SimArgMap::getArgument(const string&, bool, bool)’:
    /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:263:24: error: cannot bind ‘std::string {aka std::basic_string<char>}’ lvalue to ‘std::string&& {aka std::basic_string<char>&&}’
                     return ret;
                            ^
    In file included from /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:2:0:
    /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/include/SimArgs.h:53:3: error:   initializing argument 1 of ‘CommHandler::GetIntegralHelper::GetIntegralHelper(std::string&&)’
       GetIntegralHelper(std::string&& str) : m_str(str) {}
       ^
    3.)

    Function call:
    ---------------


    File CliParser.y ->

    Code:
    GetListHelper SimArgMap::getArgumentList(const std::string& varName, bool mandatory, bool eraseElem)
    {
        auto it = find(varName);
        if(it != end())
        {
            if(eraseElem)
            {
                GetListHelper ret(std::move(*it->second), varName);
                erase(it);
                return ret;
            }
            else
            {
    -> Line :294 return GetListHelper(*it->second, varName);


    File SimArgs.h ->

    Code:
           class GetListHelper
            {
                 SimArgList m_list;
                 const std::string& m_varName;
    Line :81->   GetListHelper(SimArgList&& list, const std::string& varName) : m_list(std::move(list)), m_varName(varName) {}
    Compilation Error:
    -------------------

    Code:
    In member function ‘CommHandler::GetListHelper CommHandler::SimArgMap::getArgumentList(const string&, bool, bool)’:
    /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:294:45: error: cannot bind ‘CommHandler::SimArgList’ lvalue to ‘CommHandler::SimArgList&&’
        return GetListHelper(*it->second, varName);
                                                 ^
    In file included from /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/src/CliParser.y:2:0:
    /fgw_test/test/NETSim/SimulatorNew/Common/CommHandler/include/SimArgs.h:81:3: error:   initializing argument 1 of ‘CommHandler::GetListHelper::GetListHelper(CommHandler::SimArgList&&, const string&)’
       GetListHelper(SimArgList&& list, const std::string& varName) : m_list(std::move(list)), m_varName(varName) {}
       ^
    Thanks,

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Shalini
    Below function calls are resulting in compilation errors in RHEL 7.6 with c++11 compiler option. But compiles successfully with RHEL 6.
    You compile with a compiler, not an operating system. While stating the operating system is good, you still should say exactly what compiler versions are involved, so someone aware of changes between versions of that compiler would be in a better position to advise you.

    Quote Originally Posted by Shalini
    Also please suggest how to resolve this compilation errors.
    For each of the three issues that you're facing, come up with the smallest and simplest program that you expect to compile, but which demonstrates the error. In other words, instead of this:
    Code:
    outputSimArgMap->insert(std::make_pair($1, (SimArgList*) NULL));
    where you should have told us the types of all the entities involved, and which is obviously invalid syntax since $1 is not a valid identifier in C++ (but perhaps you're running your C++ code through some kind of preprocessor that will replace $1 with a valid identifier), skip all that and isolate the problem such that you give us a small self-contained program that we can try to compile for ourselves and see what is the error, and hence suggest how to fix it. It is possible that while trying to come up with this program, you will have an "aha!" moment in isolating the problem and realise what is your mistake and so fix it yourself.

    What I can suggest is to use nullptr instead of (SimArgList*) NULL, but it may do nothing to fix the error you're facing.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    The dollar-sign character is an implementation-defined identifier character in many compilers (such as gcc and MSVC). It's wacky, very rarely seen, and I think in most people's opinions really shouldn't be used at all.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MPI Odd Even Sort - errors during compilation
    By brianbyrneirl in forum C Programming
    Replies: 4
    Last Post: 12-03-2011, 07:31 AM
  2. Compilation Errors
    By nagarjuna02 in forum C# Programming
    Replies: 2
    Last Post: 02-10-2010, 08:55 PM
  3. Linking and compilation errors
    By _lazycat_ in forum Windows Programming
    Replies: 2
    Last Post: 02-13-2009, 07:16 AM
  4. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  5. Compilation Errors
    By nevermind in forum C++ Programming
    Replies: 8
    Last Post: 10-28-2002, 07:42 AM

Tags for this Thread