r186757 - If a default argument is a dependent type, get the real type from the desugared
Richard Trieu
rtrieu at google.com
Fri Jul 19 20:49:02 PDT 2013
Author: rtrieu
Date: Fri Jul 19 22:49:02 2013
New Revision: 186757
URL: http://llvm.org/viewvc/llvm-project?rev=186757&view=rev
Log:
If a default argument is a dependent type, get the real type from the desugared
template. Passing around dependent types can lead to integral arguments that
cannot be evaluated.
Modified:
cfe/trunk/lib/AST/ASTDiagnostic.cpp
cfe/trunk/test/Misc/diag-template-diffing.cpp
Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=186757&r1=186756&r2=186757&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDiagnostic.cpp (original)
+++ cfe/trunk/lib/AST/ASTDiagnostic.cpp Fri Jul 19 22:49:02 2013
@@ -1054,10 +1054,14 @@ class TemplateDiff {
if (!Iter.isEnd())
return Iter->getAsType();
- if (!isVariadic)
- return DefaultTTPD->getDefaultArgument();
+ if (isVariadic)
+ return QualType();
- return QualType();
+ QualType ArgType = DefaultTTPD->getDefaultArgument();
+ if (ArgType->isDependentType())
+ return Iter.getDesugar().getAsType();
+
+ return ArgType;
}
/// GetExpr - Retrieves the template expression argument, including default
Modified: cfe/trunk/test/Misc/diag-template-diffing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-template-diffing.cpp?rev=186757&r1=186756&r2=186757&view=diff
==============================================================================
--- cfe/trunk/test/Misc/diag-template-diffing.cpp (original)
+++ cfe/trunk/test/Misc/diag-template-diffing.cpp Fri Jul 19 22:49:02 2013
@@ -935,10 +935,10 @@ namespace DependentDefault {
B<int, char> b3;
b1 = b2;
// CHECK-ELIDE-NOTREE: no viable overloaded '='
- // CHECK-ELIDE-NOTREE: no known conversion from 'B<char, (default) Trait<T>::Ty>' to 'B<int, int>'
+ // CHECK-ELIDE-NOTREE: no known conversion from 'B<char, [...]>' to 'B<int, [...]>'
b3 = b1;
// CHECK-ELIDE-NOTREE: no viable overloaded '='
- // CHECK-ELIDE-NOTREE: no known conversion from 'B<[...], (default) Trait<T>::Ty>' to 'B<[...], char>'
+ // CHECK-ELIDE-NOTREE: no known conversion from 'B<[...], (default) int>' to 'B<[...], char>'
b2 = b3;
// CHECK-ELIDE-NOTREE: no viable overloaded '='
// CHECK-ELIDE-NOTREE: no known conversion from 'B<int, char>' to 'B<char, int>'
@@ -1029,6 +1029,28 @@ namespace PointerArguments {
}
}
+namespace DependentInt {
+ template<int Num> struct INT;
+
+ template <class CLASS, class Int_wrapper = INT<CLASS::val> >
+ struct C;
+
+ struct N {
+ static const int val = 1;
+ };
+
+ template <class M_T>
+ struct M {};
+
+ void test() {
+ using T1 = M<C<int, INT<0>>>;
+ using T2 = M<C<N>>;
+ T2 p;
+ T1 x = p;
+ // CHECK-ELIDE-NOTREE: no viable conversion from 'M<C<struct DependentInt::N, INT<1>>>' to 'M<C<int, INT<0>>>'
+ }
+}
+
// CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated.
// CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated.
// CHECK-ELIDE-TREE: {{[0-9]*}} errors generated.
More information about the cfe-commits
mailing list