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

            Bug ID: 122609
           Summary: modules and class type structured bindings
           Product: gcc
           Version: 16.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: ---

It appears that the search for the tuple customisation points in a template
instantiation when processing a structured binding doesn't work nicely.

Consider the following set of files:

// a.cpp
module;
namespace std {
  using size_t = decltype(sizeof(0));
  template <typename T> struct tuple_size;
  template <size_t N, typename T> struct tuple_element;
}
export module std;
namespace std {
  export using std::size_t;
  export using std::tuple_size;
  export using std::tuple_element;
}


// b.cpp
export module X;
import std;  // marking 'export import' fixed the issue

struct S {};
template <> struct std::tuple_size<S> {
  static constexpr std::size_t value = 2;
};
template <std::size_t I> struct std::tuple_element<I, S> {
  using type = int;
};
template <int N> int get(S) { return N; }

export template <typename T>
void foo() {
  S s;
  auto [a, b] = s;
}
template void foo<int>();  // works


// c.cpp
import X;
int main() {
  foo<double>();  // errors
}


$ g++ -Wno-global-module -fmodules -S [abc].cpp
In module X, imported at c.cpp:1:
b.cpp: In instantiation of ‘void foo@X() [with T = double]’:
required from here
c.cpp:3:14:
    3 |   foo<double>();  // errors
      |   ~~~~~~~~~~~^~
b.cpp:16:8: error: cannot decompose class type ‘S@X’ without non-static data
members
   16 |   auto [a, b] = s;
      |        ^~~~~~


Unfortunately, by a (somewhat hostile) reading of the standard I think this
example can be considered invalid.  In this scenario, from 'c.cpp' name lookup
for 'std::tuple_size' fails, and so [dcl.struct.bind] p7 does not apply.  But I
think we should make sure to support this for QoI purposes.  (Maybe there's a
wording issue here somewhere...)


Referenced Bugs:

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

Reply via email to