Skip to content

Conversation

AdmiralCurtiss
Copy link
Contributor

I ran into this in C++14 when creating a string_view with a very long string. For example,

namespace {
    constexpr ::nonstd::string_view tmp = ::nonstd::string_view(
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
        "01234567890123456789012345678901234567890123456789"
    );
}

On MSVC 2019 in C++14 mode this gives:

error C2131: expression did not evaluate to a constant
  note: failure was caused by evaluation exceeding call depth limit of 512 (/constexpr:depth<NUMBER>)

And on g++ 9.2.1 this gives

error: ‘constexpr’ evaluation depth exceeds maximum of 512 (use ‘-fconstexpr-depth=’ to increase the maximum)

I don't think we can fix this for C++11, but when we have C++14 we have better ways to write a constexpr length() of a nullterminated string, so might as well do so to work around this problem.

…recursion depth in compile-time constexpr evaluation.
@martinmoene martinmoene merged commit 5990f16 into martinmoene:master Jan 25, 2020
@AdmiralCurtiss AdmiralCurtiss deleted the max-constexpr-recursion-depth branch January 25, 2020 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants