https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69898

            Bug ID: 69898
           Summary: Possibility for function with cv-qualifier-seq be
                    adjusted to function pointer
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wandersys at aim dot com
  Target Milestone: ---

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;
}

Reply via email to