Bug 69898 - Possibility for function with cv-qualifier-seq be adjusted to function pointer
Summary: Possibility for function with cv-qualifier-seq be adjusted to function pointer
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-22 01:30 UTC by wander
Modified: 2016-02-24 15:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
A more detailed testcase (804 bytes, application/download)
2016-02-24 15:22 UTC, wander
Details

Note You need to log in before you can comment on or make changes to this bug.
Description wander 2016-02-22 01:30:10 UTC
Hello there!

Simple code:

template <typename T>
struct test
{
    typedef void(* type)(T);
};

typedef void foo_t() const;

typedef test<foo_t>::type func_t; 

We've got a function type with cv-qualifier-seq acquires the properties of a function pointer, although it's prohibited by Standard. This behavior occurs in the entire range of compilers. And not only g++, but many others too (cl, clang, icc, etc).
Do I understand right that func_t (in this case) is invalid type, and it shouldn't be compiled?
So we can use it to bypass the restrictions and create a pointer to cv-qualified function:

template <typename F>
struct create_pointer
{
    typedef void func_t(F);
    
    template <typename X>
    struct extract 
    { typedef X type; };
    template <typename X>
    struct extract<void(X)> 
    { typedef X type; };
    
    typedef typename extract<func_t>::type type;
};

int main()
{
    create_pointer<void() const>::type p = 0;
}
Comment 1 Daniel Krügler 2016-02-22 18:24:04 UTC
I would argue that the code should be ill-formed, because the attempt to form a pointer to a function with cv-qualifier-seq is invalid, see

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1417
Comment 2 wander 2016-02-22 19:19:53 UTC
(In reply to Daniel Krügler from comment #1)
> I would argue that the code should be ill-formed, because the attempt to
> form a pointer to a function with cv-qualifier-seq is invalid, see
> 
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1417

I am talking about the same :)
Comment 3 wander 2016-02-24 15:22:06 UTC
Created attachment 37786 [details]
A more detailed testcase