From: Richard Trieu Date: Wed, 14 Jun 2017 01:28:00 +0000 (+0000) Subject: [ODRHash] Hash Expr for TemplateArgument::Expression X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d7ff3b5a971c6ab075551baae7287dabd0fab79;p=clang [ODRHash] Hash Expr for TemplateArgument::Expression git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305360 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ODRHash.cpp b/lib/AST/ODRHash.cpp index 0a4898c94d..83355270c5 100644 --- a/lib/AST/ODRHash.cpp +++ b/lib/AST/ODRHash.cpp @@ -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) {} diff --git a/test/Modules/odr_hash.cpp b/test/Modules/odr_hash.cpp index b38a0f8f45..36f2e4bea0 100644 --- a/test/Modules/odr_hash.cpp +++ b/test/Modules/odr_hash.cpp @@ -1018,6 +1018,39 @@ S1 s1; // expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}} // expected-note@second.h:* {{declaration of 'x' does not match}} #endif + +#if defined(FIRST) +template struct U2{}; +struct S2 { + using T = U2<2>; +}; +#elif defined(SECOND) +template struct U2{}; +struct S2 { + using T = U2<(2)>; +}; +#else +S2 s2; +// expected-error@second.h:* {{'TemplateArgument::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U2<(2)>'}} +// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}} +#endif + +#if defined(FIRST) +template struct U3{}; +struct S3 { + using T = U3<2>; +}; +#elif defined(SECOND) +template struct U3{}; +struct S3 { + using T = U3<1 + 1>; +}; +#else +S3 s3; +// expected-error@second.h:* {{'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>'}} +// expected-note@first.h:* {{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