From 8e8d2bb6ec0311aab3ab5f989f36868e12c968ed Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Thu, 15 Jun 2017 01:35:06 +0000 Subject: [PATCH] [ODRHash] Hash TemplateArgument::Pack and TemplateTypeParmType git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305440 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ODRHash.cpp | 11 +++++++++++ test/Modules/odr_hash.cpp | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/AST/ODRHash.cpp b/lib/AST/ODRHash.cpp index f037827da834..3bf9896985e1 100644 --- a/lib/AST/ODRHash.cpp +++ b/lib/AST/ODRHash.cpp @@ -159,6 +159,10 @@ void ODRHash::AddTemplateArgument(TemplateArgument TA) { AddStmt(TA.getAsExpr()); break; case TemplateArgument::Pack: + ID.AddInteger(TA.pack_size()); + for (auto SubTA : TA.pack_elements()) { + AddTemplateArgument(SubTA); + } break; } } @@ -549,6 +553,13 @@ class ODRTypeVisitor : public TypeVisitor { Hash.AddTemplateName(T->getTemplateName()); VisitType(T); } + + void VisitTemplateTypeParmType(const TemplateTypeParmType *T) { + ID.AddInteger(T->getDepth()); + ID.AddInteger(T->getIndex()); + Hash.AddBoolean(T->isParameterPack()); + AddDecl(T->getDecl()); + } }; void ODRHash::AddType(const Type *T) { diff --git a/test/Modules/odr_hash.cpp b/test/Modules/odr_hash.cpp index 51bd62697246..28b05a535644 100644 --- a/test/Modules/odr_hash.cpp +++ b/test/Modules/odr_hash.cpp @@ -1068,7 +1068,48 @@ S4 s4; // expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}} // expected-note@second.h:* {{declaration of 'x' does not match}} #endif +} +namespace TemplateTypeParmType { +#if defined(FIRST) +template +struct S1 { + T1 x; +}; +#elif defined(SECOND) +template +struct S1 { + T2 x; +}; +#else +using TemplateTypeParmType::S1; +// expected-error@first.h:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'x' does not match}} +#endif + +#if defined(FIRST) +template +struct U2 {}; +template +class S2 { + typedef U2 type; + type x; +}; +#elif defined(SECOND) +template +struct U2 {}; +template +class S2 { + typedef U2 type; + type x; +}; +#else +using TemplateTypeParmType::S2; +// expected-error@first.h:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'x' does not match}} +// expected-error@first.h:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'type' does not match}} +#endif } // Interesting cases that should not cause errors. struct S should not error