/// arguments or the type arguments that are templates.
TemplateDecl *FromTD, *ToTD;
+ /// FromQual, ToQual - Qualifiers for template types.
+ Qualifiers FromQual, ToQual;
+
/// FromDefault, ToDefault - Whether the argument is a default argument.
bool FromDefault, ToDefault;
FlatTree[CurrentNode].ToExpr = ToExpr;
}
+ /// SetNode - Set FromQual and ToQual of the current node.
+ void SetNode(Qualifiers FromQual, Qualifiers ToQual) {
+ FlatTree[CurrentNode].FromQual = FromQual;
+ FlatTree[CurrentNode].ToQual = ToQual;
+ }
+
/// SetSame - Sets the same flag of the current node.
void SetSame(bool Same) {
FlatTree[CurrentNode].Same = Same;
ToTD = FlatTree[ReadNode].ToTD;
}
+ /// GetNode - Gets the FromQual and ToQual.
+ void GetNode(Qualifiers &FromQual, Qualifiers &ToQual) {
+ FromQual = FlatTree[ReadNode].FromQual;
+ ToQual = FlatTree[ReadNode].ToQual;
+ }
+
/// NodeIsSame - Returns true the arguments are the same.
bool NodeIsSame() {
return FlatTree[ReadNode].Same;
if (Context.hasSameType(FromType, ToType)) {
Tree.SetSame(true);
} else {
+ Qualifiers FromQual = FromType.getQualifiers(),
+ ToQual = ToType.getQualifiers();
const TemplateSpecializationType *FromArgTST =
GetTemplateSpecializationType(Context, FromType);
const TemplateSpecializationType *ToArgTST =
if (FromArgTST && ToArgTST &&
hasSameTemplate(FromArgTST, ToArgTST)) {
+ FromQual -= QualType(FromArgTST, 0).getQualifiers();
+ ToQual -= QualType(ToArgTST, 0).getQualifiers();
Tree.SetNode(FromArgTST->getTemplateName().getAsTemplateDecl(),
ToArgTST->getTemplateName().getAsTemplateDecl());
+ Tree.SetNode(FromQual, ToQual);
DiffTemplate(FromArgTST, ToArgTST);
}
}
assert(Tree.HasChildren() && "Template difference not found in diff tree.");
+ Qualifiers FromQual, ToQual;
+ Tree.GetNode(FromQual, ToQual);
+ PrintQualifiers(FromQual, ToQual);
+
OS << FromTD->getNameAsString() << '<';
Tree.MoveToChild();
unsigned NumElideArgs = 0;
return;
}
+ if (!FromType.isNull() && !ToType.isNull() &&
+ FromType.getLocalUnqualifiedType() ==
+ ToType.getLocalUnqualifiedType()) {
+ Qualifiers FromQual = FromType.getLocalQualifiers(),
+ ToQual = ToType.getLocalQualifiers(),
+ CommonQual;
+ PrintQualifiers(FromQual, ToQual);
+ FromType.getLocalUnqualifiedType().print(OS, Policy);
+ return;
+ }
+
std::string FromTypeStr = FromType.isNull() ? "(no argument)"
: FromType.getAsString();
std::string ToTypeStr = ToType.isNull() ? "(no argument)"
OS << "[" << NumElideArgs << " * ...]";
}
+ // Prints and highlights differences in Qualifiers.
+ void PrintQualifiers(Qualifiers FromQual, Qualifiers ToQual) {
+ // Both types have no qualifiers
+ if (FromQual.empty() && ToQual.empty())
+ return;
+
+ // Both types have same qualifiers
+ if (FromQual == ToQual) {
+ PrintQualifier(FromQual, /*ApplyBold*/false);
+ return;
+ }
+
+ // Find common qualifiers and strip them from FromQual and ToQual.
+ Qualifiers CommonQual = Qualifiers::removeCommonQualifiers(FromQual,
+ ToQual);
+
+ // The qualifiers are printed before the template name.
+ // Inline printing:
+ // The common qualifiers are printed. Then, qualifiers only in this type
+ // are printed and highlighted. Finally, qualifiers only in the other
+ // type are printed and highlighted inside parentheses after "missing".
+ // Tree printing:
+ // Qualifiers are printed next to each other, inside brackets, and
+ // separated by "!=". The printing order is:
+ // common qualifiers, highlighted from qualifiers, "!=",
+ // common qualifiers, highlighted to qualifiers
+ if (PrintTree) {
+ OS << "[";
+ if (CommonQual.empty() && FromQual.empty()) {
+ Bold();
+ OS << "(no qualifiers) ";
+ Unbold();
+ } else {
+ PrintQualifier(CommonQual, /*ApplyBold*/false);
+ PrintQualifier(FromQual, /*ApplyBold*/true);
+ }
+ OS << "!= ";
+ if (CommonQual.empty() && ToQual.empty()) {
+ Bold();
+ OS << "(no qualifiers)";
+ Unbold();
+ } else {
+ PrintQualifier(CommonQual, /*ApplyBold*/false,
+ /*appendSpaceIfNonEmpty*/!ToQual.empty());
+ PrintQualifier(ToQual, /*ApplyBold*/true,
+ /*appendSpaceIfNonEmpty*/false);
+ }
+ OS << "] ";
+ } else {
+ PrintQualifier(CommonQual, /*ApplyBold*/false);
+ PrintQualifier(FromQual, /*ApplyBold*/true);
+ }
+ }
+
+ void PrintQualifier(Qualifiers Q, bool ApplyBold,
+ bool AppendSpaceIfNonEmpty = true) {
+ if (Q.empty()) return;
+ if (ApplyBold) Bold();
+ Q.print(OS, Policy, AppendSpaceIfNonEmpty);
+ if (ApplyBold) Unbold();
+ }
+
public:
TemplateDiff(ASTContext &Context, QualType FromType, QualType ToType,
/// DiffTemplate - Start the template type diffing.
void DiffTemplate() {
+ Qualifiers FromQual = FromType.getQualifiers(),
+ ToQual = ToType.getQualifiers();
+
const TemplateSpecializationType *FromOrigTST =
GetTemplateSpecializationType(Context, FromType);
const TemplateSpecializationType *ToOrigTST =
return;
}
+ FromQual -= QualType(FromOrigTST, 0).getQualifiers();
+ ToQual -= QualType(ToOrigTST, 0).getQualifiers();
Tree.SetNode(FromType, ToType);
+ Tree.SetNode(FromQual, ToQual);
// Same base template, but different arguments.
Tree.SetNode(FromOrigTST->getTemplateName().getAsTemplateDecl(),
// CHECK-NOELIDE-TREE: a14<
// CHECK-NOELIDE-TREE: [char != int]>
+void set15(vector<vector<int>>) {}
+void test15() {
+ set15(vector<vector<int>>());
+}
+// CHECK-ELIDE-NOTREE-NOT: set15
+// CHECK-NOELIDE-NOTREE-NOT: set15
+// CHECK-ELIDE-TREE-NOT: set15
+// CHECK-NOELIDE-TREE-NOT: set15
+// no error here
+
+void set16(vector<const vector<int>>) {}
+void test16() {
+ set16(vector<const vector<const int>>());
+}
+// CHECK-ELIDE-NOTREE: no matching function for call to 'set16'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<const vector<const int>>' to 'vector<const vector<int>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'set16'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<const vector<const int>>' to 'vector<const vector<int>>' for 1st argument
+// CHECK-ELIDE-TREE: no matching function for call to 'set16'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: vector<
+// CHECK-ELIDE-TREE: const vector<
+// CHECK-ELIDE-TREE: [const != (no qualifiers)] int>>
+// CHECK-NOELIDE-TREE: no matching function for call to 'set16'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: vector<
+// CHECK-NOELIDE-TREE: const vector<
+// CHECK-NOELIDE-TREE: [const != (no qualifiers)] int>>
+
+void set17(vector<vector<int>>) {}
+void test17() {
+ set17(vector<const vector<int>>());
+}
+// CHECK-ELIDE-NOTREE: no matching function for call to 'set17'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<const vector<[...]>>' to 'vector<vector<[...]>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'set17'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<const vector<int>>' to 'vector<vector<int>>' for 1st argument
+// CHECK-ELIDE-TREE: no matching function for call to 'set17'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: vector<
+// CHECK-ELIDE-TREE: [const != (no qualifiers)] vector<
+// CHECK-ELIDE-TREE: [...]>>
+// CHECK-NOELIDE-TREE: no matching function for call to 'set17'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: vector<
+// CHECK-NOELIDE-TREE: [const != (no qualifiers)] vector<
+// CHECK-NOELIDE-TREE: int>>
+
+void set18(vector<const vector<int>>) {}
+void test18() {
+ set18(vector<vector<int>>());
+}
+// CHECK-ELIDE-NOTREE: no matching function for call to 'set18'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<vector<[...]>>' to 'vector<const vector<[...]>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'set18'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<vector<int>>' to 'vector<const vector<int>>' for 1st argument
+// CHECK-ELIDE-TREE: no matching function for call to 'set18'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: vector<
+// CHECK-ELIDE-TREE: [(no qualifiers) != const] vector<
+// CHECK-ELIDE-TREE: [...]>>
+// CHECK-NOELIDE-TREE: no matching function for call to 'set18'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: vector<
+// CHECK-NOELIDE-TREE: [(no qualifiers) != const] vector<
+// CHECK-NOELIDE-TREE: int>>
+
+void set19(vector<volatile vector<int>>) {}
+void test19() {
+ set19(vector<const vector<int>>());
+}
+// CHECK-ELIDE-NOTREE: no matching function for call to 'set19'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<const vector<[...]>>' to 'vector<volatile vector<[...]>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'set19'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<const vector<int>>' to 'vector<volatile vector<int>>' for 1st argument
+// CHECK-ELIDE-TREE: no matching function for call to 'set19'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: vector<
+// CHECK-ELIDE-TREE: [const != volatile] vector<
+// CHECK-ELIDE-TREE: [...]>>
+// CHECK-NOELIDE-TREE: no matching function for call to 'set19'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: vector<
+// CHECK-NOELIDE-TREE: [const != volatile] vector<
+// CHECK-NOELIDE-TREE: int>>
+
+void set20(vector<const volatile vector<int>>) {}
+void test20() {
+ set20(vector<const vector<int>>());
+}
+// CHECK-ELIDE-NOTREE: no matching function for call to 'set20'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<const vector<[...]>>' to 'vector<const volatile vector<[...]>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'set20'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<const vector<int>>' to 'vector<const volatile vector<int>>' for 1st argument
+// CHECK-ELIDE-TREE: no matching function for call to 'set20'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: vector<
+// CHECK-ELIDE-TREE: [const != const volatile] vector<
+// CHECK-ELIDE-TREE: [...]>>
+// CHECK-NOELIDE-TREE: no matching function for call to 'set20'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: vector<
+// CHECK-NOELIDE-TREE: [const != const volatile] vector<
+// CHECK-NOELIDE-TREE: int>>
+
+
+// Checks that volatile does not show up in diagnostics.
+template<typename T> struct S21 {};
+template<typename T> using U21 = volatile S21<T>;
+int f21(vector<const U21<int>>);
+int k21 = f21(vector<U21<int>>());
+// CHECK-ELIDE-NOTREE: no matching function for call to 'f21'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<U21<[...]>>' to 'vector<const U21<[...]>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'f21'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<U21<int>>' to 'vector<const U21<int>>' for 1st argument
+// CHECK-ELIDE-TREE: no matching function for call to 'f21'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: vector<
+// CHECK-ELIDE-TREE: [(no qualifiers) != const] U21<
+// CHECK-ELIDE-TREE: [...]>>
+// CHECK-NOELIDE-TREE: no matching function for call to 'f21'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: vector<
+// CHECK-NOELIDE-TREE: [(no qualifiers) != const] U21<
+// CHECK-NOELIDE-TREE: int>>
+
+// Checks that volatile does not show up in diagnostics.
+template<typename T> struct S22 {};
+template<typename T> using U22 = volatile S22<T>;
+int f22(vector<volatile const U22<int>>);
+int k22 = f22(vector<volatile U22<int>>());
+// CHECK-ELIDE-NOTREE: no matching function for call to 'f22'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<U22<[...]>>' to 'vector<const U22<[...]>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'f22'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'vector<U22<int>>' to 'vector<const U22<int>>' for 1st argument
+// CHECK-ELIDE-TREE: no matching function for call to 'f22'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: vector<
+// CHECK-ELIDE-TREE: [(no qualifiers) != const] U22<
+// CHECK-ELIDE-TREE: [...]>>
+// CHECK-NOELIDE-TREE: no matching function for call to 'f22'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: vector<
+// CHECK-NOELIDE-TREE: [(no qualifiers) != const] U22<
+// CHECK-NOELIDE-TREE: int>>
+
+// Testing qualifiers and typedefs.
+template <class T> struct D23{};
+template <class T> using C23 = D23<T>;
+typedef const C23<int> B23;
+template<class ...T> using A23 = B23;
+
+void foo23(D23<A23<>> b) {}
+void test23() {
+ foo23(D23<D23<char>>());
+ foo23(C23<char>());
+}
+
+// CHECK-ELIDE-NOTREE: no matching function for call to 'foo23'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'D23<D23<char>>' to 'D23<const D23<int>>' for 1st argument
+// CHECK-ELIDE-NOTREE: no matching function for call to 'foo23'
+// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'D23<char>' to 'D23<A23<>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'foo23'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'D23<D23<char>>' to 'D23<const D23<int>>' for 1st argument
+// CHECK-NOELIDE-NOTREE: no matching function for call to 'foo23'
+// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'D23<char>' to 'D23<A23<>>' for 1st argument
+// CHECK-ELIDE-TREE: no matching function for call to 'foo23'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: D23<
+// CHECK-ELIDE-TREE: [(no qualifiers) != const] D23<
+// CHECK-ELIDE-TREE: [char != int]>>
+// CHECK-ELIDE-TREE: no matching function for call to 'foo23'
+// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-ELIDE-TREE: D23<
+// CHECK-ELIDE-TREE: [char != A23<>]>
+// CHECK-NOELIDE-TREE: no matching function for call to 'foo23'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: D23<
+// CHECK-NOELIDE-TREE: [(no qualifiers) != const] D23<
+// CHECK-NOELIDE-TREE: [char != int]>>
+// CHECK-NOELIDE-TREE: no matching function for call to 'foo23'
+// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
+// CHECK-NOELIDE-TREE: D23<
+// CHECK-NOELIDE-TREE: [char != A23<>]>
+
// CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated.
// CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated.
// CHECK-ELIDE-TREE: {{[0-9]*}} errors generated.