From 900d980cd881f40da142ae12c9f4317217f4dad2 Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 13 Apr 2010 22:18:28 +0000 Subject: [PATCH] Fix an embarrasing memory error. I was apparently very tired when I wrote this code the first time. Fixes PR6827. llvm-svn: 101184 --- clang/lib/AST/Decl.cpp | 2 +- .../CXX/temp/temp.decls/temp.friend/p1.cpp | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 965f32da28d7..d4cc945b1ba0 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1316,7 +1316,7 @@ FunctionDecl::setDependentTemplateSpecialization(ASTContext &Context, assert(TemplateOrSpecialization.isNull()); size_t Size = sizeof(DependentFunctionTemplateSpecializationInfo); Size += Templates.size() * sizeof(FunctionTemplateDecl*); - Size += TemplateArgs.size(); + Size += TemplateArgs.size() * sizeof(TemplateArgumentLoc); void *Buffer = Context.Allocate(Size); DependentFunctionTemplateSpecializationInfo *Info = new (Buffer) DependentFunctionTemplateSpecializationInfo(Templates, diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp index 03e51321bb2b..41cf3632b16f 100644 --- a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp @@ -251,3 +251,28 @@ namespace test11 { template struct Foo::IteratorImpl; template struct Foo::IteratorImpl; } + +// PR6827 +namespace test12 { + template class Foo; + template Foo foo(T* t){ return Foo(t, true); } + + template class Foo { + public: + Foo(T*); + friend Foo foo(T*); + private: + Foo(T*, bool); // expected-note {{declared private here}} + }; + + // Should work. + int globalInt; + Foo f = foo(&globalInt); + + // Shouldn't work. + long globalLong; + template <> Foo foo(long *t) { + Foo s(&globalInt, false); // expected-error {{calling a private constructor}} + return Foo(t, true); + } +}