]> granicus.if.org Git - clang/commitdiff
Fix an embarrasing memory error. I was apparently very tired when I wrote this
authorJohn McCall <rjmccall@apple.com>
Tue, 13 Apr 2010 22:18:28 +0000 (22:18 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 13 Apr 2010 22:18:28 +0000 (22:18 +0000)
code the first time.

Fixes PR6827.

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

lib/AST/Decl.cpp
test/CXX/temp/temp.decls/temp.friend/p1.cpp

index 965f32da28d722bbc4d72c72a5c7051607266833..d4cc945b1ba083c3f81a24a80e17079634c08e83 100644 (file)
@@ -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,
index 03e51321bb2b3ea99223a391e9a929ae176069f1..41cf3632b16f0d1f8be8b36515af065bdcfaa296 100644 (file)
@@ -251,3 +251,28 @@ namespace test11 {
   template struct Foo::IteratorImpl<int>;
   template struct Foo::IteratorImpl<long>;  
 }
+
+// PR6827
+namespace test12 {
+  template <typename T> class Foo;
+  template <typename T> Foo<T> foo(T* t){ return Foo<T>(t, true); }
+
+  template <typename T> class Foo {
+  public:
+    Foo(T*);
+    friend Foo<T> foo<T>(T*);
+  private:
+    Foo(T*, bool); // expected-note {{declared private here}}
+  };
+
+  // Should work.
+  int globalInt;
+  Foo<int> f = foo(&globalInt);
+
+  // Shouldn't work.
+  long globalLong;
+  template <> Foo<long> foo(long *t) {
+    Foo<int> s(&globalInt, false); // expected-error {{calling a private constructor}}
+    return Foo<long>(t, true);
+  }
+}