[cfe-commits] r83003 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp

Douglas Gregor dgregor at apple.com
Mon Sep 28 11:41:38 PDT 2009


Author: dgregor
Date: Mon Sep 28 13:41:37 2009
New Revision: 83003

URL: http://llvm.org/viewvc/llvm-project?rev=83003&view=rev
Log:
Make sure that out-of-line function and variable definitions are not
pushed into scope. Fixes PR5056.

Added:
    cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=83003&r1=83002&r2=83003&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep 28 13:41:37 2009
@@ -288,14 +288,22 @@
          ((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<FunctionTemplateDecl>(D) &&
+       cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->isOutOfLine()) ||
+      (isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isOutOfLine()) ||
+      (isa<VarDecl>(D) && cast<VarDecl>(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

Added: cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp?rev=83003&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/pr5056.cpp Mon Sep 28 13:41:37 2009
@@ -0,0 +1,17 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+extern "C" void * malloc(int);
+
+template <typename T> struct A {
+  void *malloc(int);
+};
+
+template <typename T>
+inline void *A<T>::malloc(int)
+{
+  return 0;
+}
+
+void f() {
+  malloc(10);
+}





More information about the cfe-commits mailing list