Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:33:12+00:00 2026-06-08T18:33:12+00:00

I get some warning with template and g++ -Os. Why ? How to remove

  • 0

I get some warning with template and g++ -Os.
Why ?
How to remove these warning with -Os -Winline ?

Edit 1: g++ v4.6.1 And if I replace uint32_t by unsigned int my main error is corrected: ( This bug has been reported: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52888 )

Event.h:109:12: attention : inlining failed in call to ‘uint32_t Event<ParamT>::attach(ListenerT*, bool (ListenerT::*)(ParamT)) [with ListenerT = Listener, ParamT = unsigned int, uint32_t = unsigned int]’: mismatched arguments [-Winline]

Edit 2: The following warning seem to be a g++ error (http://gcc.gnu.org/ml/gcc-help/2012-07/msg00029.html) ( I havn’t any ~Player() ) inlining failed in call to ‘Player::~Player()’: call is unlikely and code size would grow [-Winline]

Edit 3: For removing the previous warning, add Player::~Player() __attribute__ ((noinline)) {}

.

Code for testing: Event.h

#ifndef EVENT_H
#define EVENT_H

#include <map>
#include <stdint.h>

/***************************************************************************//*!
* @brief Collect Listener
* @tparam ParamT        Param type of the function
*/
template<typename ParamT>
class EventHandlerBase
{
    public:
        virtual bool notify( ParamT param ) = 0;
};


/***************************************************************************//*!
* @brief Conteneur d'un receveur d'event.
* @tparam ListenerT     Object type
* @tparam ParamT        Param type of the function
*/
template<typename ListenerT, typename ParamT>
class EventHandler : public EventHandlerBase<ParamT>
{
    private:
        typedef bool (ListenerT::*PtrMember)(ParamT);

    private:
        ListenerT*      m_object;//!< Object listener
        PtrMember       m_member;//!< Function listener

    public:
        /********************************************************************//*!
        * @brief Constructor
        * @param[in] object     Instance listener
        * @param[in] member     Function listener ( Function need to be a public member of {object} )
        * @return[NONE]
        */
        EventHandler( ListenerT* object, PtrMember member )
        {
            m_object = object;
            m_member = member;
        }


        /*******************************************************************//*!
        * @brief Emit a signal to listeners
        * @param[in] param      Data
        * @return FALSE for breaking event loop
        */
        bool notify( ParamT param )
        {
            return (m_object->*m_member)(param);
        }
};


/***************************************************************************//*!
* @brief Event system
* @tparam ParamT        Param type of the function
*/
template<typename ParamT>
class Event
{
    private:
        typedef typename std::map< uint32_t, EventHandlerBase<ParamT>* > HandlersMap;

    private:
        HandlersMap     m_handlers;//!< Contient la liste des instances::fonctions en écoute sur cet event
        uint32_t        m_counter;//!< Permet de gérer les id

    public:
        /********************************************************************//*!
        * @brief Constructor
        * @return[NONE]
        */
        Event()
        {
            m_counter = 0;
        }


        /********************************************************************//*!
        * @brief Destructor
        * @return[NONE]
        */
        ~Event()
        {
            typename HandlersMap::iterator it = m_handlers.begin();
            for(; it != m_handlers.end(); it++)
            {
                if( it->second )
                    delete it->second;
            }
        }


        /*******************************************************************//*!
        * @brief Link a function and instance to this event
        * @param[in] object     Instance listener
        * @param[in] PtrMember  Function listener ( Function need to be a public member of {object} )
        * @return Connection ID
        *
        * @warning DO NOT FORGET TO CALL Event::detach(uint32_t) if you delete {object}
        */
        template<typename ListenerT>
        uint32_t attach( ListenerT* object, bool (ListenerT::*PtrMember)(ParamT) )
        {
            m_handlers[m_counter] = new EventHandler<ListenerT,ParamT>(object, PtrMember);
            m_counter++;
            return m_counter-1;
        }


        /*******************************************************************//*!
        * @brief Emit a signal to listeners
        * @param[in] param      Data
        * @return[NONE]
        */
        void notify( ParamT param )
        {
            typename HandlersMap::iterator it = m_handlers.begin();
            for(; it != m_handlers.end(); it++)
            {
                if( !it->second->notify(param) )
                    return ;
            }
        }


        /*******************************************************************//*!
        * @brief Unlink a listener.
        * @param[in] id     Connection ID from Event::attach
        * @return TRUE if removed
        */
        bool detach( uint32_t id )
        {
            typename HandlersMap::iterator it = m_handlers.find(id);

            if( it == m_handlers.end() )
                return false;

            delete it->second;
            m_handlers.erase(it);
            return true;
        }
};

#endif // EVENT_H

Main.cpp

#include <stdio.h>
#include "Event.h"

class Player
{
    public:
        Event<uint32_t> e_speed;

    private:
        uint32_t        m_speed;

    public:
        Player()
        {
            m_speed = 15;
        }
        void setSpeed( uint32_t speed )
        {
            m_speed = speed;
            e_speed.notify(speed);
        }
};

class Listener
{
    private:
        Player      m_player;

    public:
        Listener()
        {
            m_player.e_speed.attach(this, &Listener::SLOT_speed);
        }
        bool SLOT_speed( uint32_t speed )
        {
            printf("Speed changed to %u\n", speed);
            return true;
        }
        Player* player()
        {
            return &m_player;
        }
};

int main()
{
    Listener l;
    l.player()->setSpeed(42);

    return 0;
}

Compile this code with: g++ -Os -W -Wall -Winline *.cpp
You will get these warning:

Event.h:109:12: attention : inlining failed in call to ‘uint32_t Event<ParamT>::attach(ListenerT*, bool (ListenerT::*)(ParamT)) [with ListenerT = Listener, ParamT = unsigned int, uint32_t = unsigned int]’: mismatched arguments [-Winline]
main.cpp:32:56: attention : appelé d'ici [-Winline]
main.cpp:4:7: attention : inlining failed in call to ‘Player::~Player()’: call is unlikely and code size would grow [-Winline]
main.cpp:31:3: attention : appelé d'ici [-Winline]
main.cpp:4:7: attention : inlining failed in call to ‘Player::~Player()’: call is unlikely and code size would grow [-Winline]
main.cpp:24:7: attention : appelé d'ici [-Winline]
main.cpp:4:7: attention : inlining failed in call to ‘Player::~Player()’: call is unlikely and code size would grow [-Winline]
main.cpp:24:7: attention : appelé d'ici [-Winline]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:33:13+00:00Added an answer on June 8, 2026 at 6:33 pm

    It seems that g++ expands typedefs before using them as template arguments, but fails to expand typedefs not used as template arguments when comparing them with the former.

    A simpler version of your code illustrates this :

    #include <iostream>
    
    typedef unsigned int uint32_t;
    
    template <typename T>
    class Foo {
        public :
            template <typename C>
            void fun(C* c, void (C::*f)(T)) {
                (c->*f)(42);
            }
    };
    
    class BarBad {
        private :
            Foo<uint32_t> foo;
    
        public :
            BarBad() {
                foo.fun(this, &BarBad::fun);
            }
            void fun(uint32_t t) {
                std::cout << t << std::endl;
            }
    };
    
    template <typename T>
    class BarGood {
        private :
            Foo<T> foo;
    
        public :
            BarGood() {
                foo.fun(this, &BarGood<T>::fun);
            }
            void fun(T t) {
                std::cout << t << std::endl;
            }
    };
    
    int main(void) {
        BarBad bb;
        BarGood<uint32_t> bg;
        return 0;
    }
    

    This code only gets a warning for the BarBad code :

    test.cpp: In function ‘int main()’:
    test.cpp:9: warning: inlining failed in call to ‘void Foo<T>::fun(C*, void (C::*)(T)) [with C = BarBad, T = unsigned int]’: function not considered for inlining
    test.cpp:20: warning: called from here
    

    In BarBad, when calling Foo<uint32_t>::fun, the type of the second parameter is void (BarBad::*)(uint32_t), but the called function expects void (BarBad::*)(unsigned int), and fails to see that uint32_t and unsigned int are the same types.

    In BarGood<uint32_t>, when calling Foo<uint32_t>::fun, the type of the second parameter is void (BarGood<uint32_t>::*)(unsigned int), which matches what the called function expects.

    This feels like a compiler bug to me. And a bit of searching turned up this bug report :

    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52888

    I haven’t tested whether the solution there fixes this issue too, but it sounds like it would.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the middle of some work and suddenly I get this. Warning: require(/opt/lampp/htdocs/ERP/laravel/÷5
I get some datetime (ExactDate) from a db. These time are in US timezone,
I'm having some trouble with this warning message, it is implemented within a template
I'm making practice with CakePHP user registration validation but I get some error from
For some reason I get some warnings about non dll-interface class when building with
I get some wierd logs, which obviously only occurs on Android-Devices with Versions below
I get some data from an PHP-Script via AJAX and want to have the
I get some weird overflow whenever I want to fit an object inside foreignObject
i get some Color Value like #FF6100. now i was need Covert #FF6100 to
I was hoping to get some help with my SQL Server script. Basically, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.