The following code should not compile:

template <class T> struct C
{
  friend void f (C *)
  {
    char a[sizeof(T)-1]; // { dg-error "ISO C++ forbids zero-size array" }
  }

  void g (C *t)
  {
    f (t);
  }
};

C <char>x;

The C++ standard clause 14.5.3; 5 states that friend function definitions (as
opposed to declarations) in template classes are instantiated whether they are
used or not. GCC appears to only instantiate them when they are used.

Note, when you add:
int i = ((x.g(&x)), 3);
a suitable diagnostic is emitted.


-- 
           Summary: Failure to define friend functions for all template
                    instatiations
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: amylaar at gcc dot gnu dot org


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

Reply via email to