Skip to content

Commit

Permalink
[ODRHash] Hash Expr for TemplateArgument::Expression
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305360 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Weverything committed Jun 14, 2017
1 parent 4249ebf commit 5d7ff3b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/AST/ODRHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ void ODRHash::AddTemplateName(TemplateName Name) {
void ODRHash::AddTemplateArgument(TemplateArgument TA) {
const auto Kind = TA.getKind();
ID.AddInteger(Kind);

switch (Kind) {
case TemplateArgument::Null:
case TemplateArgument::Type:
case TemplateArgument::Declaration:
case TemplateArgument::NullPtr:
case TemplateArgument::Integral:
case TemplateArgument::Template:
case TemplateArgument::TemplateExpansion:
break;
case TemplateArgument::Expression:
AddStmt(TA.getAsExpr());
break;
case TemplateArgument::Pack:
break;
}
}

void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {}
Expand Down
33 changes: 33 additions & 0 deletions test/Modules/odr_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,39 @@ S1 s1;
// [email protected]:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}}
// [email protected]:* {{declaration of 'x' does not match}}
#endif

#if defined(FIRST)
template <int> struct U2{};
struct S2 {
using T = U2<2>;
};
#elif defined(SECOND)
template <int> struct U2{};
struct S2 {
using T = U2<(2)>;
};
#else
S2 s2;
// [email protected]:* {{'TemplateArgument::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U2<(2)>'}}
// [email protected]:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}}
#endif

#if defined(FIRST)
template <int> struct U3{};
struct S3 {
using T = U3<2>;
};
#elif defined(SECOND)
template <int> struct U3{};
struct S3 {
using T = U3<1 + 1>;
};
#else
S3 s3;
// [email protected]:* {{'TemplateArgument::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U3<1 + 1>'}}
// [email protected]:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}}
#endif

}

// Interesting cases that should not cause errors. struct S should not error
Expand Down

0 comments on commit 5d7ff3b

Please sign in to comment.