Skip to content

Introduction of -fbracket-depth broke std::array:s longer than 256 #49522

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
fiesh mannequin opened this issue Apr 30, 2021 · 5 comments
Open

Introduction of -fbracket-depth broke std::array:s longer than 256 #49522

fiesh mannequin opened this issue Apr 30, 2021 · 5 comments
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party rejects-valid

Comments

@fiesh
Copy link
Mannequin

fiesh mannequin commented Apr 30, 2021

Bugzilla Link 50178
Version trunk
OS Linux
CC @DougGregor,@zygoloid

Extended Description

The code at the bottom behaves like this with clang-12:

% clang++ -std=c++17 -c b.cpp
In file included from b.cpp:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10/array:245:52: fatal error: instantiating fold expression with 257 arguments exceeded expression nesting limit of 256
      -> array<enable_if_t<(is_same_v<_Tp, _Up> && ...), _Tp>,
                           ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
b.cpp:6:12: note: while substituting deduced template arguments into function template '<deduction guide for array>' [with _Tp = S, _Up = <S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S>]
std::array a{S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
           ^
1 error generated.

% clang++ -std=c++17 -c -fbracket-depth=512 b.cpp
% echo $?
0

This actually hit our production code and took me a while to reduce. I think limiting the length of std::array to <= 256 by default is not desirable.

This is the code:

#include<array>

struct S {};

std::array a{S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}};
@fiesh
Copy link
Mannequin Author

fiesh mannequin commented Apr 30, 2021

(I should have said limiting the length of std::array being construced via deduction guide to <= 256.)

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@wheatman wheatman added clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid confirmed Verified by a second party labels Oct 19, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 19, 2023

@llvm/issue-subscribers-clang-frontend

Author: None (4f99a97d-37e2-4b4f-939b-3f5760df598b)

| | | | --- | --- | | Bugzilla Link | [50178](https://llvm.org/bz50178) | | Version | trunk | | OS | Linux | | CC | @DougGregor,@zygoloid |

Extended Description

The code at the bottom behaves like this with clang-12:

% clang++ -std=c++17 -c b.cpp
In file included from b.cpp:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10/array:245:52: fatal error: instantiating fold expression with 257 arguments exceeded expression nesting limit of 256
      -&gt; array&lt;enable_if_t&lt;(is_same_v&lt;_Tp, _Up&gt; &amp;&amp; ...), _Tp&gt;,
                           ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
b.cpp:6:12: note: while substituting deduced template arguments into function template '&lt;deduction guide for array&gt;' [with _Tp = S, _Up = &lt;S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S&gt;]
std::array a{S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
           ^
1 error generated.

% clang++ -std=c++17 -c -fbracket-depth=512 b.cpp
% echo $?
0

This actually hit our production code and took me a while to reduce. I think limiting the length of std::array to <= 256 by default is not desirable.

This is the code:

#include&lt;array&gt;

struct S {};

std::array a{S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}};

@wheatman
Copy link
Contributor

confirming that this is still the case in post 17 trunk(5a56f00)
https://godbolt.org/z/4o3oWEzx7

code

#include<array>

struct S {};

std::array a{S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
                     S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}};

error

In file included from <source>:1:
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../include/c++/14.0.0/array:291:52: fatal error: instantiating fold expression with 257 arguments exceeded expression nesting limit of 256
  291 |       -> array<enable_if_t<(is_same_v<_Tp, _Up> && ...), _Tp>,
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
<source>:5:12: note: while substituting deduced template arguments into function template '<deduction guide for array>' [with _Tp = S, _Up = <S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S>]
    5 | std::array a{S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{}, S{},
      |            ^
1 error generated.
Compiler returned: 1

@shafik
Copy link
Collaborator

shafik commented Oct 24, 2023

This feels like it is behaving as expected: https://clang.llvm.org/docs/UsersManual.html#controlling-implementation-limits

Although it might be nice for the diagnostic to point out more information.

CC @AaronBallman

@AaronBallman
Copy link
Collaborator

Yeah, I don't think this is actually a bug; it could be an enhancement request to support a bigger default value than 256, but unless a lot of users are hitting this issue, I think the current limit is reasonable (it's the same default as recommended by the standard in https://eel.is/c++draft/implimits#2.4). The diagnostic could be improved a bit because it's not obvious why bracket depth is involved (it's because a fold expression formally expands to a series of nested parenthesized expressions).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party rejects-valid
Projects
None yet
Development

No branches or pull requests

4 participants