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

            Bug ID: 115196
           Summary: Bad error message when using library functions from
                    versions before they were introduced
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luigighiron at gmail dot com
  Target Milestone: ---

GCC generates some error messages when attempting to use library functions
without including the appropriate header, indicating that the appropriate
header should be included. This seems to act incorrectly when attempting to use
a library function from a version before the function was introduced, for
example:

#include<memory>
int main(){
    std::to_address((void*)0);
}

std::to_address was introduced in C++20 so when using the default compilation
settings, i.e. C++17 this code is invalid. This is the generated error message
from testing on godbolt with GCC 14.1.0:

<source>: In function 'int main()':
<source>:3:10: error: 'to_address' is not a member of 'std'
    3 |     std::to_address((void*)0);
      |          ^~~~~~~~~~
<source>:2:1: note: 'std::to_address' is defined in header '<memory>'; this is
probably fixable by adding '#include <memory>'
    1 | #include<memory>
  +++ |+#include <memory>
    2 | int main(){

This note doesn't seem to be very helpful, it mentions adding an extra
'#include<memory>' when one is already present. A better error message here
would be to omit the note, or to make it mention changing the selected C++
standard version.

Reply via email to