Commit Graph

278 Commits

Author SHA1 Message Date
Richard Smith 2a7d481faf Implement most of N3638 (return type deduction for normal functions).
Missing (somewhat ironically) is support for the new deduction rules
in lambda functions, plus PCH support for return type patching.

llvm-svn: 181108
2013-05-04 07:00:32 +00:00
Richard Smith b875c43307 Simplify slightly.
llvm-svn: 181092
2013-05-04 01:51:08 +00:00
Richard Smith 061f1e21be When deducing an 'auto' type, don't modify the type-as-written.
llvm-svn: 180808
2013-04-30 21:23:01 +00:00
Richard Smith 27d807cc9c Don't treat a non-deduced 'auto' type as being type-dependent. Instead, there
are now two distinct canonical 'AutoType's: one is the undeduced 'auto'
placeholder type, and the other is a deduced-but-dependent type. All
deduced-to-a-non-dependent-type cases are still non-canonical.

llvm-svn: 180789
2013-04-30 13:56:41 +00:00
Richard Smith 74aeef50a0 Implement C++1y decltype(auto).
llvm-svn: 180610
2013-04-26 16:15:35 +00:00
Douglas Gregor 19a41f161b Fix PR15291: noreturn adjustment in overload resolution for function templates, from Alexander Zinenko!
llvm-svn: 179680
2013-04-17 08:45:07 +00:00
Jordan Rose a0a86bed71 Sema: Preserve attributes on parameters in instantiated function templates.
This was causing correctness issues for ARC and the static analyzer when a
function template has "consumed" Objective-C object parameters (i.e.
parameters that will be released by the function before returning).

The fix is threefold:
(1) Actually copy over the attributes from old ParmVarDecls to new ones.
(2) Have Sema::BuildFunctionType only work for building FunctionProtoTypes,
    which it was doing anyway. This allows us to pass an ExtProtoInfo
    instead of a plain ExtInfo and several flags.
(3) Drop param attributes as part of StripImplicitInstantiation, which is
    used when an implicit instantiation is followed by an explicit one.

<rdar://problem/12685622>

llvm-svn: 176728
2013-03-08 22:25:36 +00:00
Jordan Rose 5c38272c1a ArrayRef-ize ASTContext::getFunctionType and Sema::BuildFunctionType.
No (intended) functionality change.

llvm-svn: 176726
2013-03-08 21:51:21 +00:00
Richard Smith 44ecdbdc61 Improve 'failed template argument deduction' diagnostic for the case where we
have a direct mismatch between some component of the template and some
component of the argument. The diagnostic now says what the mismatch was, but
doesn't yet say which part of the template doesn't match.

llvm-svn: 174039
2013-01-31 05:19:49 +00:00
Richard Smith 8c6eeb9599 Replace "failed template argument deduction" diagnostic with something useful
in the one case where we've already factored out a reason code.

llvm-svn: 174036
2013-01-31 04:03:12 +00:00
Dmitri Gribenko fe0483dbea Use 'const Decl *' throughout code completion in Sema
llvm-svn: 173277
2013-01-23 17:21:11 +00:00
Douglas Gregor caddba9f00 Once we've collected the template arguments for a
partially-substituted parameter pack in a template, forget about the
partially-substituted parameter pack: it is now completed. Fixes
<rdar://problem/12176336>.

llvm-svn: 172859
2013-01-18 22:27:09 +00:00
Richard Smith 2bf7fdb723 s/CPlusPlus0x/CPlusPlus11/g
llvm-svn: 171367
2013-01-02 11:42:31 +00:00
Richard Smith 16b65394ee Fix http://stackoverflow.com/questions/13521163
Don't require that, during template deduction, a template specialization type
as a function parameter has at least as many template arguments as one used in
a function argument (not even if the argument has been resolved to an exact
type); the additional parameters might be provided by default template
arguments in the template. We don't need this check, since we now implement
[temp.deduct.call]p4 with an additional check after deduction.

llvm-svn: 169475
2012-12-06 06:44:44 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

llvm-svn: 169237
2012-12-04 09:13:33 +00:00
NAKAMURA Takumi bae23ed8c5 SemaTemplateDeduction.cpp: Prune two obsolete descriptions. [-Wdocumentation]
* getMostSpecialized()

/// \param Index if non-NULL and the result of this function is non-nULL,
/// receives the index corresponding to the resulting function template
/// specialization.

* DeduceTemplateArguments()

/// \param Name the name of the function being called. This is only significant
/// when the function template is a conversion function template, in which
/// case this routine will also perform template argument deduction based on
/// the function to which

llvm-svn: 167909
2012-11-14 02:21:48 +00:00
Richard Trieu 23bafad985 When template deduction fails on a derived class, try a template deduction on
the base class.  If the base class deduction succeeds, use those results.  If
it fails, keep using the results from the derived class template deduction.

This prevents an assertion later where the type of deduction failure doesn't
match up with the template deduction info.

llvm-svn: 167550
2012-11-07 21:17:13 +00:00
Eli Friedman e43109557c Fix assertion failure with auto and nested initializer list; PR14272.
llvm-svn: 167506
2012-11-06 23:56:42 +00:00
Eli Friedman b826a00857 Fix the AST representation for non-type template arguments to encode
enough information so we can mangle them correctly in cases involving
dependent parameter types. (This specifically impacts cases involving
null pointers and cases involving parameters of reference type.)
Fix the mangler to use this information instead of trying to scavenge
it out of the parameter declaration.

<rdar://problem/12296776>.

llvm-svn: 164656
2012-09-26 02:36:12 +00:00
Eli Friedman ee2ff1cb96 Fix a small FIXME involving template partial ordering and
member function templates with an rvalue ref qualifier.

llvm-svn: 164267
2012-09-19 23:52:13 +00:00
Eli Friedman 3b5774ab0f Fix function template partial ordering rules for static vs. non-static
functions.

llvm-svn: 164263
2012-09-19 23:27:04 +00:00
Craig Topper e6706e40bb Remove Context argument from TemplateDeductionInfo constructor. It was no longer needed after the unused Context member was removed in r164104.
llvm-svn: 164196
2012-09-19 02:26:47 +00:00
Douglas Gregor c5c01a60c2 Don't perform template argument deduction against invalid templates;
it's likely to lead to a crash later on. Fixes PR12933 /
<rdar://problem/11525335>.

llvm-svn: 163838
2012-09-13 21:01:57 +00:00
Richard Smith 1fde8ece37 PR9023: A template template parameter whose template parameter list contains an
unexpanded parameter pack is a pack expansion. Thus, as with a non-type template
parameter which is a pack expansion, it needs to be expanded early into a fixed
list of template parameters.

Since the expanded list of template parameters is not itself a parameter pack,
it is permitted to appear before the end of the template parameter list, so also
remove that restriction (for both template template parameter pack expansions and
non-type template parameter pack expansions).

llvm-svn: 163369
2012-09-07 02:06:42 +00:00
Dmitri Gribenko adba9be7c5 Fix a bunch of -Wdocumentation warnings.
llvm-svn: 162452
2012-08-23 17:58:28 +00:00
Richard Smith 802c4b7015 Fix undefined behavior: member function calls where 'this' is a null pointer.
llvm-svn: 162430
2012-08-23 06:16:52 +00:00
Douglas Gregor a906ad2f9e When performing the deduced/actual argument type check for C++
[temp.deduct.call]p4 under Objective-C++ ARC, make sure to adjust the
qualifiers to introduce the implicit strong lifetime when
needed. Fixes <rdar://problem/11825671>.

llvm-svn: 160412
2012-07-18 00:14:59 +00:00
Richard Smith 8093465a0b PR13365: Fix code which was trying to treat an array of DeducedTemplateArgument
as an array of its base class TemplateArgument. Switch the const
TemplateArgument* parameters of InstantiatingTemplate's constructors to
ArrayRef<TemplateArgument> to prevent this from happening again in the future.

llvm-svn: 160245
2012-07-16 01:09:10 +00:00
Richard Smith 34349003cf PR13136:
* When substituting a reference to a non-type template parameter pack where the
   corresponding argument is a pack expansion, transform into an expression
   which contains an unexpanded parameter pack rather than into an expression
   which contains a pack expansion. This causes the SubstNonTypeTemplateParmExpr
   to be inside the PackExpansionExpr, rather than outside, so the expression
   still looks like a pack expansion and can be deduced.

 * Teach MarkUsedTemplateParameters that we can deduce a reference to a template
   parameter if it's wrapped in a SubstNonTypeTemplateParmExpr (such nodes are
   added during alias template substitution).

llvm-svn: 159922
2012-07-09 03:07:20 +00:00
Richard Smith 7ebb07c87c PR13243: When deducing a non-type template parameter which is specified as an
expression, skip over any SubstNonTypeTemplateParmExprs which alias templates
may have inserted before checking for a DeclRefExpr referring to a non-type
template parameter declaration.

llvm-svn: 159909
2012-07-08 04:37:51 +00:00
Richard Smith 74801c8182 PR13293: Defer deduction of an auto type with a dependent declarator, such as "auto (*f)(T t)".
llvm-svn: 159908
2012-07-08 04:13:07 +00:00
James Dennett 41725129a4 Documentation cleanup: making \param docs match the code.
llvm-svn: 158982
2012-06-22 10:16:05 +00:00
James Dennett 18348b6218 Diagnostics cleanup: Fixing \params to match the code.
llvm-svn: 158981
2012-06-22 08:52:37 +00:00
James Dennett 634962f3e1 Still more Doxygen documentation fixes:
* Escape #, < and @ symbols where Doxygen would try to interpret them;
* Fix several function param documentation where names had got out of sync;
* Delete param documentation referring to parameters that no longer exist.

llvm-svn: 158472
2012-06-14 21:40:34 +00:00
Benjamin Kramer 6003ad5848 Plug a long standing memory leak in TemplateArgument.
The integral APSInt value is now stored in a decomposed form and the backing
store for large values is allocated via the ASTContext. This way its not
leaked as TemplateArguments are never destructed when they are allocated in
the ASTContext. Since the integral data is immutable it is now shared between
instances, making copying TemplateArguments a trivial operation.

Currently getting the integral data out of a TemplateArgument requires creating
a new APSInt object. This is cheap when the value is small but can be expensive
if it's not. If this turns out to be an issue a more efficient accessor could
be added.

llvm-svn: 158150
2012-06-07 15:09:51 +00:00
Douglas Gregor 7bfb2d026e Move Sema::RequireCompleteType() and Sema::RequireCompleteExprType()
off PartialDiagnostic. PartialDiagnostic is rather heavyweight for
something that is in the critical path and is rarely used. So, switch
over to an abstract-class-based callback mechanism that delays most of
the work until a diagnostic is actually produced. Good for ~11k code
size reduction in the compiler and 1% speedup in -fsyntax-only on the
code in <rdar://problem/11004361>.

llvm-svn: 156176
2012-05-04 16:32:21 +00:00
Douglas Gregor 3024f07c12 Implement C++11 [expr.prim.general]p3, which permits the use of 'this'
in the declaration of a non-static member function after the
(optional) cv-qualifier-seq, which in practice means in the exception
specification and late-specified return type. 

The new scheme here used to manage 'this' outside of a member function
scope is more general than the Scope-based mechanism previously used
for non-static data member initializers and late-parsesd attributes,
because it can also handle the cv-qualifiers on the member
function. Note, however, that a separate pass is required for static
member functions to determine whether 'this' was used, because we
might not know that we have a static function until after declaration
matching.

Finally, this introduces name mangling for 'this' and for the implicit
'this', which is intended to match GCC's mangling. Independent
verification for the new mangling test case would be appreciated.

Fixes PR10036 and PR12450.

llvm-svn: 154799
2012-04-16 07:05:22 +00:00
Douglas Gregor 31f55dced5 Implement support for null non-type template arguments for non-type
template parameters of pointer, pointer-to-member, or nullptr_t
type in C++11. Fixes PR9700 / <rdar://problem/11193097>.

llvm-svn: 154219
2012-04-06 22:40:38 +00:00
Douglas Gregor 0e60cd78cc When performing template argument deduction for an initializer list,
be sure to perform the argument type adjustments in
[temp.deduct.call]p2, e.g., array decay.

And, when performing these deductions in the context of 'auto', make
sure that we're deducing the P' in std::initializer_list<P'> rather
than the whole initializer list.

Together, this makes code like

  for( auto s : {"Deferred", "New", "Open", "Review"}) { }

work properly.

llvm-svn: 153998
2012-04-04 05:10:53 +00:00
Sebastian Redl 1918166de7 Support deducing template arguments from nested initializer lists. PR12119.
llvm-svn: 152848
2012-03-15 21:40:51 +00:00
Douglas Gregor 8409ccd8f6 C++11 [temp.deduct.call]p6 tweak: when given a set of overlaoded
functions that includes an explicit template argument list, perform
an inner deduction against each of the function templates in that list
and, if successful, use the result of that deduction for the outer
template argument deduction. Fixes PR11713.

llvm-svn: 152575
2012-03-12 21:09:16 +00:00
David Blaikie bbafb8a745 Unify naming of LangOptions variable/get function across the Clang stack (Lex to AST).
The member variable is always "LangOpts" and the member function is always "getLangOpts".

Reviewed by Chris Lattner

llvm-svn: 152536
2012-03-11 07:00:24 +00:00
Douglas Gregor 194ea69d62 When template argument deduction is ignoring qualifiers, perform deep
structural comparison of non-dependent types. Otherwise, we end up
rejecting cases where the non-dependent types don't match due to
qualifiers in, e.g., a pointee type. Fixes PR12132.

llvm-svn: 152529
2012-03-11 03:29:50 +00:00
Ahmed Charles b24b9aa298 ArrayRef'ize various functions in the AST/Parser/Sema.
llvm-svn: 151447
2012-02-25 11:00:22 +00:00
Bill Wendling 8eb771d4ca More ArrayRef-ification of methods.
llvm-svn: 151152
2012-02-22 09:51:33 +00:00
Bill Wendling 8ac06afa9b ArrayRef-icize the function arguments.
llvm-svn: 151151
2012-02-22 09:38:11 +00:00
Douglas Gregor 0c46b2b7ce Introduce support for template instantiation of lambda
expressions. This is mostly a simple refact, splitting the main "start
a lambda expression" function into smaller chunks that are driven
either from the parser (Sema::ActOnLambdaExpr) or during AST
transformation (TreeTransform::TransformLambdaExpr). A few minor
interesting points:

  - Added new entry points for TreeTransform, so that we can
  explicitly establish the link between the lambda closure type in the
  template and the lambda closure type in the instantiation.
  - Added a bit into LambdaExpr specifying whether it had an explicit
  result type or not. We should have had this anyway.

This code is 'lightly' tested.

llvm-svn: 150417
2012-02-13 22:00:16 +00:00
Richard Smith 5e580292ac Track whether a function type has a trailing return type as type sugar. Use this
to pretty-print such function types better, and to fix a case where we were not
instantiating templates in lexical order. In passing, move the Variadic bit from
Type's bitfields to FunctionProtoType to get the Type bitfields down to 32 bits.
Also ensure that we always substitute the return type of a function when
substituting explicitly-specified arguments, since that can cause us to bail
out with a SFINAE error before we hit a hard error in parameter substitution.

llvm-svn: 150241
2012-02-10 09:58:53 +00:00
Eli Friedman 77dcc726de Make sure template argument deduction is consistently performed in an unevaluated context.
llvm-svn: 150049
2012-02-08 03:07:05 +00:00
Benjamin Kramer e0513cb3b3 SmallBitVectorize the deduced parameter set.
llvm-svn: 149253
2012-01-30 16:17:39 +00:00