microsoft / microsoft/STL

`<array>`: CTAD and element count limit

Open
#5,665 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

The pseudo code below when compiled with clang errors out.

static constexpr const std::array arr = { 49000 items };

error:


<compiler>\lib\native\include\type_traits:40:27: error: recursive template instantiation exceeded maximum depth of 1024 [clang-diagnostic-error]
   40 |     using type = typename _Conjunction<static_cast<bool>(_Next::value), _Next, _Rest...>::type;
      |                           ^
<compiler>\lib\native\include\type_traits:40:27: note: in instantiation of template class 'std::_Conjunction<true, std::is_same<unsigned int, unsigned int>, ..., std::is_same<unsigned int, unsigned int>>' requested here
  584 |         conjunction_v<is_same<_First, _Rest>...>, "N4950 [array.cons]/2: Mandates: (is_same_v<T, U> && ...) is true.");
      |         ^
<compiler>\lib\native\include\array:589:43: note: in instantiation of template class 'std::_Enforce_same<unsigned int, ..., unsigned int>' requested here
  589 | array(_First, _Rest...) -> array<typename _Enforce_same<_First, _Rest...>::type, 1 + sizeof...(_Rest)>;
      |                                           ^
<file>:11:35: note: while substituting deduced template arguments into function template '<deduction guide for array>' [with _First = unsigned int, _Rest = <unsigned int, ..., unsigned int>]
   11 | static constexpr const std::array arr = {
      |  

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the 49,000-element CTAD case with clang, then read the std::array deduction guide and _Enforce_same in alongside _Conjunction in <type_traits>. Determine why the recursive instantiation exceeds the depth limit and verify that the case compiles without changing the required element-type checking.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.