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

            Bug ID: 99158
           Summary: [Enhancement] Better error message when missing
                    #include<new> and using placement new
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kirshamir at gmail dot com
  Target Milestone: ---

Use of placement new requires  #include <new>
Without this include the error message is something like:

error: no matching function for call to 'operator new(sizetype, A*)'
    8 |       new (this) A(other);
      |                         ^
note: candidate function not viable: no known conversion from 'A *' to
'std::align_val_t' for 2nd argument
note: candidate function not viable: requires 1 argument, but 2 were provided

Many std headers have #include <new> thus users just usually write placement
new without a special include and everything works fine, but when code moves
around above error message may just pop up.

A better error might be:

error: no matching function for call to 'operator new'
Note: use of placement new requires #include <new>

...

Reply via email to