public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64]
@ 2006-08-03 13:57 denis dot charland at imi dot cnrc-nrc dot gc dot ca
2009-12-08 20:32 ` [Bug c++/28584] Cast to pointer from integer of different size redi at gcc dot gnu dot org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: denis dot charland at imi dot cnrc-nrc dot gc dot ca @ 2006-08-03 13:57 UTC (permalink / raw)
To: gcc-bugs
The following code does not generate any warning when
compiled with g++ 4.0.x and 4.1.x on a x86_64 platform:
/*
#include <cstdio>
int f(void);
int f(void)
{
return (long) &std::printf;
}
*/
typedef unsigned long mysize_t;
void *mymmap(void *start, mysize_t length, int prot , int flags, int fd, int
offset);
//typedef unsigned long DWORD;
typedef unsigned int DWORD;
struct UDA {
DWORD UserDirectAddr;
DWORD TransAddr;
DWORD Bytes;
};
void f(UDA *puda);
void f(UDA *puda)
{
puda->UserDirectAddr =
(unsigned long) mymmap((void *) puda->TransAddr,
puda->Bytes,
0, 0, 0, 0);
}
When compiled with g++ 3.4.6 on the same platform,
the following warning is issued:
g++ -c test.cpp
test.cpp: In function `void f(UDA*)':
test.cpp:30: warning: cast to pointer from integer of different size
--
Summary: Cast to pointer from integer of different size [gcc
4.0.x and 4.1.x on x86_64]
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: denis dot charland at imi dot cnrc-nrc dot gc dot ca
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28584
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/28584] Cast to pointer from integer of different size
2006-08-03 13:57 [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64] denis dot charland at imi dot cnrc-nrc dot gc dot ca
@ 2009-12-08 20:32 ` redi at gcc dot gnu dot org
2010-02-20 18:19 ` manu at gcc dot gnu dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-12-08 20:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from redi at gcc dot gnu dot org 2009-12-08 20:32 -------
reduced:
void f() {
unsigned short i = 0;
void* p = (void*)i;
}
this warns in 32-bit or 64-bit mode using the C compiler, and is controlled by
this option that g++ doesn't support:
-Wno-int-to-pointer-cast (C and Objective-C only)
Suppress warnings from casts to pointer type of an integer of a different size.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28584
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/28584] Cast to pointer from integer of different size
2006-08-03 13:57 [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64] denis dot charland at imi dot cnrc-nrc dot gc dot ca
2009-12-08 20:32 ` [Bug c++/28584] Cast to pointer from integer of different size redi at gcc dot gnu dot org
@ 2010-02-20 18:19 ` manu at gcc dot gnu dot org
2010-02-20 20:15 ` jason at redhat dot com
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-20 18:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from manu at gcc dot gnu dot org 2010-02-20 18:19 -------
Jason, do we want this?
It seems trivial:
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c (revision 156923)
+++ gcc/cp/typeck.c (working copy)
@@ -6260,10 +6260,20 @@ cp_build_c_cast (tree type, tree expr, t
if (complain & tf_error)
error ("invalid cast to function type %qT", type);
return error_mark_node;
}
+
+ if (TREE_CODE (type) == POINTER_TYPE
+ && TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
+ && TYPE_PRECISION (type) != TYPE_PRECISION (TREE_TYPE (value))
+ /* Don't warn about converting any constant. */
+ && !TREE_CONSTANT (value))
+ warning_at (loc,
+ OPT_Wint_to_pointer_cast, "cast to pointer from integer "
+ "of different size");
+
/* A C-style cast can be a const_cast. */
result = build_const_cast_1 (type, value, /*complain=*/false,
&valid_p);
if (valid_p)
return result;
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at redhat dot com,
| |manu at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28584
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/28584] Cast to pointer from integer of different size
2006-08-03 13:57 [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64] denis dot charland at imi dot cnrc-nrc dot gc dot ca
2009-12-08 20:32 ` [Bug c++/28584] Cast to pointer from integer of different size redi at gcc dot gnu dot org
2010-02-20 18:19 ` manu at gcc dot gnu dot org
@ 2010-02-20 20:15 ` jason at redhat dot com
2010-02-22 19:05 ` manu at gcc dot gnu dot org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jason at redhat dot com @ 2010-02-20 20:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from jason at redhat dot com 2010-02-20 20:15 -------
Subject: Re: Cast to pointer from integer of different size
On 02/20/2010 01:19 PM, manu at gcc dot gnu dot org wrote:
> Jason, do we want this?
Sure.
Jason
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28584
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/28584] Cast to pointer from integer of different size
2006-08-03 13:57 [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64] denis dot charland at imi dot cnrc-nrc dot gc dot ca
` (2 preceding siblings ...)
2010-02-20 20:15 ` jason at redhat dot com
@ 2010-02-22 19:05 ` manu at gcc dot gnu dot org
2010-02-22 19:50 ` manu at gcc dot gnu dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-22 19:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from manu at gcc dot gnu dot org 2010-02-22 19:04 -------
Patch http://gcc.gnu.org/ml/gcc-patches/2010-02/msg00891.html
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |manu at gcc dot gnu dot org
|dot org |
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2010-
| |02/msg00891.html
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Keywords| |patch
Last reconfirmed|0000-00-00 00:00:00 |2010-02-22 19:04:58
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28584
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/28584] Cast to pointer from integer of different size
2006-08-03 13:57 [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64] denis dot charland at imi dot cnrc-nrc dot gc dot ca
` (3 preceding siblings ...)
2010-02-22 19:05 ` manu at gcc dot gnu dot org
@ 2010-02-22 19:50 ` manu at gcc dot gnu dot org
2010-04-09 7:50 ` manu at gcc dot gnu dot org
2010-04-09 7:53 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-22 19:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from manu at gcc dot gnu dot org 2010-02-22 19:49 -------
Approved for GCC 4.6
http://gcc.gnu.org/ml/gcc-patches/2010-02/msg00893.html
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
OtherBugsDependingO| |41998
nThis| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28584
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/28584] Cast to pointer from integer of different size
2006-08-03 13:57 [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64] denis dot charland at imi dot cnrc-nrc dot gc dot ca
` (4 preceding siblings ...)
2010-02-22 19:50 ` manu at gcc dot gnu dot org
@ 2010-04-09 7:50 ` manu at gcc dot gnu dot org
2010-04-09 7:53 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-04-09 7:50 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2387 bytes --]
------- Comment #6 from manu at gcc dot gnu dot org 2010-04-09 07:50 -------
Subject: Bug 28584
Author: manu
Date: Fri Apr 9 07:49:41 2010
New Revision: 158150
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158150
Log:
2010-04-09 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c++/28584
* c.opt (Wint-to-pointer-cast): Available in C++.
* doc/invoke.texi (Wint-to-pointer-cast): Available in C++.
cp/
* typeck.c (cp_build_c_cast): Warn for casting integer to larger
pointer type.
testsuite/
* gcc.dg/Wint-to-pointer-cast-1.c: Move to...
* c-c++-common/Wint-to-pointer-cast-1.c: ... here.
* gcc.dg/Wint-to-pointer-cast-2.c: Move to...
* c-c++-common/Wint-to-pointer-cast-2.c: ... here.
* gcc.dg/Wint-to-pointer-cast-3.c: Move to...
* c-c++-common/Wint-to-pointer-cast-3.c: ... here. Update.
* g++.old-deja/g++.mike/warn1.C: Add -Wno-int-to-pointer-cast.
* g++.dg/other/increment1.C: Likewise.
Added:
trunk/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c (props changed)
- copied unchanged from r158134,
trunk/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c
trunk/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c (props changed)
- copied unchanged from r158134,
trunk/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c
trunk/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c (contents,
props changed)
- copied, changed from r158134,
trunk/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c
Removed:
trunk/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c
trunk/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c
trunk/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/c.opt
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/typeck.c
trunk/gcc/doc/invoke.texi
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.dg/other/increment1.C
trunk/gcc/testsuite/g++.old-deja/g++.mike/warn1.C
Propchange: trunk/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c
('svn:mergeinfo' added)
Propchange: trunk/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c
('svn:mergeinfo' added)
Propchange: trunk/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c
('svn:mergeinfo' added)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28584
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/28584] Cast to pointer from integer of different size
2006-08-03 13:57 [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64] denis dot charland at imi dot cnrc-nrc dot gc dot ca
` (5 preceding siblings ...)
2010-04-09 7:50 ` manu at gcc dot gnu dot org
@ 2010-04-09 7:53 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-04-09 7:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from manu at gcc dot gnu dot org 2010-04-09 07:53 -------
FIXED in GCC 4.6
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28584
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-04-09 7:53 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-03 13:57 [Bug c++/28584] New: Cast to pointer from integer of different size [gcc 4.0.x and 4.1.x on x86_64] denis dot charland at imi dot cnrc-nrc dot gc dot ca
2009-12-08 20:32 ` [Bug c++/28584] Cast to pointer from integer of different size redi at gcc dot gnu dot org
2010-02-20 18:19 ` manu at gcc dot gnu dot org
2010-02-20 20:15 ` jason at redhat dot com
2010-02-22 19:05 ` manu at gcc dot gnu dot org
2010-02-22 19:50 ` manu at gcc dot gnu dot org
2010-04-09 7:50 ` manu at gcc dot gnu dot org
2010-04-09 7:53 ` manu at gcc dot gnu dot org
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).