Skip to content

[libc++] _LIBCPP_CTAD_SUPPORTED_FOR_TYPE does not work for out of class defined nested classes #64719

@crtrott

Description

@crtrott

I ran into this problem with mdspan layouts, when I tried to rely on the implicitly defined deduction guides.
That works but produces a warning with -Wctad-maybe-unsupported on the compile line.

It was suggested to use _LIBCPP_CTAD_SUPPORTED_FOR_TYPE but that gives a compile error: https://godbolt.org/z/7n48snYfb

Adding the deduction guide explicitly in the layout_left class leads to this warning:

__fwd/mdspan.h:55:3: error: unused function template '<deduction guide for mapping>' [-Werror,-Wunused-template]
   55 |   mapping(_Extents, array<_OtherIndexType, _Extents::rank>) -> mapping<_Extents>;

which I can silence with a [[maybe_unused]], that however leads to a compile error with GCC: https://godbolt.org/z/69xEqavGv

Here is the code reproducer:

#include <__config>
#include<array>

struct layout_left {
  template<class E> 
  struct mapping;
  _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(mapping);
};

template<class E> 
struct layout_left::mapping {
  template<class T>
  mapping(E e, std::array<T, 1> a) {}
};


void func() {
  layout_left::mapping m(5, std::array<int,1>{1});
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions