https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123526
Bug ID: 123526
Summary: Linking error when using standard exception as base
class
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: d7d1cd at mail dot ru
Target Milestone: ---
In the trunk version of the compiler with the -std=c++26 option, attempting to
create a user-defined exception object whose base class is any standard
exception type other than std::range_error results in a link error. The linker
cannot find the definition of the standard exception constructor.
The following example demonstrates this:
$ cat main.cc
#include <stdexcept>
template <typename TBase>
class MyException : public TBase {
using TBase::TBase;
};
int main() {
throw MyException<std::logic_error>("Oops");
}
Compilation results in a link error:
$ g++ -std=c++26 main.cc
gnu/bin/ld: /tmp/cc8bHDIu.o: in function `main':
<source>:13:(.text+0x1d): undefined reference to
`MyException<std::logic_error>::MyException(char const*)'
collect2: error: ld returned 1 exit status
Here's a replica in the online compiler with all standard exception types
(again, there is no link error with the std::range_error type):
https://godbolt.org/z/1cx3oec69
The above code links in gcc 15.2 with the -std=c++26 option:
https://godbolt.org/z/bx71dYd78, and also links in the trunk version with the
option -std=c++23: https://godbolt.org/z/edGxoqEK1