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

            Bug ID: 114488
           Summary: internal compiler error: unexpected expression
                    static_cast ...
           Product: gcc
           Version: 9.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ing.russomauro at gmail dot com
  Target Milestone: ---

The error is reproduced on godbolt online compiler with gcc 9.5.

It was initially experienced on a local machine.

/* BEGIN CODE */

#include <memory>

int main(){
    const auto b = std::make_shared<int>(1);

    [b](const auto& v) {
        const auto u = static_cast<short>(b ? 1 : 3);
    }(2);
}

/* END CODE */

The compiler message reads:

internal compiler error: unexpected expression 'static_cast<short int>((b ? 1 :
3))' of kind static_cast_expr

Note that the same happens with the gcc versions 9.4 and 10.2, whereas 9.3,
10.1, 10.3, and 13.2 do not present the error (not applicable to version 9.2
for unsupported features). Not checked on intermediate versions between 10.3
and 13.2.
The error arises even adding options to the compiler on godbolt, as
"-std=c++14" or "-std=gnu++14" or "-std=c++17" or "-std=gnu++17" or
"-std=c++2a" or "-std=gnu++2a" (it seems C++14 is the default; nonetheless,
does not affect the resulting internal error).
The error is confirmed even with options either "-Wall -Wextra" or
"-fno-strict-aliasing -fwrapv".

Among the possible duplicates, 63415 has the most similar title but the kind of
source code appears different, I cannot guess whether the root cause was
overlapped or not, taking also into account that 63415 is for version 4.9.1 and
above I mentioned that version 9.2 is not capable to compile my posted code for
missing features.

Reply via email to