forked from OSchip/llvm-project
[clang][SemaTemplate] Fix a stack use after scope
Differential Revision: https://reviews.llvm.org/D120065
This commit is contained in:
parent
3773d04a13
commit
c79c13cae6
|
@ -2461,10 +2461,10 @@ private:
|
||||||
SourceLocation FriendLoc;
|
SourceLocation FriendLoc;
|
||||||
|
|
||||||
FriendTemplateDecl(DeclContext *DC, SourceLocation Loc,
|
FriendTemplateDecl(DeclContext *DC, SourceLocation Loc,
|
||||||
MutableArrayRef<TemplateParameterList *> Params,
|
TemplateParameterList **Params, unsigned NumParams,
|
||||||
FriendUnion Friend, SourceLocation FriendLoc)
|
FriendUnion Friend, SourceLocation FriendLoc)
|
||||||
: Decl(Decl::FriendTemplate, DC, Loc), NumParams(Params.size()),
|
: Decl(Decl::FriendTemplate, DC, Loc), NumParams(NumParams),
|
||||||
Params(Params.data()), Friend(Friend), FriendLoc(FriendLoc) {}
|
Params(Params), Friend(Friend), FriendLoc(FriendLoc) {}
|
||||||
|
|
||||||
FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
|
FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "llvm/ADT/FoldingSet.h"
|
#include "llvm/ADT/FoldingSet.h"
|
||||||
#include "llvm/ADT/None.h"
|
#include "llvm/ADT/None.h"
|
||||||
#include "llvm/ADT/PointerUnion.h"
|
#include "llvm/ADT/PointerUnion.h"
|
||||||
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/Support/Casting.h"
|
#include "llvm/Support/Casting.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
|
@ -1098,7 +1099,13 @@ FriendTemplateDecl::Create(ASTContext &Context, DeclContext *DC,
|
||||||
SourceLocation L,
|
SourceLocation L,
|
||||||
MutableArrayRef<TemplateParameterList *> Params,
|
MutableArrayRef<TemplateParameterList *> Params,
|
||||||
FriendUnion Friend, SourceLocation FLoc) {
|
FriendUnion Friend, SourceLocation FLoc) {
|
||||||
return new (Context, DC) FriendTemplateDecl(DC, L, Params, Friend, FLoc);
|
TemplateParameterList **TPL = nullptr;
|
||||||
|
if (!Params.empty()) {
|
||||||
|
TPL = new (Context) TemplateParameterList *[Params.size()];
|
||||||
|
llvm::copy(Params, TPL);
|
||||||
|
}
|
||||||
|
return new (Context, DC)
|
||||||
|
FriendTemplateDecl(DC, L, TPL, Params.size(), Friend, FLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C,
|
FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C,
|
||||||
|
|
|
@ -329,3 +329,12 @@ namespace rdar12350696 {
|
||||||
foo(b); // expected-note {{in instantiation}}
|
foo(b); // expected-note {{in instantiation}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace StackUseAfterScope {
|
||||||
|
template <typename T> class Bar {};
|
||||||
|
class Foo {
|
||||||
|
// Make sure this doesn't crash.
|
||||||
|
template <> friend class Bar<int>; // expected-error {{template specialization declaration cannot be a friend}}
|
||||||
|
bool aux;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue