12a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall//===- TemplateDeduction.h - C++ template argument deduction ----*- C++ -*-===/ 22a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// 32a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// The LLVM Compiler Infrastructure 42a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// 52a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// This file is distributed under the University of Illinois Open Source 62a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// License. See LICENSE.TXT for details. 72a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall//===----------------------------------------------------------------------===/ 82a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// 92a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// This file provides types used with Sema's template argument deduction 102a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// routines. 112a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall// 122a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall//===----------------------------------------------------------------------===/ 132a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall#ifndef LLVM_CLANG_SEMA_TEMPLATE_DEDUCTION_H 142a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall#define LLVM_CLANG_SEMA_TEMPLATE_DEDUCTION_H 152a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 162a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall#include "clang/AST/DeclTemplate.h" 1730a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Basic/PartialDiagnostic.h" 189b623639378d53a675921ddfa7316034d571881eDouglas Gregor#include "llvm/ADT/SmallVector.h" 192a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 202a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCallnamespace clang { 212a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 22ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct DeducedPack; 232a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCallclass TemplateArgumentList; 244384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufoclass Sema; 252a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 262a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCallnamespace sema { 27ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 282a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall/// \brief Provides information about an attempted template argument 292a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall/// deduction, whose success or failure was described by a 302a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall/// TemplateDeductionResult value. 312a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCallclass TemplateDeductionInfo { 322a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// \brief The deduced template argument list. 332a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 342a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall TemplateArgumentList *Deduced; 352a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 362a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// \brief The source location at which template argument 372a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// deduction is occurring. 382a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall SourceLocation Loc; 392a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 40b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith /// \brief Have we suppressed an error during deduction? 41b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith bool HasSFINAEDiagnostic; 42b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith 43ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Warnings (and follow-on notes) that were suppressed due to 449b623639378d53a675921ddfa7316034d571881eDouglas Gregor /// SFINAE while performing template argument deduction. 45686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<PartialDiagnosticAt, 4> SuppressedDiagnostics; 46ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 47f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko TemplateDeductionInfo(const TemplateDeductionInfo &) LLVM_DELETED_FUNCTION; 48f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const TemplateDeductionInfo &) LLVM_DELETED_FUNCTION; 492a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 502a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCallpublic: 5193e4599196654907dad3bd476013ad05d36ce604Craig Topper TemplateDeductionInfo(SourceLocation Loc) 526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines : Deduced(nullptr), Loc(Loc), HasSFINAEDiagnostic(false), 536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Expression(nullptr) {} 542a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 552a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// \brief Returns the location at which template argument is 56fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// occurring. 572a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall SourceLocation getLocation() const { 582a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall return Loc; 592a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall } 602a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 612a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// \brief Take ownership of the deduced template argument list. 622a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall TemplateArgumentList *take() { 632a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall TemplateArgumentList *Result = Deduced; 646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Deduced = nullptr; 652a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall return Result; 662a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall } 672a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 68b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith /// \brief Take ownership of the SFINAE diagnostic. 69b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith void takeSFINAEDiagnostic(PartialDiagnosticAt &PD) { 70b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith assert(HasSFINAEDiagnostic); 71b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith PD.first = SuppressedDiagnostics.front().first; 72b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith PD.second.swap(SuppressedDiagnostics.front().second); 73b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith SuppressedDiagnostics.clear(); 74b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith HasSFINAEDiagnostic = false; 75b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith } 76b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith 772a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// \brief Provide a new template argument list that contains the 782a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// results of template argument deduction. 792a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall void reset(TemplateArgumentList *NewDeduced) { 802a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall Deduced = NewDeduced; 812a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall } 822a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 83b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith /// \brief Is a SFINAE diagnostic available? 84b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith bool hasSFINAEDiagnostic() const { 85b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith return HasSFINAEDiagnostic; 86b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith } 87b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith 88b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith /// \brief Set the diagnostic which caused the SFINAE failure. 89b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith void addSFINAEDiagnostic(SourceLocation Loc, PartialDiagnostic PD) { 90b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith // Only collect the first diagnostic. 91b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith if (HasSFINAEDiagnostic) 92b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith return; 93b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith SuppressedDiagnostics.clear(); 94b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith SuppressedDiagnostics.push_back( 95b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith std::make_pair(Loc, PartialDiagnostic::NullDiagnostic())); 96b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith SuppressedDiagnostics.back().second.swap(PD); 97b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith HasSFINAEDiagnostic = true; 98b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith } 99b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith 100ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Add a new diagnostic to the set of diagnostics 101ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void addSuppressedDiagnostic(SourceLocation Loc, 102b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith PartialDiagnostic PD) { 103b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith if (HasSFINAEDiagnostic) 104b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith return; 105b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith SuppressedDiagnostics.push_back( 106b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith std::make_pair(Loc, PartialDiagnostic::NullDiagnostic())); 107b8590f3572158bde97f14037c4cc8f4a57c8d810Richard Smith SuppressedDiagnostics.back().second.swap(PD); 1089b623639378d53a675921ddfa7316034d571881eDouglas Gregor } 109ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1109b623639378d53a675921ddfa7316034d571881eDouglas Gregor /// \brief Iterator over the set of suppressed diagnostics. 111ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie typedef SmallVectorImpl<PartialDiagnosticAt>::const_iterator 1129b623639378d53a675921ddfa7316034d571881eDouglas Gregor diag_iterator; 113ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1149b623639378d53a675921ddfa7316034d571881eDouglas Gregor /// \brief Returns an iterator at the beginning of the sequence of suppressed 1159b623639378d53a675921ddfa7316034d571881eDouglas Gregor /// diagnostics. 1169b623639378d53a675921ddfa7316034d571881eDouglas Gregor diag_iterator diag_begin() const { return SuppressedDiagnostics.begin(); } 117ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1189b623639378d53a675921ddfa7316034d571881eDouglas Gregor /// \brief Returns an iterator at the end of the sequence of suppressed 1199b623639378d53a675921ddfa7316034d571881eDouglas Gregor /// diagnostics. 1209b623639378d53a675921ddfa7316034d571881eDouglas Gregor diag_iterator diag_end() const { return SuppressedDiagnostics.end(); } 121ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1222a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// \brief The template parameter to which a template argument 1232a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// deduction failure refers. 1242a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 1252a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// Depending on the result of template argument deduction, this 1262a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// template parameter may have different meanings: 1272a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 1282a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// TDK_Incomplete: this is the first template parameter whose 1292a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// corresponding template argument was not deduced. 1302a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 1312a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// TDK_Inconsistent: this is the template parameter for which 1322a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// two different template argument values were deduced. 1332a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall TemplateParameter Param; 1342a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 1352a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// \brief The first template argument to which the template 1362a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// argument deduction failure refers. 1372a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 1382a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// Depending on the result of the template argument deduction, 1392a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// this template argument may have different meanings: 1402a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 1412a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// TDK_Inconsistent: this argument is the first value deduced 1422a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// for the corresponding template parameter. 1432a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 1442a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// TDK_SubstitutionFailure: this argument is the template 1452a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// argument we were instantiating when we encountered an error. 1462a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 14729805ca6d278b4d9563adfee67f2478f0fecdcfcRichard Smith /// TDK_NonDeducedMismatch: this is the component of the 'parameter' 14829805ca6d278b4d9563adfee67f2478f0fecdcfcRichard Smith /// of the deduction, directly provided in the source code. 1492a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall TemplateArgument FirstArg; 1502a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 1512a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// \brief The second template argument to which the template 1522a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// argument deduction failure refers. 1532a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// 15429805ca6d278b4d9563adfee67f2478f0fecdcfcRichard Smith /// TDK_NonDeducedMismatch: this is the mismatching component of the 15529805ca6d278b4d9563adfee67f2478f0fecdcfcRichard Smith /// 'argument' of the deduction, from which we are deducing arguments. 15629805ca6d278b4d9563adfee67f2478f0fecdcfcRichard Smith /// 1572a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall /// FIXME: Finish documenting this. 1582a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall TemplateArgument SecondArg; 1590efa62f2096f28a610ac2ea8d2651448a7ec89c7Richard Smith 1600efa62f2096f28a610ac2ea8d2651448a7ec89c7Richard Smith /// \brief The expression which caused a deduction failure. 1610efa62f2096f28a610ac2ea8d2651448a7ec89c7Richard Smith /// 1620efa62f2096f28a610ac2ea8d2651448a7ec89c7Richard Smith /// TDK_FailedOverloadResolution: this argument is the reference to 16360e141e1f87211ca831de6821003d80fe20a06f3Richard Smith /// an overloaded function which could not be resolved to a specific 16460e141e1f87211ca831de6821003d80fe20a06f3Richard Smith /// function. 1650efa62f2096f28a610ac2ea8d2651448a7ec89c7Richard Smith Expr *Expression; 166ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 167ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \brief Information on packs that we're currently expanding. 168ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// 169ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// FIXME: This should be kept internal to SemaTemplateDeduction. 170ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SmallVector<DeducedPack *, 8> PendingDeducedPacks; 1712a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall}; 1722a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 1734384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo} // end namespace sema 1744384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 1754384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// A structure used to record information about a failed 1764384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// template argument deduction, for diagnosis. 1774384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufostruct DeductionFailureInfo { 1784384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// A Sema::TemplateDeductionResult. 1794384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo unsigned Result : 8; 1804384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 1814384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Indicates whether a diagnostic is stored in Diagnostic. 1824384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo unsigned HasDiagnostic : 1; 1834384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 1844384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Opaque pointer containing additional data about 1854384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// this deduction failure. 1864384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void *Data; 1874384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 1884384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief A diagnostic indicating why deduction failed. 1894384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo union { 1904384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void *Align; 1914384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo char Diagnostic[sizeof(PartialDiagnosticAt)]; 1924384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo }; 1934384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 1944384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Retrieve the diagnostic which caused this deduction failure, 1954384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// if any. 1964384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo PartialDiagnosticAt *getSFINAEDiagnostic(); 1974384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 1984384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Retrieve the template parameter this deduction failure 1994384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// refers to, if any. 2004384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo TemplateParameter getTemplateParameter(); 2014384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2024384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Retrieve the template argument list associated with this 2034384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// deduction failure, if any. 2044384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo TemplateArgumentList *getTemplateArgumentList(); 2054384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2064384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Return the first template argument this deduction failure 2074384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// refers to, if any. 2084384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo const TemplateArgument *getFirstArg(); 2094384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2104384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Return the second template argument this deduction failure 2114384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// refers to, if any. 2124384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo const TemplateArgument *getSecondArg(); 2134384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2144384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Return the expression this deduction failure refers to, 2154384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// if any. 2164384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo Expr *getExpr(); 2174384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2184384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Free any memory associated with this deduction failure. 2194384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void Destroy(); 2204384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo}; 2214384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2224384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// TemplateSpecCandidate - This is a generalization of OverloadCandidate 2234384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// which keeps track of template argument deduction failure info, when 2244384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// handling explicit specializations (and instantiations) of templates 2254384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// beyond function overloading. 2264384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// For now, assume that the candidates are non-matching specializations. 2274384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// TODO: In the future, we may need to unify/generalize this with 2284384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// OverloadCandidate. 2294384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufostruct TemplateSpecCandidate { 2304384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// Specialization - The actual specialization that this candidate 2314384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// represents. When NULL, this may be a built-in candidate. 2324384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo Decl *Specialization; 2334384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2344384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// Template argument deduction info 2354384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo DeductionFailureInfo DeductionFailure; 2364384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2374384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void set(Decl *Spec, DeductionFailureInfo Info) { 2384384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo Specialization = Spec; 2394384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo DeductionFailure = Info; 2404384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo } 2414384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2424384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// Diagnose a template argument deduction failure. 2434384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void NoteDeductionFailure(Sema &S); 2444384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo}; 2454384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2464384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// TemplateSpecCandidateSet - A set of generalized overload candidates, 2474384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// used in template specializations. 2484384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// TODO: In the future, we may need to unify/generalize this with 2494384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo/// OverloadCandidateSet. 2504384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufoclass TemplateSpecCandidateSet { 2514384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo SmallVector<TemplateSpecCandidate, 16> Candidates; 2524384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo SourceLocation Loc; 2534384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2544384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo TemplateSpecCandidateSet( 2554384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo const TemplateSpecCandidateSet &) LLVM_DELETED_FUNCTION; 2564384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void operator=(const TemplateSpecCandidateSet &) LLVM_DELETED_FUNCTION; 2574384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2584384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void destroyCandidates(); 2594384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2604384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufopublic: 2614384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo TemplateSpecCandidateSet(SourceLocation Loc) : Loc(Loc) {} 2624384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo ~TemplateSpecCandidateSet() { destroyCandidates(); } 2634384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2644384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo SourceLocation getLocation() const { return Loc; } 2654384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2664384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Clear out all of the candidates. 2674384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// TODO: This may be unnecessary. 2684384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void clear(); 2694384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2704384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo typedef SmallVector<TemplateSpecCandidate, 16>::iterator iterator; 2714384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo iterator begin() { return Candidates.begin(); } 2724384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo iterator end() { return Candidates.end(); } 2734384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2744384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo size_t size() const { return Candidates.size(); } 2754384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo bool empty() const { return Candidates.empty(); } 2764384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2774384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// \brief Add a new candidate with NumConversions conversion sequence slots 2784384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo /// to the overload set. 2794384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo TemplateSpecCandidate &addCandidate() { 2804384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo Candidates.push_back(TemplateSpecCandidate()); 2814384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo return Candidates.back(); 2824384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo } 2834384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2844384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void NoteCandidates(Sema &S, SourceLocation Loc); 2854384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2864384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo void NoteCandidates(Sema &S, SourceLocation Loc) const { 2874384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo const_cast<TemplateSpecCandidateSet *>(this)->NoteCandidates(S, Loc); 2884384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo } 2894384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo}; 2904384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo 2914384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo} // end namespace clang 2922a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall 2932a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall#endif 294