sigs icon indicating copy to clipboard operation
sigs copied to clipboard

Could not convert "void" to "bool"

Open jcracine-cimeq opened this issue 6 months ago • 0 comments

Hi, I've got this weird behaviour where if I put a return type for the signal, its convinced its void?

I've made a quick example on godbolt to try it out because it didn't do that last time i used this library. I've compiled the unit tests to make sure everything works as it should and every tests pass so I'm pretty sure I'm doing something wrong.

For the sake of future proofing this issue, here is the example.

#include <iostream>

class Sender{
    public:
        [[nodiscard]] auto testSignal(){
            return test.interface();
        }

        void send(){
            if(test())
                std::cout << "True" << std::endl;
            else
                std::cout << "False" << std::endl;
        }

    private:
        sigs::Signal<bool()> test;
};

class Receiver{
    public:

        Receiver(bool state): state(state){}
        ~Receiver() = default;

        bool update(){
            return state;
        }
    
    private:
        bool state;
};

int main(){

    Receiver a(true);
    Receiver b(false);

    Sender s;
    s.testSignal()->connect(&a, &Receiver::update);
    s.testSignal()->connect(&b, &Receiver::update);

    return 0;
}

Here's the compiler output:

<source>: In member function 'void Sender::send()':
<source>:12:20: error: could not convert '((Sender*)this)->Sender::test.sigs::BasicSignal<bool(), std::lock_guard<std::mutex> >::operator()()' from 'void' to 'bool'
   12 |             if(test())
      |                ~~~~^~
      |                    |
      |                    void

jcracine-cimeq avatar Aug 07 '25 19:08 jcracine-cimeq