https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122659

            Bug ID: 122659
           Summary: Move constructor of derived class used by a template
                    defined in one module but instantiated in an inline
                    function in another is not emitted in any object file
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: brady at bullwinkle dot ca
  Target Milestone: ---

Created attachment 62775
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62775&action=edit
Preprocessed source inner.ii

$ cat inner.cpp
export module inner;

export struct Base {
  Base() = default;
  Base(Base&& other) { (void)other; }
};

export struct Derived: public Base {};

export template<typename T> struct Wrapper {
  T t;
  Wrapper(T&& t): t(static_cast<T&&>(t)) {}
};

export template<bool> Wrapper<Derived> bar() {
  return {Derived{}};
}

$ cat outer.cpp
export module outer;

import inner;

export inline void foo() {
  bar<false>();
}

$ cat bug.cpp
import outer;

int main() {
  foo();
  return 0;
}

$ stat gcm.cache
stat: cannot statx 'gcm.cache': No such file or directory
$ g++ -std=c++23 -fmodules-ts -c -Wall -Wextra -Werror inner.cpp
$ g++ -std=c++23 -fmodules-ts -c -Wall -Wextra -Werror outer.cpp
$ g++ -std=c++23 -fmodules-ts -c -Wall -Wextra -Werror bug.cpp
$ g++ -std=c++23 -fmodules-ts inner.o outer.o bug.o
/usr/bin/ld: bug.o: in function `Wrapper@inner<Derived@inner>
bar@inner<false>()':
bug.cpp:(.text._ZW5inner3barILb0EES_7WrapperIS_7DerivedEv[_ZW5inner3barILb0EES_7WrapperIS_7DerivedEv]+0x2e):
undefined reference to `Wrapper@inner<Derived@inner>::Wrapper(Derived@inner&&)'
collect2: error: ld returned 1 exit status

$ g++ -v
Using built-in specs.
COLLECT_GCC=/opt/gcc-15.2/bin/g++
COLLECT_LTO_WRAPPER=/opt/gcc-15.2/libexec/gcc/x86_64-pc-linux-gnu/15.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/gcc-15.2 --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.2.0 (GCC)

Reply via email to