Skip to content

constexpr cast operator crashes parser #1073

Open
@abandoned-cocoon

Description

@abandoned-cocoon

The parser seems to fail on

struct a {
  constexpr operator int() { return 3; }
};

I modified Parser::rOtherDeclaration to look for ID_operator recursively

if(is_constructor)
{
  #ifdef DEBUG
  std::cout << std::string(__indent, ' ') << "Parser::rOtherDeclaration 4\n";
  #endif

  assert(!type_name.get_sub().empty());

  std::function<bool(typet&)> is_operator_recurse = [&](typet& t) {
    for(unsigned i=0; i < t.get_sub().size(); i++)
    {
      irept& sub = t.get_sub()[i];
      if(sub.id() == ID_operator)
        return true;
    }
    if(t.id() == ID_merged_type)
      for (auto& st: t.subtypes())
          if (is_operator_recurse(st))
            return true;
    return false;
  };

  is_operator = is_operator_recurse(type_name);

}

but that just moves the crash to a later phase (cpp_typecheckt::typecheck_compound_declarator)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions