https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109946
Bug ID: 109946 Summary: linker error undefined reference to `vtable for std::bad_expected_access<void>' Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: saifi.khan at nishan dot io Target Milestone: --- Environment: Archlinux kernel 6.3.2 glibc 2.37 gcc 13.1 gcc 14.0.0 Consider the following code import "iostream"; import "string"; import "string_view"; import "expected"; import "charconv"; import "system_error"; namespace parser { enum class error { input_invalid , overflow }; auto logic (std::string_view str) -> std::expected <double, error> { int value {0}; std::from_chars_result result { std::from_chars (str.begin (), str.end (), value) }; if (result.ec == std::errc{}) { return value; } else if (result.ec == std::errc::invalid_argument) { return std::unexpected {error::input_invalid}; } else if (result.ec == std::errc::result_out_of_range) { return std::unexpected {error::overflow}; } } } auto test () -> void { std::string str { "9876dairy" }; const auto result { parser::logic (str) }; if (result.has_value ()) { std::cout << result.value () << '\n'; } else if (result.error () == parser::error::input_invalid) { std::cout << "E: input invalid" << '\n'; } else if (result.error () == parser::error::overflow) { std::cout << "overflow" << '\n'; } else { std::cout << "unexpected" << '\n'; } } The code compiles and program work fine with - gcc 13.1.1 - gcc 14.0.0 as long as i don't use the option -fmodules-ts. When using the -fmodules-ts flag, the following linker error is seen: /usr/bin/ld: /tmp/cchUGnbx.o: warning: relocation against `_ZTVSt19bad_expected_accessIvE' in read-only section `.text._ZNSt19bad_expected_accessIvED2Ev[_ZNSt19bad_expected_accessIvED5Ev]' /usr/bin/ld: /tmp/cchUGnbx.o: in function `std::bad_expected_access<void>::bad_expected_access()': /opt/gcc/include/c++/14.0.0/expected:80: undefined reference to `vtable for std::bad_expected_access<void>' /usr/bin/ld: /tmp/cchUGnbx.o: in function `std::bad_expected_access<void>::~bad_expected_access()': /opt/gcc/include/c++/14.0.0/expected:85: undefined reference to `vtable for std::bad_expected_access<void>' /usr/bin/ld: /tmp/cchUGnbx.o:(.data.rel.ro._ZTISt19bad_expected_accessIN6parser5errorEE[_ZTISt19bad_expected_accessIN6parser5errorEE]+0x10): undefined reference to `typeinfo for std::bad_expected_access<void>' /usr/bin/ld: warning: creating DT_TEXTREL in a PIE collect2: error: ld returned 1 exit status