]> granicus.if.org Git - clang/commitdiff
Fix assertion failure when deducing an auto-typed argument against a different-width...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 25 Dec 2016 20:21:12 +0000 (20:21 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 25 Dec 2016 20:21:12 +0000 (20:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290522 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateDeduction.cpp
test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

index 5c98ebf39ab7d1fc23d1fffae393b5e02f147712..73772a5910935ce95422ac4a9fe74103f6c05c7d 100644 (file)
@@ -2037,7 +2037,7 @@ static bool isSameTemplateArg(ASTContext &Context,
                     Y.getAsTemplateOrTemplatePattern()).getAsVoidPointer();
 
     case TemplateArgument::Integral:
-      return X.getAsIntegral() == Y.getAsIntegral();
+      return hasSameExtendedValue(X.getAsIntegral(), Y.getAsIntegral());
 
     case TemplateArgument::Expression: {
       llvm::FoldingSetNodeID XID, YID;
index 265ea41c3fb4c720adcd638b456f07d539ed889b..abfb0f2836ede2a72b3f61697e82fe6a2c172944 100644 (file)
@@ -250,6 +250,23 @@ namespace Auto {
   }
 
   namespace Decomposition {
+    // Types of deduced non-type template arguments must match exactly, so
+    // partial ordering fails in both directions here.
+    template<auto> struct Any;
+    template<int N> struct Any<N> { typedef int Int; }; // expected-note 3{{match}}
+    template<short N> struct Any<N> { typedef int Short; }; // expected-note 3{{match}}
+    Any<0>::Int is_int; // expected-error {{ambiguous}}
+    Any<(short)0>::Short is_short; // expected-error {{ambiguous}}
+    Any<(char)0>::Short is_char; // expected-error {{ambiguous}}
+
+    template<int, auto> struct NestedAny;
+    template<auto N> struct NestedAny<0, N>; // expected-note 3{{match}}
+    template<int N> struct NestedAny<0, N> { typedef int Int; }; // expected-note 3{{match}}
+    template<short N> struct NestedAny<0, N> { typedef int Short; }; // expected-note 3{{match}}
+    NestedAny<0, 0>::Int nested_int; // expected-error {{ambiguous}}
+    NestedAny<0, (short)0>::Short nested_short; // expected-error {{ambiguous}}
+    NestedAny<0, (char)0>::Short nested_char; // expected-error {{ambiguous}}
+
     double foo(int, bool);
     template<auto& f> struct fn_result_type;