Bug 57869 - [C++11] Casting a object pointer to a function pointer should not warn about a forbidden conversion
Summary: [C++11] Casting a object pointer to a function pointer should not warn about ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 minor
Target Milestone: 4.9.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-09 19:52 UTC by Daniel Krügler
Modified: 2013-07-10 16:46 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-07-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2013-07-09 19:52:38 UTC
gcc 4.9.0 20130616 (experimental) diagnoses a warning for the following code compiled with the flags:

-Wall -pedantic -std=c++11

//-------------------------------------
void* po = 0;
void (*pf)() = reinterpret_cast<decltype(pf)>(po); // #2
static_assert(sizeof(po) >= sizeof(pf), "Conversion not supported");
//-------------------------------------

"main.cpp|2|warning: ISO C++ forbids casting between pointer-to-function and pointer-to-object [enabled by default]"

Given that 5.2.10 p8 says:

"Converting a function pointer to an object pointer type or vice versa is conditionally-supported."

and since to my knowledge gcc supports such conversions (without that ::dlopen wouldn't work), the warning should be removed in the context of C++11.
Comment 1 Paolo Carlini 2013-07-09 22:19:08 UTC
Seems easy to fix. We got this (outdated) comment:

      if (pedantic && (complain & tf_warning))
	/* Only issue a warning, as we have always supported this
	   where possible, and it is necessary in some cases.  DR 195
	   addresses this issue, but as of 2004/10/26 is still in
	   drafting.  */
	warning (0, "ISO C++ forbids casting between pointer-to-function and pointer-to-object");

thus it seems just matter of suppressing he warning for c++11 (and c++1y) and updating the comment.
Comment 2 Paolo Carlini 2013-07-10 16:46:35 UTC
Fixed for 4.9.0.