r234374 - Use the most recent previous decl to check if inline is added after a definition
Reid Kleckner
reid at kleckner.net
Tue Apr 7 17:04:48 PDT 2015
Author: rnk
Date: Tue Apr 7 19:04:47 2015
New Revision: 234374
URL: http://llvm.org/viewvc/llvm-project?rev=234374&view=rev
Log:
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
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaTemplate/friend.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=234374&r1=234373&r2=234374&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Apr 7 19:04:47 2015
@@ -615,7 +615,8 @@ bool Sema::MergeCXXFunctionDecl(Function
<< New << New->isConstexpr();
Diag(Old->getLocation(), diag::note_previous_declaration);
Invalid = true;
- } else if (!Old->isInlined() && New->isInlined() && Old->isDefined(Def)) {
+ } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
+ Old->isDefined(Def)) {
// C++11 [dcl.fcn.spec]p4:
// If the definition of a function appears in a translation unit before its
// first declaration as inline, the program is ill-formed.
Modified: cfe/trunk/test/SemaTemplate/friend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/friend.cpp?rev=234374&r1=234373&r2=234374&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/friend.cpp (original)
+++ cfe/trunk/test/SemaTemplate/friend.cpp Tue Apr 7 19:04:47 2015
@@ -31,3 +31,19 @@ namespace PR6770 {
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;
+}
More information about the cfe-commits
mailing list