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

            Bug ID: 127050
           Summary: [modules] hidden friend declaration in exported class
                    cannot resolve to unexported free function definition
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dr.xiaosa at gmail dot com
  Target Milestone: ---

===
// p.hh
namespace demo {

template <typename A>
struct P {
  template <typename R, typename Self>
  friend constexpr auto operator|(R&&, Self&&);
};

template <typename R, typename Self>
constexpr auto operator|(R&&, Self&&) { return 0; }

}
===

===
// m.cc
module;
#include "p.hh"
export module m;
export namespace demo {
    using demo::P;
}
===

===
// main.cc
import m;
struct T {};
int main() { (void)(T{} | demo::P<int>{}); }
===

Fail with:
===
g++ -std=c++20 -fmodules -o m.o -c m.cc
g++ -std=c++20 -fmodules -o main.o -c main.cc
main.cc: In function 'int main()':
main.cc:4:40: error: use of 'constexpr auto demo::operator|(R&&, Self&&) [with
R = T; Self = P<int>; A = int]' before deduction of 'auto'
    4 | int main() { (void)(T{} | demo::P<int>{}); }
      |                                        ^                              
^
===

If change deduced return type of operator| to 'int', then it emits following
warning:
===
In file included from m.cc:3,
of module m, imported at main.cc:2:
p.hh:7:24: warning: inline function 'constexpr int demo::operator|(R&&, Self&&)
[with R = T; Self = P<int>; A = int]' used but never defined
    7 |   friend constexpr int operator|(R&&, Self&&);
      |                        ^~~~~~~~
===

If add following function to m.cc then the error gone:
===
static void f() { 42 | demo::P<void>{}; }
===

Reply via email to