]> granicus.if.org Git - clang/commitdiff
[ODRHash] Hash Expr for TemplateArgument::Expression
authorRichard Trieu <rtrieu@google.com>
Wed, 14 Jun 2017 01:28:00 +0000 (01:28 +0000)
committerRichard Trieu <rtrieu@google.com>
Wed, 14 Jun 2017 01:28:00 +0000 (01:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305360 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ODRHash.cpp
test/Modules/odr_hash.cpp

index 0a4898c94df5b20b51039f4806d6deec26032056..83355270c59a88b465a19844996be564de91b601 100644 (file)
@@ -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) {}
index b38a0f8f45c02cd17bf116f24d53865b1d9e4e49..36f2e4bea00c62d53e6e6def17d12546ff0a90fe 100644 (file)
@@ -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 <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;
+// 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 <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;
+// 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