GCC rejects this code:

template <void (*p)()> struct pp
{ 
  static void (*the_p)();
};
template <void (*p)()> void (* pp<p>::the_p )() = p;

typedef struct
{ 
  static void f() { }
  struct pp<f> mypp;
} f_struct;

void g()
{ 
  pp<f_struct::f>::the_p = 0;
}

with

t9.cc:10: error: '<anonymous struct>::f' is not a valid template argument for
type 'void (*)()' because function 'static void<anonymous struct>::f()' has not
external linkage
t9.cc: In function 'void g()':
t9.cc:15: error: 'f_struct::f' is not a valid template argument for type 'void
(*)()' because function 'static void f_struct::f()' has not external linkage
t9.cc:15: error: invalid type in declaration before '=' token

I believe this is incorrect.  f_struct has external linkage by [basic.link]
paragraph 4 item 3, and then f_struct::f has external linkage by paragraph 5.

There is a FIXME in decl.c that says:

          /* FIXME remangle member functions; member functions of a
             type with external linkage have external linkage.  */

which is related but not quite the same thing; it's not just the mangling that
is a problem.


-- 
           Summary: need to rework behaviour of 'typedef struct { ... } x;'
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: geoffk at gcc dot gnu dot org


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

Reply via email to