public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115196] New: Bad error message when using library functions from versions before they were introduced
@ 2024-05-22 19:56 luigighiron at gmail dot com
  2024-05-22 20:00 ` [Bug c++/115196] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: luigighiron at gmail dot com @ 2024-05-22 19:56 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-22 20:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-22 19:56 [Bug c++/115196] New: Bad error message when using library functions from versions before they were introduced luigighiron at gmail dot com
2024-05-22 20:00 ` [Bug c++/115196] " pinskia at gcc dot gnu.org
2024-05-22 20:01 ` sjames at gcc dot gnu.org
2024-05-22 20:01 ` redi at gcc dot gnu.org
2024-05-22 20:13 ` redi at gcc dot gnu.org
2024-05-22 20:28 ` luigighiron at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).