Good day!acquires
I came across an interesting feature in the behavior of popular
compilers and would like to understand the reasons.
There's a simple code:
#include <iostream>
template <typename F>
void (* declval() ) (F);
template <typename X>
char (& probe( void(*) ( X * ) ) )[1];
template <typename X>
char (& probe( void(*) ( X ) ) )[2];
int main()
{
std::cout << sizeof( probe(declval<void() const>()) );
}
The question is about type deduction. If you run this code on
* compiler GCC 4.8.x (or later)
* compiler Clang 3.4 (or later)
* compiler in the Visual Stuido (tested on VS 2013 Community)
* compiler Intel ICC 13.0.1
it will display the number "1". And I thought it is logical, since
function type, being substituted argument in another function,
the properties of a pointer type.
On newer versions of compilers mentioned (except for VS and ICC)
behavior has changed and now this code for Clang 3.5 (or higher), GCC
4.9 (or higher) displays the number "2". If you remove the second
overload, then the mentioned versions of GCC and Clang error occurs:
"Forming pointer to qualified function type"
I understand why but doubt whether this rule applies in this context.
In particular, it would be interesting to know whether the behavior of
the new and old versions of the compilers conforms to C++ Standard.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 434 |
Nodes: | 16 (2 / 14) |
Uptime: | 119:05:55 |
Calls: | 9,109 |
Calls today: | 3 |
Files: | 13,422 |
Messages: | 6,030,803 |