From: John McCall Date: Tue, 13 Apr 2010 22:18:28 +0000 (+0000) Subject: Fix an embarrasing memory error. I was apparently very tired when I wrote this X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21c0160959961b3a6ab3308608ee3fde182ecb49;p=clang Fix an embarrasing memory error. I was apparently very tired when I wrote this code the first time. Fixes PR6827. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101184 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 965f32da28..d4cc945b1b 100644 --- a/lib/AST/Decl.cpp +++ b/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/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/test/CXX/temp/temp.decls/temp.friend/p1.cpp index 03e51321bb..41cf3632b1 100644 --- a/test/CXX/temp/temp.decls/temp.friend/p1.cpp +++ b/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); + } +}