Reid Kleckner 9386417047 Use the most recent previous decl to check if inline is added after a definition
This affects this test case:
  void foo();
  template <typename T> class C {
    friend inline void foo();
  };
  inline void foo() {}
  C<int> c;

Here, we instantiate the foo friend decl and add it to foo's redecl
chain. However, our previous decl pointer happens to reference the first
declaration of foo, which is not marked inline. When we check to see if
foo was already defined, we implicitly search all previous decls. We
should do the same for the inline check, instead of just checking this
particular previous decl.

Reviewers: rsmith

Differential Revision: http://reviews.llvm.org/D8872

llvm-svn: 234374
2015-04-08 00:04:47 +00:00

50 lines
914 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T> struct A {
struct B { };
friend struct B;
};
void f() {
A<int>::B b;
}
struct C0 {
friend struct A<int>;
};
namespace PR6770 {
namespace N {
int f1(int);
}
using namespace N;
namespace M {
float f1(float);
}
using M::f1;
template<typename T> void f1(T, T);
template <class T>
void f() {
friend class f; // expected-error{{'friend' used outside of class}}
friend class f1; // expected-error{{'friend' used outside of class}}
}
}
namespace friend_redecl_inline {
// We had a bug where instantiating the foo friend declaration would check the
// defined-ness of the most recent decl while checking if the canonical decl was
// inlined.
void foo();
void bar();
template <typename T>
class C {
friend void foo();
friend inline void bar();
};
inline void foo() {}
inline void bar() {}
C<int> c;
}