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

            Bug ID: 125711
           Summary: [15/16/17 Regression] internal compiler error: tree
                    check: expected class 'expression', have 'declaration'
                    (var_decl) in tree_operand_check, at tree.h:4349
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mirko.yuenyong at teamviewer dot com
  Target Milestone: ---

Created attachment 64689
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64689&action=edit
Proprocessed file of minimal code example

Please see the attached preprocessed file which triggers the bug.
I got this internal compiler error using GCC 15, 16 and 17:

$ /usr/lib/gcc-snapshot/bin/g++ -freport-bug -save-temps -Wall -Wextra
-fno-strict-aliasing -fwrapv -c gcc_ice.cpp 
gcc_ice.cpp: In function 'Empty GetEmpty(bool)':
gcc_ice.cpp:17:28: internal compiler error: tree check: expected class
'expression', have 'declaration' (var_decl) in tree_operand_check, at
tree.h:4349
   17 |                 return Get();
      |                            ^
0x327343f internal_error(char const*, ...)
        ../../src/gcc/diagnostic-global-context.cc:787
0xa67d2a tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
        ../../src/gcc/tree.cc:9269
0x93a67d expr_check(tree_node*, char const*, int, char const*)
        ../../src/gcc/tree.h:3988
0x93a67d tree_operand_check(tree_node*, int, char const*, int, char const*)
        ../../src/gcc/tree.h:4349
0x93a67d gimplify_return_expr
        ../../src/gcc/gimplify.cc:1903
0x16cca2f gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../src/gcc/gimplify.cc:20741
0x16cbb31 gimplify_stmt(tree_node**, gimple**)
        ../../src/gcc/gimplify.cc:8679
0x16cbb31 gimplify_cleanup_point_expr
        ../../src/gcc/gimplify.cc:8406
0x16cbb31 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../src/gcc/gimplify.cc:20878
0x16cdd96 gimplify_stmt(tree_node**, gimple**)
        ../../src/gcc/gimplify.cc:8679
0x16cbd4b gimplify_statement_list
        ../../src/gcc/gimplify.cc:2294
0x16cbd4b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../src/gcc/gimplify.cc:20930
0x16cdd96 gimplify_stmt(tree_node**, gimple**)
        ../../src/gcc/gimplify.cc:8679
0x16cb700 gimplify_and_add(tree_node*, gimple**)
        ../../src/gcc/gimplify.cc:554
0x16cb700 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../src/gcc/gimplify.cc:20831
0x16cdd96 gimplify_stmt(tree_node**, gimple**)
        ../../src/gcc/gimplify.cc:8679
0x16cc3eb gimplify_and_add(tree_node*, gimple**)
        ../../src/gcc/gimplify.cc:554
0x16cc3eb gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../src/gcc/gimplify.cc:20889
0x16cdd96 gimplify_stmt(tree_node**, gimple**)
        ../../src/gcc/gimplify.cc:8679
0x16cb763 gimplify_and_add(tree_node*, gimple**)
        ../../src/gcc/gimplify.cc:554
/usr/lib/gcc-snapshot/libexec/gcc/x86_64-linux-gnu/17/cc1plus -fpreprocessed
gcc_ice.ii -quiet -dumpbase gcc_ice.cpp -dumpbase-ext .cpp -mtune=generic
-march=x86-64 -Wall -Wextra -freport-bug -fno-strict-aliasing -fwrapv -o
gcc_ice.s
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-snapshot/README.Bugs> for instructions.

The compiler versions i could reproduce this are:

$ /usr/lib/gcc-snapshot/bin/g++ --version
g++ (Debian 20260503-1) 17.0.0 20260503 (experimental) [trunk
r17-283-g00f6fb9df07]
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++-16 --version
g++-16 (Debian 16.1.0-1) 16.1.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++-15 --version
g++-15 (Debian 15.2.0-17) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Using GCC 14 (g++-14 (Debian 14.2.0-19) 14.2.0) the code got compiled without
any errors, so i guess this is a regression. 

Also i found a way to mitigate the error: Replacing the ternary conditional by
an if statement compiles just fine on all mentioned versions.

Reply via email to