Skip to content

Syntax error for overloaded operator[] in 32-bit address space #124913

@ararmine

Description

@ararmine

x86-64 clang 19.1.0 issues a compilation error for the following example:

  1. cat ex.cpp
struct value {
      public:
        operator int() const;
        struct value &operator[](const char * __ptr32 _param_1);
};

extern struct value *new_value();

int json_send_error(int status)
{
  struct value * v = new_value();
  (void)(*v)["error"];
  return 0;
}
  1. clang ex.cpp -fms-extensions -S
ex.cpp:13:13: error: use of overloaded operator '[]' is ambiguous (with operand types 'struct value' and 'const char[6]')
   13 |   (void)(*v)["error"];
      |         ~~~~^~~~~~~~
ex.cpp:5:23: note: candidate function
    5 |         struct value &operator[](const char * __ptr32 _param_1);
      |                       ^
ex.cpp:13:13: note: built-in candidate operator[](long, const char *)
   13 |   (void)(*v)["error"];
      |             ^
1 error generated.

https://godbolt.org/z/dbvEGfz13

x64 MSVC v.19 compiles successfully https://godbolt.org/z/qWc584f5f

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions