1 //===- TemplateDeduction.h - C++ template argument deduction ----*- C++ -*-===/
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===/
9 // This file provides types used with Sema's template argument deduction
12 //===----------------------------------------------------------------------===/
13 #ifndef LLVM_CLANG_SEMA_TEMPLATE_DEDUCTION_H
14 #define LLVM_CLANG_SEMA_TEMPLATE_DEDUCTION_H
16 #include "clang/Basic/PartialDiagnostic.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "llvm/ADT/SmallVector.h"
23 class TemplateArgumentList;
27 /// \brief Provides information about an attempted template argument
28 /// deduction, whose success or failure was described by a
29 /// TemplateDeductionResult value.
30 class TemplateDeductionInfo {
31 /// \brief The context in which the template arguments are stored.
34 /// \brief The deduced template argument list.
36 TemplateArgumentList *Deduced;
38 /// \brief The source location at which template argument
39 /// deduction is occurring.
42 /// \brief Warnings (and follow-on notes) that were suppressed due to
43 /// SFINAE while performing template argument deduction.
44 SmallVector<PartialDiagnosticAt, 4> SuppressedDiagnostics;
46 // do not implement these
47 TemplateDeductionInfo(const TemplateDeductionInfo&);
48 TemplateDeductionInfo &operator=(const TemplateDeductionInfo&);
51 TemplateDeductionInfo(ASTContext &Context, SourceLocation Loc)
52 : Context(Context), Deduced(0), Loc(Loc) { }
54 ~TemplateDeductionInfo() {
55 // FIXME: if (Deduced) Deduced->Destroy(Context);
58 /// \brief Returns the location at which template argument is
60 SourceLocation getLocation() const {
64 /// \brief Take ownership of the deduced template argument list.
65 TemplateArgumentList *take() {
66 TemplateArgumentList *Result = Deduced;
71 /// \brief Provide a new template argument list that contains the
72 /// results of template argument deduction.
73 void reset(TemplateArgumentList *NewDeduced) {
74 // FIXME: if (Deduced) Deduced->Destroy(Context);
78 /// \brief Add a new diagnostic to the set of diagnostics
79 void addSuppressedDiagnostic(SourceLocation Loc, const PartialDiagnostic &PD) {
80 SuppressedDiagnostics.push_back(std::make_pair(Loc, PD));
83 /// \brief Iterator over the set of suppressed diagnostics.
84 typedef SmallVectorImpl<PartialDiagnosticAt>::const_iterator
87 /// \brief Returns an iterator at the beginning of the sequence of suppressed
89 diag_iterator diag_begin() const { return SuppressedDiagnostics.begin(); }
91 /// \brief Returns an iterator at the end of the sequence of suppressed
93 diag_iterator diag_end() const { return SuppressedDiagnostics.end(); }
95 /// \brief The template parameter to which a template argument
96 /// deduction failure refers.
98 /// Depending on the result of template argument deduction, this
99 /// template parameter may have different meanings:
101 /// TDK_Incomplete: this is the first template parameter whose
102 /// corresponding template argument was not deduced.
104 /// TDK_Inconsistent: this is the template parameter for which
105 /// two different template argument values were deduced.
106 TemplateParameter Param;
108 /// \brief The first template argument to which the template
109 /// argument deduction failure refers.
111 /// Depending on the result of the template argument deduction,
112 /// this template argument may have different meanings:
114 /// TDK_Inconsistent: this argument is the first value deduced
115 /// for the corresponding template parameter.
117 /// TDK_SubstitutionFailure: this argument is the template
118 /// argument we were instantiating when we encountered an error.
120 /// TDK_NonDeducedMismatch: this is the template argument
121 /// provided in the source code.
122 TemplateArgument FirstArg;
124 /// \brief The second template argument to which the template
125 /// argument deduction failure refers.
127 /// FIXME: Finish documenting this.
128 TemplateArgument SecondArg;