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

* [Bug c++/115196] Bad error message when using library functions from versions before they were introduced
  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 ` pinskia at gcc dot gnu.org
  2024-05-22 20:01 ` sjames at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-22 20:00 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Already fixed. Dup of bug 107800.

*** This bug has been marked as a duplicate of bug 107800 ***

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

* [Bug c++/115196] Bad error message when using library functions from versions before they were introduced
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-05-22 20:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Sam James <sjames at gcc dot gnu.org> ---
See r14-10227-g5b96d547ce71b8.

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

* [Bug c++/115196] Bad error message when using library functions from versions before they were introduced
  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
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-22 20:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
You seem to imply it's a general problem, but I think it's specific to
sd::to_address, and that's already fixed.

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

* [Bug c++/115196] Bad error message when using library functions from versions before they were introduced
  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
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-22 20:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Halalaluyafail3 from comment #0)
> 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.

If you'd tried gcc trunk on godbolt you'd have seen that's exactly what
happens:

<source>:3:10: note: 'std::to_address' is only available from C++20 onwards

There was just a typo which made gcc think std::to_address is part of <memory>
in C++11, so if it wasn't declared in your program then it must be because you
didn't include <memory>.

After the fix it correctly suggests using at least C++20.

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

* [Bug c++/115196] Bad error message when using library functions from versions before they were introduced
  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
                   ` (3 preceding siblings ...)
  2024-05-22 20:13 ` redi at gcc dot gnu.org
@ 2024-05-22 20:28 ` luigighiron at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: luigighiron at gmail dot com @ 2024-05-22 20:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Halalaluyafail3 <luigighiron at gmail dot com> ---
(In reply to Jonathan Wakely from comment #4)
> (In reply to Halalaluyafail3 from comment #0)
> > 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.
> 
> If you'd tried gcc trunk on godbolt you'd have seen that's exactly what
> happens:
> 
> <source>:3:10: note: 'std::to_address' is only available from C++20 onwards
> 
> There was just a typo which made gcc think std::to_address is part of
> <memory> in C++11, so if it wasn't declared in your program then it must be
> because you didn't include <memory>.
> 
> After the fix it correctly suggests using at least C++20.

My bad, I only tested this on GCC 14.1 and assumed that GCC 14.1 was recent
enough that it wouldn't have been changed.

^ 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).