]> granicus.if.org Git - clang/commitdiff
Fixes for a couple of things:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 14 Jul 2009 03:18:53 +0000 (03:18 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 14 Jul 2009 03:18:53 +0000 (03:18 +0000)
- Declaration context of ParmVarDecls (that we got from the Declarator) was not their containing function.
- C++ out-of-line method definitions didn't get an access specifier.

Both were exposed by a crash when emitting a C++ method to a PCH file (assert at Decl::CheckAccessDeclContext()).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75597 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/PCH/cxx-method.cpp [new file with mode: 0644]

index 3ce11570feb04dc4c02ab7d809cb9683d1ac5d2f..c1dcdd6ec030555ba85b9267853c78f4605b77da 100644 (file)
@@ -2298,8 +2298,12 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
         Diag(Param->getLocation(), diag::err_param_typedef_of_void);
       // FIXME: Leaks decl?
     } else if (FTI.NumArgs > 0 && FTI.ArgInfo[0].Param != 0) {
-      for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
-        Params.push_back(FTI.ArgInfo[i].Param.getAs<ParmVarDecl>());
+      for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
+        ParmVarDecl *Param = FTI.ArgInfo[i].Param.getAs<ParmVarDecl>();
+        assert(Param->getDeclContext() != NewFD && "Was set before ?");
+        Param->setDeclContext(NewFD);
+        Params.push_back(Param);
+      }
     }
   
   } else if (const FunctionProtoType *FT = R->getAsFunctionProtoType()) {
@@ -2546,8 +2550,11 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl,
       if (FunctionTemplateDecl *OldTemplateDecl
             = dyn_cast<FunctionTemplateDecl>(OldDecl))
         NewFD->setPreviousDeclaration(OldTemplateDecl->getTemplatedDecl());
-      else
+      else {
+        if (isa<CXXMethodDecl>(NewFD)) // Set access for out-of-line definitions
+          NewFD->setAccess(OldDecl->getAccess());
         NewFD->setPreviousDeclaration(cast<FunctionDecl>(OldDecl));
+      }
     }
   }
 
diff --git a/test/PCH/cxx-method.cpp b/test/PCH/cxx-method.cpp
new file mode 100644 (file)
index 0000000..144406e
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang-cc -emit-pch %s -o %t
+
+struct S {
+  void m(int x);
+};
+
+void S::m(int x) { }