[Bug c++/123737] New: GCC produces incorrect output when overloading operator, comma operator

jlame646 at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Jan 21 03:13:40 GMT 2026


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

            Bug ID: 123737
           Summary: GCC produces incorrect output when overloading
                    operator, comma operator
           Product: gcc
           Version: 15.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following program's output is unexpected and differs from clang and msvc:
https://godbolt.org/z/j6a1811d4
```
#include <cstddef>
#include <iostream>

struct Counter { // Counts number of `operator,` calls
  std::size_t count = 0;

  Counter& operator,(int) {
    ++count;
    return *this;
  }

  void finish(const char* label, std::size_t expected) const {
    std::cout << label << ": count=" << count << " expected=" << expected <<
"\n";
  }
};

int main() {


  Counter c130;
  c130, // an array of 130 zeros
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0;
  c130.finish("131", 131);
  return 0;
}
```
GCC outputs: 
```
131: count=3 expected=131
```
while the expected output is:
```
131: count=131 expected=131
```


More information about the Gcc-bugs mailing list