Skip to content

Clang fails to compile code that uses std::apply on a member variable from a __restrict member function #42411

@ameisen

Description

@ameisen
mannequin
Bugzilla Link 43066
Version trunk
OS All
CC @dwblaikie,@DougGregor,@dobbelaj-snps,@ameisen,@zygoloid,@zoecarver

Extended Description

The following code fails to compile under Clang with '-std=c++2a' and '-std=c++17':

#include <tuple>

struct foo {
    const std::tuple<int> v_;
    constexpr foo (int v) : v_(v) {}

    bool operator == (int value) const __restrict {
        return std::apply([](auto) {return true;}, v_);
    }
};

bool test (int v) {
    return foo{0} == v;
}

If the __restrict is removed from the operator ==, it compiles.

This code successfully compiles under GCC and MSVC:

https://godbolt.org/z/S8bGiA

The core errors appear to be:

tuple:1271:44: error: implicit instantiation of undefined template 'std::tuple_size<__restrict std::tuple<int> >'
    inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;

tuple:1686:44: error: non-type template argument is not a constant expression
      using _Indices = make_index_sequence<tuple_size_v<decay_t<_Tuple>>>;

tuple:1687:14: error: no matching function for call to '__apply_impl'
      return std::__apply_impl(std::forward<_Fn>(__f),

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"rejects-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions