chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.81k stars 1.2k forks source link

experimental/concurrent_channel crash 0xC0000005 #1307

Open kahotv opened 1 year ago

kahotv commented 1 year ago

using my_channel = concurrent_channel<void(asio::error_code, std::size_t)>; int main() { A a; a.show(); }

class A { public: A() :m_ch(m_ctx) {} void show() { printf("hello\n"); } private: // crash: my_channel m_ch; io_context m_ctx; // not crash: //io_context m_ctx; //my_channel m_ch; };

kashirin-alex commented 1 year ago

put a -Werror -Wall -Werror -Wextra -Wpedantic -Weffc++ flags in your compile build . -- If it can't compile such code, it is for a good reason

You cannot be ignoring initialization order , by doing so, A() :m_ch(m_ctx) {} m_ch is initialized with uninitialized storage