Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: cast from pointer to smaller type #52

Open
SteveLee123 opened this issue Mar 26, 2024 · 10 comments
Open

error: cast from pointer to smaller type #52

SteveLee123 opened this issue Mar 26, 2024 · 10 comments

Comments

@SteveLee123
Copy link

I use x86_64 gcc and I encounter this error. how can I fix that ?
seems that is because my pointer is 64bits.

In file included from /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.4.0/../../../../include/c++/11.4.0/memory:72:
/usr/local/lib/gcc/x86_64-pc-linux-gnu/11.4.0/../../../../include/c++/11.4.0/bits/align.h:66:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
   66 |   const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@qqiangwu
Copy link
Owner

still, it's the problem of headers. uintptr_t are the same length of pointers by design.

Please provide the concrete os versions and how to re-produce it, otherwise I cannot handle it.

@SteveLee123
Copy link
Author

SteveLee123 commented Mar 26, 2024

still, it's the problem of headers. uintptr_t are the same length of pointers by design.

Please provide the concrete os versions and how to re-produce it, otherwise I cannot handle it.

I got them from google:

'uintptr_t' (aka 'unsigned int') is alwasys 4bytes.
but pointer is 4bytes at 32bit system and 8bytes at 64bit system.

seems that is not about headers.

@qqiangwu
Copy link
Owner

NO. see https://en.cppreference.com/w/cpp/types/integer

uintptr_t(optional) | unsigned integer type capable of holding a pointer to void(typedef)

@qqiangwu
Copy link
Owner

I somehow knowns the problem, but I need an environment to reproduce it. Please wait.

A potential solution is to not rely on auto-detection, specify includes by your self. For example:

cppsafe a.cpp -- -isystem/usr/include -isystem/usr/local/include

Remember to replace these -isystem to your local c/c++ includes.

@SteveLee123
Copy link
Author

I somehow knowns the problem, but I need an environment to reproduce it. Please wait.

A potential solution is to not rely on auto-detection, specify includes by your self. For example:

cppsafe a.cpp -- -isystem/usr/include -isystem/usr/local/include

Remember to replace these -isystem to your local c/c++ includes.

seems that I can't use compile_commands.json if I use --

@qqiangwu
Copy link
Owner

seems that I can't use compile_commands.json if I use --

Can you show me your compile_commands.json?

@SteveLee123
Copy link
Author

SteveLee123 commented Mar 26, 2024

I will show you part of it tomorrow.

@SteveLee123
Copy link
Author

I somehow knowns the problem, but I need an environment to reproduce it. Please wait.

A potential solution is to not rely on auto-detection, specify includes by your self. For example:

cppsafe a.cpp -- -isystem/usr/include -isystem/usr/local/include

Remember to replace these -isystem to your local c/c++ includes.

so you still think is because the headers ?
how can I make sure I got the right header by auto-detection?

my header directory search way is like this: #42 (comment)

@SteveLee123
Copy link
Author

SteveLee123 commented Mar 27, 2024

fix by:
cppsafe -p xxxx a.cpp --extra-arg=-m32

because cppsafe cannot detect my cpu.

@SteveLee123
Copy link
Author

SteveLee123 commented Mar 27, 2024

Can you show me your compile_commands.json?

I somehow know the reason of why I got so many headers error.

Firstly, I compile my project with gcc7.3.0, so My compile_commands.json is generated by gcc 7.3.0;
Secondly, I upgrate my gcc to 11.4.0, and compile cppsafe .
Lastly, I use cppsafe -p compile_commands.json xxx.cpp.

Are these error all about I use a wrong version of gcc in my compile_commands.json?
And I need to downgrade my gcc to 7.3.0?
Is it right ?

Thanks for helping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants