public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning
@ 2013-01-25 10:50 joerg.richter@pdv-fs.de
  2013-01-25 13:04 ` [Bug c++/56104] " daniel.kruegler at googlemail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: joerg.richter@pdv-fs.de @ 2013-01-25 10:50 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

             Bug #: 56104
           Summary: Wrong "dereferencing type-punned pointer" warning
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: joerg.richter@pdv-fs.de


cat > t.cc <<EOF
struct Foo
{
    void call()
    {}
};

template<class MEMSIG, MEMSIG MEMFUNC>
struct Wrap
{
    inline static void call( Foo cc )
    {
      (cc.*MEMFUNC)();     // <- warning here
    }
};

void bar()
{
  Wrap<void (Foo::*)(), &Foo::call>::call( Foo() );
}
EOF

/tools/pkg/gcc/4.7.2/bin/g++ -Wall -O2 -c -o t.o t.cc


Outputs:
t.cc: In instantiation of 'static void Wrap<MEMSIG, MEMFUNC>::call(Foo) [with
MEMSIG = void (Foo::*)(); MEMSIG MEMFUNC = &Foo::call]':
t.cc:18:38:   required from here
t.cc:12:7: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]

I think this warning is wrong.


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

* [Bug c++/56104] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
@ 2013-01-25 13:04 ` daniel.kruegler at googlemail dot com
  2013-01-25 14:36 ` [Bug c++/56104] [4.7/4.8 Regression] " jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-01-25 13:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-01-25 13:03:27 UTC ---
I can see the same warning for gcc 4.8.0 20130120 (experimental). It's
essential to have -02 set (maybe even higher). I agree that the diagnostics
seems incorrect and the code seems to be well-formed and well-defined.


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

* [Bug c++/56104] [4.7/4.8 Regression] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
  2013-01-25 13:04 ` [Bug c++/56104] " daniel.kruegler at googlemail dot com
@ 2013-01-25 14:36 ` jakub at gcc dot gnu.org
  2013-01-25 14:58 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-25 14:36 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-01-25
                 CC|                            |jakub at gcc dot gnu.org
   Target Milestone|---                         |4.7.3
            Summary|Wrong "dereferencing        |[4.7/4.8 Regression] Wrong
                   |type-punned pointer"        |"dereferencing type-punned
                   |warning                     |pointer" warning
     Ever Confirmed|0                           |1

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-25 14:35:46 UTC ---
Started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176461
Of course, might be a FE bug which has been just latent before.


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

* [Bug c++/56104] [4.7/4.8 Regression] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
  2013-01-25 13:04 ` [Bug c++/56104] " daniel.kruegler at googlemail dot com
  2013-01-25 14:36 ` [Bug c++/56104] [4.7/4.8 Regression] " jakub at gcc dot gnu.org
@ 2013-01-25 14:58 ` jakub at gcc dot gnu.org
  2013-01-25 15:06 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-25 14:58 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-25 14:57:47 UTC ---
Guess the relevant change in the patch is:
--- trunk/gcc/cp/typeck.c    2011/07/19 13:28:15    176460
+++ trunk/gcc/cp/typeck.c    2011/07/19 14:01:59    176461
@@ -3078,8 +3078,7 @@
         return error_mark_node;
     }
       /* ...and then the delta in the PMF.  */
-      instance_ptr = build2 (POINTER_PLUS_EXPR, TREE_TYPE (instance_ptr),
-                 instance_ptr, fold_convert (sizetype, delta));
+      instance_ptr = fold_build_pointer_plus (instance_ptr, delta);

       /* Hand back the adjusted 'this' argument to our caller.  */
       *instance_ptrptr = instance_ptr;
where we didn't fold the POINTER_PLUS_EXPR in this case before (delta is 0
here), but now we do.
The above is followed by:
      /* Next extract the vtable pointer from the object.  */
      vtbl = build1 (NOP_EXPR, build_pointer_type (vtbl_ptr_type_node),
                     instance_ptr);
      vtbl = cp_build_indirect_ref (vtbl, RO_NULL, complain);
      if (vtbl == error_mark_node)
        return error_mark_node;
and during cp_build_indirect_ref this warns, instance_ptr here is ADDR_EXPR of
cc VAR_DECL, and as the class type of cc isn't virtual, it doesn't have a
vtable pointer at the beginning.


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

* [Bug c++/56104] [4.7/4.8 Regression] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
                   ` (2 preceding siblings ...)
  2013-01-25 14:58 ` jakub at gcc dot gnu.org
@ 2013-01-25 15:06 ` jakub at gcc dot gnu.org
  2013-01-25 15:32 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-25 15:06 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-25 15:05:48 UTC ---
Given the
/* If the object is not dynamic the access invokes undefined
   behavior.  As it is not executed in this case silence the
   spurious warnings it may provoke.  */
comment after it, can't we just build the INDIRECT_REF by hand instead of
cp_build_indirect_ref ?  Or revert richi's hunk and force always
POINTER_PLUS_EXPR, even for zero offset?  Then this warning isn't emitted.


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

* [Bug c++/56104] [4.7/4.8 Regression] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
                   ` (3 preceding siblings ...)
  2013-01-25 15:06 ` jakub at gcc dot gnu.org
@ 2013-01-25 15:32 ` jason at gcc dot gnu.org
  2013-01-25 17:56 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-25 15:32 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-25 15:32:17 UTC ---
If we know the dynamic type of the object, we can avoid building the
questionable code in the first place.


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

* [Bug c++/56104] [4.7/4.8 Regression] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
                   ` (4 preceding siblings ...)
  2013-01-25 15:32 ` jason at gcc dot gnu.org
@ 2013-01-25 17:56 ` jason at gcc dot gnu.org
  2013-01-25 20:27 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-25 17:56 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-25 17:55:22 UTC ---
Author: jason
Date: Fri Jan 25 17:55:09 2013
New Revision: 195470

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195470
Log:
    PR c++/56104
    * typeck.c (get_member_function_from_ptrfunc): Optimize if the
    dynamic type has no virtual functions.

Added:
    trunk/gcc/testsuite/g++.dg/warn/pmf2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/g++.old-deja/g++.mike/pmf1.C


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

* [Bug c++/56104] [4.7/4.8 Regression] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
                   ` (5 preceding siblings ...)
  2013-01-25 17:56 ` jason at gcc dot gnu.org
@ 2013-01-25 20:27 ` jason at gcc dot gnu.org
  2013-01-25 20:29 ` jason at gcc dot gnu.org
  2013-01-31 16:35 ` jason at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-25 20:27 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-25 20:26:56 UTC ---
Author: jason
Date: Fri Jan 25 20:26:46 2013
New Revision: 195476

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195476
Log:
    PR c++/56104
    * typeck.c (get_member_function_from_ptrfunc): Don't fold
    POINTER_PLUS_EXPR.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/warn/pmf2.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/typeck.c


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

* [Bug c++/56104] [4.7/4.8 Regression] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
                   ` (6 preceding siblings ...)
  2013-01-25 20:27 ` jason at gcc dot gnu.org
@ 2013-01-25 20:29 ` jason at gcc dot gnu.org
  2013-01-31 16:35 ` jason at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-25 20:29 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-25 20:29:22 UTC ---
Fixed for 4.8 by not building the questionable code at all; fixed for 4.7 by
reverting the fold_build_pointer_plus change.


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

* [Bug c++/56104] [4.7/4.8 Regression] Wrong "dereferencing type-punned pointer" warning
  2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
                   ` (7 preceding siblings ...)
  2013-01-25 20:29 ` jason at gcc dot gnu.org
@ 2013-01-31 16:35 ` jason at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-31 16:35 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56104

--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-31 16:34:29 UTC ---
Author: jason
Date: Thu Jan 31 16:34:14 2013
New Revision: 195614

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195614
Log:
    PR c++/56162
    PR c++/56104
    * typeck.c (get_member_function_from_ptrfunc): Fix
    ptrmemfunc_vbit_in_delta case.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c


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

end of thread, other threads:[~2013-01-31 16:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-25 10:50 [Bug c++/56104] New: Wrong "dereferencing type-punned pointer" warning joerg.richter@pdv-fs.de
2013-01-25 13:04 ` [Bug c++/56104] " daniel.kruegler at googlemail dot com
2013-01-25 14:36 ` [Bug c++/56104] [4.7/4.8 Regression] " jakub at gcc dot gnu.org
2013-01-25 14:58 ` jakub at gcc dot gnu.org
2013-01-25 15:06 ` jakub at gcc dot gnu.org
2013-01-25 15:32 ` jason at gcc dot gnu.org
2013-01-25 17:56 ` jason at gcc dot gnu.org
2013-01-25 20:27 ` jason at gcc dot gnu.org
2013-01-25 20:29 ` jason at gcc dot gnu.org
2013-01-31 16:35 ` jason at gcc dot gnu.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).