diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 7811be0e832b..8899b50e27e3 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1804,6 +1804,11 @@ public: /// until it reaches a TypedefType or a non-sugared type. template <> const TypedefType *Type::getAs() const; +/// \brief This will check for a TemplateSpecializationType by removing any +/// existing sugar until it reaches a TemplateSpecializationType or a +/// non-sugared type. +template <> const TemplateSpecializationType *Type::getAs() const; + // We can do canonical leaf types faster, because we don't have to // worry about preserving child type decoration. #define TYPE(Class, Base) diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 529c90603c22..9db41c4b1e95 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -288,18 +288,17 @@ QualType QualType::IgnoreParens(QualType T) { return T; } -/// \brief This will check for a TypedefType by removing any existing sugar -/// until it reaches a TypedefType or a non-sugared type. -template <> const TypedefType *Type::getAs() const { - const Type *Cur = this; - +/// \brief This will check for a T (which should be a Type which can act as +/// sugar, such as a TypedefType) by removing any existing sugar until it +/// reaches a T or a non-sugared type. +template static const T *getAsSugar(const Type *Cur) { while (true) { - if (const TypedefType *TDT = dyn_cast(Cur)) - return TDT; + if (const T *Sugar = dyn_cast(Cur)) + return Sugar; switch (Cur->getTypeClass()) { #define ABSTRACT_TYPE(Class, Parent) #define TYPE(Class, Parent) \ - case Class: { \ + case Type::Class: { \ const Class##Type *Ty = cast(Cur); \ if (!Ty->isSugared()) return 0; \ Cur = Ty->desugar().getTypePtr(); \ @@ -310,6 +309,14 @@ template <> const TypedefType *Type::getAs() const { } } +template <> const TypedefType *Type::getAs() const { + return getAsSugar(this); +} + +template <> const TemplateSpecializationType *Type::getAs() const { + return getAsSugar(this); +} + /// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic /// sugar off the given type. This should produce an object of the /// same dynamic type as the canonical type. diff --git a/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp b/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp index 4cc1f17a11e9..59618d263683 100644 --- a/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp +++ b/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp @@ -95,13 +95,17 @@ template struct drop { }; using T1 = take<3, int, char, double, long>::type; // expected-note {{previous}} -using T1 = types; // expected-error {{'types' vs 'types'}} +// FIXME: Desguar the types on the RHS in this diagnostic. +// desired-error {{'types' vs 'types'}} +using T1 = types; // expected-error {{'types' vs 'types::type, typename inner<_>::type, typename inner<_>::type, (no argument)>'}} using D1 = drop<3, int, char, double, long>::type; using D1 = types; using T2 = take<4, int, char, double, long>::type; // expected-note {{previous}} using T2 = types; -using T2 = types; // expected-error {{'types' vs 'types'}} +// FIXME: Desguar the types on the RHS in this diagnostic. +// desired-error {{'types' vs 'types'}} +using T2 = types; // expected-error {{'types' vs 'types::type, typename inner<_>::type, typename inner<_>::type, typename inner<_>::type>'}} using D2 = drop<4, int, char, double, long>::type; using D2 = types<>; diff --git a/clang/test/Misc/diag-template-diffing.cpp b/clang/test/Misc/diag-template-diffing.cpp index 9addcc50aec6..24563e3ec89b 100644 --- a/clang/test/Misc/diag-template-diffing.cpp +++ b/clang/test/Misc/diag-template-diffing.cpp @@ -426,6 +426,24 @@ void test13() { // CHECK-NOELIDE-TREE: &b13, // CHECK-NOELIDE-TREE: [&d13 != (no argument)]> +template struct s14 {}; +template using a14 = s14; +typedef a14 b14; +template using c14 = b14; +int f14(c14); +int k14 = f14(a14()); +// CHECK-ELIDE-NOTREE: no matching function for call to 'f14' +// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'a14' to 'a14' for 1st argument +// CHECK-NOELIDE-NOTREE: no matching function for call to 'f14' +// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'a14' to 'a14' for 1st argument +// CHECK-ELIDE-TREE: no matching function for call to 'f14' +// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument +// CHECK-ELIDE-TREE: a14< +// CHECK-ELIDE-TREE: [char != int]> +// CHECK-NOELIDE-TREE: no matching function for call to 'f14' +// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument +// CHECK-NOELIDE-TREE: a14< +// CHECK-NOELIDE-TREE: [char != int]> // CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated.