]> granicus.if.org Git - clang/commitdiff
[ODRHash] Add support for TemplateArgument types.
authorRichard Trieu <rtrieu@google.com>
Fri, 9 Jun 2017 21:00:10 +0000 (21:00 +0000)
committerRichard Trieu <rtrieu@google.com>
Fri, 9 Jun 2017 21:00:10 +0000 (21:00 +0000)
Recommit r304592 that was reverted in r304618.  r305104 should have fixed the
issue.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305110 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 08593da89bbd8236a33785c4e01b16c5cde0f22a..b260bad9d378e287206ecc55d3a3bbb7ef4c237a 100644 (file)
@@ -140,7 +140,25 @@ void ODRHash::AddTemplateName(TemplateName Name) {
   }
 }
 
-void ODRHash::AddTemplateArgument(TemplateArgument TA) {}
+void ODRHash::AddTemplateArgument(TemplateArgument TA) {
+  auto Kind = TA.getKind();
+  ID.AddInteger(Kind);
+
+  switch (Kind) {
+  case TemplateArgument::Null:
+  case TemplateArgument::Declaration:
+  case TemplateArgument::NullPtr:
+  case TemplateArgument::Integral:
+  case TemplateArgument::Template:
+  case TemplateArgument::TemplateExpansion:
+  case TemplateArgument::Expression:
+  case TemplateArgument::Pack:
+    break;
+  case TemplateArgument::Type:
+    AddQualType(TA.getAsType());
+    break;
+  }
+}
 void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {}
 
 void ODRHash::clear() {
index a6a0b74743aaa315fa03c8cc8df3502abb7e3dac..fb7005be259527331b46af3e50320a4fc7e28fd2 100644 (file)
@@ -900,6 +900,24 @@ S2 s2;
 #endif
 }
 
+namespace TemplateArgument {
+#if defined(FIRST)
+template<typename> struct U1 {};
+struct S1 {
+  U1<int> u;
+};
+#elif defined(SECOND)
+template<typename> struct U1 {};
+struct S1 {
+  U1<double> u;
+};
+#else
+S1 s1;
+// expected-error@first.h:* {{'TemplateArgument::S1::u' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'u' does not match}}
+#endif
+}
+
 // Interesting cases that should not cause errors.  struct S should not error
 // while struct T should error at the access specifier mismatch at the end.
 namespace AllDecls {