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

            Bug ID: 115364
           Summary: ICE-on-invalid when calling non-const template member
                    on const object
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blubban at gmail dot com
  Target Milestone: ---

struct foo
{
    template<int> void not_const() {}
};
void fn(const foo& obj) { obj.not_const<5>(); }


No flags needed.


<source>: In member function 'void foo::fn() const':
<source>:4:41: error: cannot convert 'const foo*' to 'foo*'
    4 |     void fn() const { this->not_const<5>(); }
      |                       ~~~~~~~~~~~~~~~~~~^~
<source>:4:41: internal compiler error: tree check: expected function_decl,
have template_decl in get_fndecl_argument_location, at cp/call.cc:8354
0x26aa1ac internal_error(char const*, ...)
        ???:0
0x96fd9e tree_check_failed(tree_node const*, char const*, int, char const*,
...)
        ???:0
0xa7d15f complain_about_bad_argument(unsigned int, tree_node*, tree_node*,
tree_node*, int)
        ???:0
0xa8c20a build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ???:0
0xce8267 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xc6a70a c_parse_file()
        ???:0
0xdbfcf9 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1


Online reproducer: https://godbolt.org/z/86noE3935


I would've expected something as simple as this to have been tested and fixed
long ago, but apparently not. Probably because it's just a tree check; from
what I've heard, they don't exist in versioned releases of GCC.

Reply via email to