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

            Bug ID: 119939
           Summary: [modules] Constraints attached to defaulted friend
                    functions don't work correctly
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nshead at gcc dot gnu.org
            Blocks: 103524
  Target Milestone: ---

Consider the following:

  // test.h
  template <typename T> concept A = true;
  template <typename T> concept B = requires { T{}; };
  template <typename T> struct S {
    friend bool operator==(const S&, const S&) requires B<T> = default;
  };

  // test.cpp
  import "test.h";
  int main() {
    S<int> s;
    s == s;
  }

$ g++ -std=c++20 -fmodules -S test.h test.cpp -fconcepts-diagnostics-depth=2
test.cpp: In function ‘int main()’:
test.cpp:5:5: error: no match for ‘operator==’ (operand types are ‘S<int>’ and
‘S<int>’)
    5 |   s == s;
      |   ~ ^~ ~
      |   |    |
      |   |    S<[...]>
      |   S<[...]>
test.cpp:5:5: note: there is 1 candidate
    5 |   s == s;
      |   ~~^~~~
In module test.h, imported at test.cpp:1:
test.h:4:15: note: candidate 1: ‘bool operator==(const S<int>&, const S<int>&)
requires  B<T>’
    4 |   friend bool operator==(const S&, const S&) requires B<T> = default;
      |               ^~~~~~~~
test.h:4:15: note: constraints not satisfied
test.h: In instantiation of ‘bool operator==(const S<int>&, const S<int>&)
requires  B<T>’:
test.cpp:5:8:   required from here
    5 |   s == s;
      |        ^
test.h:2:31:   required for the satisfaction of ‘B<T>’
test.h:2:35:   in requirements  [with T = T]
test.h:2:46: note: the required expression ‘T{}’ is invalid, because
    2 | template <typename T> concept B = requires { T{}; };
      |                                              ^~~
test.h:2:46: error: invalid use of template type parameter ‘T’

This is because by the time we get to satisfy_declaration_constraints in the
importing module, the friend function no longer has template arguments attached
to it, and so constraint satisfaction gets confused.  When not importing the
DECL_TEMPLATE_INFO is still attached to this declaration; it seems that module
streaming should still stream this info even if the decl isn't strictly a
template anymore.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524
[Bug 103524] [meta-bug] modules issue

Reply via email to