https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92181

Robrecht Dewaele <robrecht.dewaele at pegus dot digital> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://godbolt.org/z/baRg-
                   |                            |1

--- Comment #1 from Robrecht Dewaele <robrecht.dewaele at pegus dot digital> ---
The following code was tested on most clang and GCC compilers available on
Godbolt, and my local machine running Arch Linux, gcc (GCC) 9.2.0.

Starting from GCC version 9, the following code results in a compile-time
error:
"modification of '<temporary>' is not a constant expression"
on the line with the closing brace of the initializer_list initialization.

Code on Godbolt (has some extras compared to the minimal version below):
https://godbolt.org/z/baRg-1

// start of source code
#include <string_view>
#include <initializer_list>

struct S { const int i; };

constexpr std::initializer_list<S> foo{
    { []() { return std::string_view("").compare(""); }() }
};
// end of source code

Another version I tested with used a constexpr function rather than a lambda,
with the same failing result.
I have also tried replacing the lambda body with a simple "return true;" which
fixes the error.

Reply via email to