From: Douglas Gregor Date: Mon, 28 Sep 2009 18:41:37 +0000 (+0000) Subject: Make sure that out-of-line function and variable definitions are not X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d04b1be7d3015a307f93eea0b9ab0ecce612951e;p=clang Make sure that out-of-line function and variable definitions are not pushed into scope. Fixes PR5056. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83003 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index d0463c658e..7f3f24efea 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -288,14 +288,22 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) { ((DeclContext *)S->getEntity())->isTransparentContext()) S = S->getParent(); - S->AddDecl(DeclPtrTy::make(D)); - // Add scoped declarations into their context, so that they can be // found later. Declarations without a context won't be inserted // into any context. if (AddToContext) CurContext->addDecl(D); + // Out-of-line function and variable definitions should not be pushed into + // scope. + if ((isa(D) && + cast(D)->getTemplatedDecl()->isOutOfLine()) || + (isa(D) && cast(D)->isOutOfLine()) || + (isa(D) && cast(D)->isOutOfLine())) + return; + + S->AddDecl(DeclPtrTy::make(D)); + // C++ [basic.scope]p4: // -- exactly one declaration shall declare a class name or // enumeration name that is not a typedef name and the other diff --git a/test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp b/test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp new file mode 100644 index 0000000000..602fd374c2 --- /dev/null +++ b/test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp @@ -0,0 +1,17 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +extern "C" void * malloc(int); + +template struct A { + void *malloc(int); +}; + +template +inline void *A::malloc(int) +{ + return 0; +} + +void f() { + malloc(10); +}