]> granicus.if.org Git - clang/commitdiff
Slightly improved template argument deduction for use in partial
authorDouglas Gregor <dgregor@apple.com>
Tue, 15 Sep 2009 16:51:42 +0000 (16:51 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 15 Sep 2009 16:51:42 +0000 (16:51 +0000)
ordering, along with another test case for partial ordering of partial
specializations.

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

lib/Sema/SemaTemplateDeduction.cpp
lib/Sema/SemaTemplateInstantiate.cpp
test/CXX/temp/temp.decls/temp.class.spec/temp.class.order/p2.cpp [new file with mode: 0644]

index 28ee7d399f2e9d5c394169c9437b2d9c6ff09f9b..da64b55d82323022ba458cfc42dbd700fa37cfbe 100644 (file)
@@ -151,7 +151,18 @@ DeduceNonTypeTemplateArgument(ASTContext &Context,
     return Sema::TDK_Success;
   }
 
-  // FIXME: Compare the expressions for equality!
+  if (Deduced[NTTP->getIndex()].getKind() == TemplateArgument::Expression) {
+    // Compare the expressions for equality
+    llvm::FoldingSetNodeID ID1, ID2;
+    Deduced[NTTP->getIndex()].getAsExpr()->Profile(ID1, Context, true);
+    Value->Profile(ID2, Context, true);
+    if (ID1 == ID2)
+      return Sema::TDK_Success;
+   
+    // FIXME: Fill in argument mismatch information
+    return Sema::TDK_NonDeducedMismatch;
+  }
+
   return Sema::TDK_Success;
 }
 
index 1cae45e4f8f0ba4dde1807c5ec92c3f95436b32d..87216a072dceac45063443e6ee3d54fe77cc6e36 100644 (file)
@@ -843,6 +843,9 @@ Sema::InstantiateClassTemplateSpecialization(
     return true;
   }
 
+  if (ClassTemplateSpec->isInvalidDecl())
+    return true;
+  
   ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
   CXXRecordDecl *Pattern = 0;
 
diff --git a/test/CXX/temp/temp.decls/temp.class.spec/temp.class.order/p2.cpp b/test/CXX/temp/temp.decls/temp.class.spec/temp.class.order/p2.cpp
new file mode 100644 (file)
index 0000000..b3b7635
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+template<int I, int J, class T> class X { 
+  static const int value = 0;
+};
+
+template<int I, int J> class X<I, J, int> { 
+  static const int value = 1;
+};
+
+template<int I> class X<I, I, int> { 
+  static const int value = 2;
+};
+
+int array0[X<0, 0, float>::value == 0? 1 : -1];
+int array1[X<0, 1, int>::value == 1? 1 : -1];
+int array2[X<0, 0, int>::value == 2? 1 : -1];