https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110328
Bug ID: 110328 Summary: Module related optimization is too aggressive Product: gcc Version: 12.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: m-matti-a.lehtonen at iki dot fi Target Milestone: --- Created attachment 55375 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55375&action=edit Example sources When the module example (files test.cc and test2.cc) is compiles as > g++-12 --std=c++20 -Wall -Wextra -Werror -pedantic -fmodules-ts -O1 > -DNDEBUG test2.cc test.cc it generates the following error: > In file included from test.cc:4, > of module test, imported at test2.cc:5: > In destructor ‘virtual std::bad_optional_access::~bad_optional_access()’, > inlined from ‘virtual std::bad_optional_access::~bad_optional_access()’ > at > test2.cc:8:15: > /usr/include/c++/12/optional:102:13: error: ‘this’ is used uninitialized > [-Werror=uninitialized] > 102 | virtual ~bad_optional_access() = default; > | ^ > In file included from test2.cc:2: > /usr/include/c++/12/optional: In destructor ‘virtual > std::bad_optional_access::~bad_optional_access()’: > /usr/include/c++/12/optional:102:13: note: ‘this’ was declared here > 102 | virtual ~bad_optional_access() = default; > | ^ If the if statement at test2.cc is uncommented, no error is generated. If basically the same code (file test3.cc) is compiled without using modules, no problem > g++-12 --std=c++20 -Wall -Wextra -Werror -pedantic -O1 -DNDEBUG test3.cc Exact version and system (Ubuntu 22.04.2 LTS) > $ g++-12 --version > g++-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0