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

            Bug ID: 118908
           Summary: c++ include <memory> defines uintptr_t *sometimes*
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bernd.edlinger at hotmail dot de
  Target Milestone: ---

previously uintptr_t was always defined after #include <memory>
but gcc-15 does this only in an unpredictable way, consider this
example:

$ cat test.cc
#include <memory>

uintptr_t x;

int main()
{
 return 0;
}

$ gcc test.cc 
test.cc:3:1: error: ‘uintptr_t’ does not name a type
    3 | uintptr_t x;
      | ^~~~~~~~~
test.cc:2:1: note: ‘uintptr_t’ is defined in header ‘<cstdint>’; this is
probably fixable by adding ‘#include <cstdint>’
    1 | #include <memory>
  +++ |+#include <cstdint>
    2 | 
$ gcc -fsanitize=address test.cc 
test.cc:3:1: error: ‘uintptr_t’ does not name a type
    3 | uintptr_t x;
      | ^~~~~~~~~
test.cc:2:1: note: ‘uintptr_t’ is defined in header ‘<cstdint>’; this is
probably fixable by adding ‘#include <cstdint>’
    1 | #include <memory>
  +++ |+#include <cstdint>
    2 | 
$ gcc -fsanitize=thread test.cc 
$ gcc --std=c++20 test.cc 


This funny behavior started with the following commit:

commit 3a817a4a5a6d94da9127af3be9f84a74e3076ee2 (HEAD)
Author:     Jonathan Wakely <jwak...@redhat.com>
AuthorDate: Thu Dec 7 12:13:59 2023 +0000
Commit:     Jonathan Wakely <r...@gcc.gnu.org>
CommitDate: Thu Aug 1 21:56:56 2024 +0100

    libstdc++: Remove unnecessary uses of <stdint.h>

    We don't need to include all of <stdint.h> when we only need uintptr_t
    from it. By using GCC's internal macro we avoid unnecessarily declaring
    everything in <stdint.h>. This helps users to avoid accidentally relying
    on those names being declared without explicitly including the header.

    libstdc++-v3/ChangeLog:

            * include/bits/align.h (align, assume_aligned): Use
            __UINTPTR_TYPE__ instead of uintptr_t. Do not include
            <stdint.h>.
            * include/bits/atomic_base.h (__atomic_ref): Likewise.
            * include/bits/atomic_wait.h (__waiter_pool_base::_S_for):
            Likewise.
            * include/std/atomic: Include <cstdint>.

Reply via email to