view gcc/testsuite/g++.old-deja/g++.other/friend4.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

// { dg-do assemble  }

// by Alexandre Oliva <oliva@dcc.unicamp.br>

// I'm not 100% sure this program is correct, but g++ shouldn't just
// crash.

// The idea is to give privileged access to bar<A> only to
// specializations foo<A,B>, for all B.

template <class A, class B> void foo();
template <class C> class bar {
  int i; // { dg-message "" } private
  template <class B> friend void foo<C,B>(); // { dg-error "34:invalid use of template-id" }
};
template <class A, class B> void foo() {
  bar<A> baz; baz.i = 1;   // { dg-error "" } foo cannot access bar<int>::i
  bar<int> buz; buz.i = 1; // { dg-error "" } foo cannot access bar<int>::i
}
int main() {
  foo<void,void>();
  foo<int,void>();
}