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

            Bug ID: 127231
           Summary: `<type error>` is printed out when delete of an
                    unknown identifier
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
void f()
{
    t = new int;
    delete t;
}
```

Currently c++ front-end errors out with:
```
<source>: In function 'void f()':
<source>:3:5: error: 't' was not declared in this scope
    3 |     t = new int;
      |     ^
<source>:4:5: error: type '<type error>' argument given to 'delete', expected
pointer
    4 |     delete t;
      |     ^~~~~~~~
```

It seems like if the type was error_mark_node, the C++ front-end could print
out a different error message about identifier not be declared.  Since most
likely the intent was a pointer type.

For comparison, clang errors out this way:
```
<source>:3:5: error: use of undeclared identifier 't'
    3 |     t = new int;
      |     ^
<source>:4:12: error: use of undeclared identifier 't'
    4 |     delete t;
      |            ^
```

edg only prints out an error about the first line.

MSVC prints out an error message similar to GCC:
```
<source>(3): error C2065: 't': undeclared identifier
<source>(4): error C2065: 't': undeclared identifier
<source>(4): error C2541: 'delete': cannot delete objects that are not pointers
```
  • [Bug c++/127231] New: `<type er... pinskia at gcc dot gnu.org via Gcc-bugs

Reply via email to