Skip to content

[C++20][Modules] Weird behavior on std::tuple_element & co. reexport #130205

@DanShaders

Description

@DanShaders

With the following code,

module;

#include <utility>

export module test;

export namespace exported {

using ::std::tuple_element;
using ::std::tuple_size;
using ::std::integral_constant;

}
#include <cstdint>

import test;

struct Foo {
    template<std::size_t i>
    int get() { return 0; }
};

template<>
struct exported::tuple_size<Foo> : exported::integral_constant<std::size_t, 1> {};

template<>
struct exported::tuple_element<0, Foo> { using type = int; };

void foo() {
    auto [a] = Foo{};
}

Clang produces the following diagnostic:

consumer.cpp:17:10: error: type 'Foo' decomposes into 0 elements, but 1 name was provided
   17 |     auto [a] = Foo{};
      |          ^
1 error generated.

as if it doesn't see tuple_size specialization. Note that the diagnostic goes away if I add

namespace std {

export using ::std::tuple_element;
export using ::std::tuple_size;

}

to the module file. I'm not sure if this code is actually UB-free according to standard (it's definitely not when I start touching std namespace) but the current Clang behavior is very confusing.

CE: https://godbolt.org/z/rKxYjrn11

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header ModulesquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions