Commit Graph

456 Commits

Author SHA1 Message Date
Richard Smith 1c9f404a25 If an explicitly-specified pack might have been extended by template argument
deduction, don't forget to check the argument is valid.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291170 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05 20:27:28 +00:00
Richard Smith 0738ab99fd Per [temp.deduct.call], do not deduce an array bound of 0 from an empty initializer list.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291075 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05 04:16:30 +00:00
Richard Smith b98cb9531f Factor out more common logic in template argument deduction from function call arguments.
No functionality change intended.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291074 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05 04:08:31 +00:00
Richard Smith cf2ed0b529 Fix assertion failure on deduction failure due to too short template argument list.
We were previously incorrectly using TDK_TooFewArguments to report a template
argument list that's too short, but it actually means that the number of
arguments in a top-level function call was insufficient. When diagnosing the
problem, SemaOverload would (rightly) assert that the failure kind didn't make
any sense.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291064 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05 02:31:32 +00:00
Richard Smith 88fb408d84 Fix failure to treat overloaded function in braced-init-list as a non-deduced context.
Previously, if an overloaded function in a braced-init-list was encountered in
template argument deduction, and the overload set couldn't be resolved to a
particular function, we'd immediately produce a deduction failure. That's not
correct; this situation is supposed to result in that particular P/A pair being
treated as a non-deduced context, and deduction can still succeed if the type
can be deduced from elsewhere.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291014 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 22:03:59 +00:00
Richard Smith cb6c3782fd Factor out duplicated code and simplify.
No functionality change intended.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290996 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 19:47:19 +00:00
Richard Smith 44ea0c4710 Fix deduction of pack elements after a braced-init-list.
Previously, if the arguments for a parameter pack contained a braced-init-list,
we would abort deduction (keeping the pack deductions from prior arguments) at
the point when we reached the braced-init-list, resulting in wrong deductions
and rejects-valids. We now just leave a "hole" in the pack for such an argument,
which needs to be filled by another deduction of the same pack.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290933 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 02:59:16 +00:00
Richard Smith 08f2fcfb4c Fix template argument deduction when only some of a parameter pack is a non-deduced context.
When a parameter pack has multiple corresponding arguments, and some subset of
them are overloaded functions, it's possible that some subset of the parameters
are non-deduced contexts. In such a case, keep deducing from the remainder of
the arguments, and resolve the incomplete pack against whatever other
deductions we've performed for the pack.

GCC, MSVC, and ICC give three different bad behaviors for this case; what we do
now (and what we did before) don't exactly match any of them, sadly :( I'm
getting a core issue opened to specify more precisely how this should be
handled.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290923 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 01:48:55 +00:00
Renato Golin 60fb868946 Revert "DR1391: Check for implicit conversion sequences for non-dependent function template parameters between deduction and substitution. The idea is to accept as many cases as possible, on the basis that substitution failure outside the immediate context is much more common during substitution than during implicit conversion sequence formation."
This reverts commit r290808, as it broken all ARM and AArch64 test-suite
test: MultiSource/UnitTests/C++11/frame_layout

Also, please, next time, try to write a commit message in according to
our guidelines:

http://llvm.org/docs/DeveloperPolicy.html#commit-messages

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290811 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 11:15:42 +00:00
Richard Smith 1c79362aff DR1391: Check for implicit conversion sequences for non-dependent function
template parameters between deduction and substitution. The idea is to accept
as many cases as possible, on the basis that substitution failure outside
the immediate context is much more common during substitution than during
implicit conversion sequence formation.

This does not implement the partial ordering portion of DR1391, which so
far appears to be misguided.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290808 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 02:42:17 +00:00
Richard Smith f34626d89a Address post-commit review comments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290807 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 02:38:22 +00:00
Richard Smith 2faed1c47d [c++17] Implement P0522R0 as written. This allows a template template argument
to be specified for a template template parameter whenever the parameter is at
least as specialized as the argument (when there's an obvious and correct
mapping from uses of the parameter to uses of the argument). For example, a
template with more parameters can be passed to a template template parameter
with fewer, if those trailing parameters have default arguments.

This is disabled by default, despite being a DR resolution, as it's fairly
broken in its current state: there are no partial ordering rules to cope with
template template parameters that have different parameter lists, meaning that
code that attempts to decompose template-ids based on arity can hit unavoidable
ambiguity issues.

The diagnostics produced on a non-matching argument are also pretty bad right
now, but I aim to improve them in a subsequent commit.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290792 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-31 21:41:23 +00:00
Richard Smith ff65ccf9af Remove redundant assertion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290780 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-31 03:33:42 +00:00
Richard Smith fd7e95640d Remove bogus assertion and add testcase that triggers it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290743 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-30 04:32:02 +00:00
Richard Smith 977e39c989 DR1495: A partial specialization is ill-formed if it is not (strictly) more
specialized than the primary template. (Put another way, if we imagine there
were a partial specialization matching the primary template, we should never
select it if some other partial specialization also matches.)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290593 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 07:56:27 +00:00
Richard Smith 5aafadd1b2 Work around a standard defect: template argument deduction for non-type
template parameters of reference type basically doesn't work, because we're
always deducing from an argument expression of non-reference type, so the type
of the deduced expression never matches. Instead, compare the type of an
expression naming the parameter to the type of the argument.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290586 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 06:14:37 +00:00
Richard Smith 21cc71f71e Factor out repeated code for deducing a non-type template parameter as a given
argument value. No functionality change intended.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290576 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 03:59:58 +00:00
Simon Pilgrim 0fa4f01b77 Wdocumentation fix
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290547 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-26 18:11:49 +00:00
Richard Smith c2f02d107c Fix assertion failure when deducing an auto-typed argument against a different-width int.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290522 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-25 20:21:12 +00:00
Richard Smith 89014aa92e Fix some subtle wrong partial ordering bugs particularly with C++1z auto-typed
non-type template parameters.

During partial ordering, when checking the substituted deduced template
arguments match the original, check the types of non-type template arguments
match even if they're dependent. The only way we get dependent types here is if
they really represent types of the other template (which are supposed to be
modeled as being substituted for unique, non-dependent types).

In order to make this work for auto-typed non-type template arguments, we need
to be able to perform auto deduction even when the initializer and
(potentially) the auto type are dependent, support for which is the bulk of
this patch. (Note that this requires the ability to deduce only a single level
of a multi-level dependent type.)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290511 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-25 08:05:23 +00:00
Richard Smith ee1644956c Factor out duplication between partial ordering for class template partial
specializations and variable template partial specializations.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290497 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-24 16:40:51 +00:00
Richard Smith def4cd5506 ArrayRefize lists of TemplateArguments in template argument deduction.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290461 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-23 23:46:56 +00:00
Richard Smith d332921ed6 Only substitute into type of non-type template parameter once, rather than
twice, in finalization of template argument deduction.

This is a re-commit of r290310 (reverted in r290329); the bug found by the
buildbots was fixed in r290399 (we would sometimes build a deduced template
argument with a bogus type).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290403 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-23 02:00:24 +00:00
Richard Smith 4066cb5f77 When merging two deduced non-type template arguments for the same parameter,
fail the merge if the arguments have different types (except if one of them was
deduced from an array bound, in which case take the type from the other).

This is correct because (except in the array bound case) the type of the
template argument in each deduction must match the type of the parameter, so at
least one of the two deduced arguments must have a mismatched type.

This is necessary because we would otherwise lose the type information for the
discarded template argument in the merge, and fail to diagnose the mismatch.

In order to power this, we now properly retain the type of a deduced non-type
template argument deduced from a declaration, rather than giving it the type of
the template parameter; we'll convert it to the template parameter type when
checking the deduced arguments.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290399 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-23 01:30:39 +00:00
Richard Smith edb9d32b8c Speculative revert of r290310 to see if that's the change that's making some of
the bots unhappy.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290329 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-22 07:24:39 +00:00
Saleem Abdulrasool fc5c25468d Sema: print qualified name for overload candidates
Print the fully qualified names for the overload candidates.  This makes
it easier to tell what the ambiguity is.  Especially if a template
is instantiated after a using namespace, it will not inherit the
namespace where it was declared.  The specialization will give a message
about a partial order being ambiguous for the same (unqualified) name,
which does not help identify the failure.

Addresses PR31450!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290315 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-22 04:26:57 +00:00
Richard Smith a71730a1f3 Only substitute into type of non-type template parameter once, rather than
twice, in finalization of template argumetn deduction.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290310 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-22 03:52:37 +00:00
Richard Smith 0eea35547d Factor out checking of template arguments after deduction into a separate
function. (This change would also allow us to handle default template arguments
in partial specializations if the standard ever permits them.)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290225 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-21 01:10:31 +00:00
Richard Smith 61df53b690 PR31081: ignore exception specifications when deducing function template
arguments from a declaration; despite what the standard says, this form of
deduction should not be considering exception specifications.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288301 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-01 02:11:49 +00:00
Richard Smith b3524deb09 p0012: Teach resolving address of overloaded function with dependent exception
specification to resolve the exception specification as part of the type check,
in C++1z onwards. This is not actually part of P0012 / CWG1330 rules for when
an exception specification is "needed", but is necessary for sanity.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285663 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 01:31:23 +00:00
Richard Smith bb4ce7e20e [c++1z] P0012R1: Implement a few remaining pieces: downgrade diagnostic for
mismatched dynamic exception specifications in expressions from an error to a
warning, since this is no longer ill-formed in C++1z.

Allow reference binding of a reference-to-non-noexcept function to a noexcept
function lvalue. As defect resolutions, also allow a conditional between
noexcept and non-noexcept function lvalues to produce a non-noexcept function
lvalue (rather than decaying to a function pointer), and allow function
template argument deduction to deduce a reference to non-noexcept function when
binding to a noexcept function type.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284905 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-22 01:32:19 +00:00
Richard Smith ce58cd720b P0012R1: Make exception specifications be part of the type system. This
implements the bulk of the change (modifying the type system to include
exception specifications), but not all the details just yet.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284337 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-16 17:54:23 +00:00
Richard Smith 55fa8090a8 P0127R2: Support type deduction for types of non-type template parameters in
C++1z.

Patch by James Touton! Some bugfixes and rebasing by me.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282651 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-28 23:55:27 +00:00
Richard Smith 43a65cdfea Fix bug where template argument deduction of a non-type template parameter used
as a template argument in a template-id, from a null non-type template
argument, failed.

Extracted from a patch by James Touton!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282641 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-28 22:08:38 +00:00
Simon Pilgrim 57f668b296 Fix Wdocumentation unknown parameter warning
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278503 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-12 11:43:57 +00:00
Richard Smith 5f0128122c P0217R3: Perform semantic checks and initialization for the bindings in a
decomposition declaration for arrays, aggregate-like structs, tuple-like
types, and (as an extension) for complex and vector types.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278435 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-11 22:25:46 +00:00
Hubert Tong 826aea87e9 Reapply r276069 with workaround for MSVC 2013
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277286 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-30 22:33:34 +00:00
Hubert Tong 06a1ffe84a Revert r276069: MSVC bots not happy
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276074 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-20 01:05:31 +00:00
Hubert Tong 2d4a61465e Concepts: Create space for requires-clause in TemplateParameterList; NFC
Summary:
Space for storing the //constraint-expression// of the
//requires-clause// associated with a `TemplateParameterList` is
arranged by taking a bit out of the `NumParams` field for the purpose
of determining whether there is a //requires-clause// or not, and by
adding to the trailing objects tied to the `TemplateParameterList`. An
accessor is provided.

An appropriate argument is supplied to `TemplateParameterList::Create`
at the various call sites.

Serialization changes will addressed as the Concepts implementation
becomes more solid.

Drive-by fix:
This change also replaces the custom
`FixedSizeTemplateParameterListStorage` implementation with one that
follows the interface provided by `llvm::TrailingObjects`.

Reviewers: aaron.ballman, faisalv, rsmith

Subscribers: cfe-commits, nwilson

Differential Revision: https://reviews.llvm.org/D19322


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276069 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-20 00:30:15 +00:00
David Majnemer ce09fec7c1 [AST] Use ArrayRef in more interfaces
ArrayRef is a little better than passing around a pointer/length
pair.

No functional change is intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274732 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-07 04:43:07 +00:00
David Majnemer 52de7439bc [AST] Use ArrayRef in more interfaces
ArrayRef is a little better than passing around a pointer/length pair.

No functional change is intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274475 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-03 21:17:51 +00:00
Erik Pilkington 82430f7ba1 [Sema] Disallow ambigious base classes in template argument deduction
Fixes PR28195.

Differential revision: http://reviews.llvm.org/D21653

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274077 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-28 23:05:09 +00:00
David Majnemer ba5c7ce848 Use more ArrayRefs
No functional change is intended, just a small refactoring.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273647 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-24 04:05:48 +00:00
Benjamin Kramer 9b28d528b7 Apply some suggestions from clang-tidy's performance-unnecessary-value-param.
No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272789 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-15 14:20:56 +00:00
Faisal Vali 5fb68f064c Fix PR27601 by reverting [r267453] - Refactor traversal of bases in deduction of template parameters from base
This reversal is being done with r267453's author's (i.e. Richard Smith's) permission.

This fixes https://llvm.org/bugs/show_bug.cgi?id=27601 

Also, per Richard's request the examples from the bug report have been added to our test suite.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270016 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-19 02:28:21 +00:00
Richard Smith a54dffea61 Refactor traversal of bases in deduction of template parameters from base
classes of an argument to use CXXRecordDecl::forallBases. Fix forallBases to
only visit each base class once.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267453 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-25 19:28:08 +00:00
Richard Smith 035ee855a9 When deducing template parameters from base classes of an argument type, don't
preserve any deduced types from a failed deduction to a subsequent attempt at
deduction. Patch by Erik Pilkington!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267444 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-25 19:09:05 +00:00
George Burgess IV 83f7b5d7d0 [Sema] Make type deduction work with some overloadable functions
Some functions can't have their address taken. If we encounter an
overload set where only one of the candidates can have its address
taken, we should automatically select that candidate's type in type
deduction.

Differential Revision: http://reviews.llvm.org/D15591


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@263888 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-19 21:51:45 +00:00
John McCall 09c7f7b1b4 Fix the template instantiation of ExtParameterInfos; tests to follow.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262289 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-01 02:09:25 +00:00
Richard Smith 27d1061f79 Ensure that we substitute into the declaration of a template parameter pack
(that is not a pack expansion) during template argument deduction, even if we
deduced that the pack would be empty.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259688 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-03 20:40:30 +00:00
Richard Smith a3bfc5dd82 Refactor conversion of deduced template arguments to reduce repetition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259687 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-03 20:15:01 +00:00
Xiuli Pan 97f9428a0d [OpenCL] Pipe type support
Summary:
Support for OpenCL 2.0 pipe type.
This is a bug-fix version for bader's patch reviews.llvm.org/D14441


Reviewers: pekka.jaaskelainen, Anastasia

Subscribers: bader, Anastasia, cfe-commits

Differential Revision: http://reviews.llvm.org/D15603

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257254 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-09 12:53:17 +00:00
Richard Smith 6735eebd0d Improve diagnostic for the case where a function template candidate is rejected
by overload resolution because deduction succeeds, but the substituted
parameter type for some parameter (with deduced type) doesn't exactly match the
corresponding adjusted argument type.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256657 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-31 02:02:54 +00:00
Richard Smith 88ece4a3de Implement [temp.deduct.type]p6: if the nested-name-specifier of a type is
dependent, the type is a non-deduced context.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256651 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-30 20:56:05 +00:00
David Majnemer e3b6e588e0 ArrayRef-ize TemplateParameterList. NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256463 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-27 07:16:27 +00:00
James Y Knight ba55d246b9 [TrailingObjects] Convert ASTTemplateKWAndArgsInfo and ASTTemplateArgumentListInfo.
Doing so required separating them so that the former doesn't inherit
from the latter anymore. Investigating that, it became clear that the
inheritance wasn't actually providing real value in any case.

So also:
- Remove a bunch of redundant functions (getExplicitTemplateArgs,
  getOptionalExplicitTemplateArgs) on various Expr subclasses which
  depended on the inheritance relationship.
- Switched external callers to use pre-existing accessors that return the
  data they're actually interested in (getTemplateArgs,
  getNumTemplateArgs, etc).
- Switched internal callers to use pre-existing getTemplateKWAndArgsInfo.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256359 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-24 02:59:37 +00:00
Richard Smith 5dbd903a7e Split RequireCompleteType into a function that actually requires that the type
is complete (with an error produced if not) and a function that merely queries
whether the type is complete. Either way we'll trigger instantiation if
necessary, but only the former will diagnose and recover from missing module
imports.

The intent of this change is to prevent a class of bugs where code would call
RequireCompleteType(..., 0) and then ignore the result. With modules, we must
check the return value and use it to determine whether the definition of the
type is visible.

This also fixes a debug info quality issue: calls to isCompleteType do not
trigger the emission of debug information for a type in limited-debug-info
mode. This allows us to avoid emitting debug information for type definitions
in more cases where we believe it is safe to do so.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256049 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-18 22:40:25 +00:00
Richard Smith e11f410f5c Wire a SourceLocation into IsDerivedFrom and move the RequireCompleteType call
for the derived class into it. This is mostly just a cleanup, but could in
principle be a bugfix if there is some codepath that reaches here and didn't
previously require a complete type (I couldn't find any such codepath, though).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256037 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-18 21:45:41 +00:00
Faisal Vali 76fd8510f1 [NFC] Improve a comment from my previous commit (r255221)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255244 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-10 12:29:11 +00:00
Craig Topper e38587e604 Add parentheses to suppress a -Wparentheses warning.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255231 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-10 08:49:55 +00:00
Faisal Vali 3648de7a63 Fix PR24694 (CWG1591): Deducing array bound and element type from initializer list
https://llvm.org/bugs/show_bug.cgi?id=24694
http://wg21.link/cwg1591

Teach DeduceFromInitializerList in SemaTemplateDeduction.cpp to deduce against array (constant and dependent sized) parameters (really, reference to arrays since they don't decay to pointers), by checking if the template parameter is either one of those kinds of arrays, and if so, deducing each initializer list element against the element type, and then deducing the array bound if needed.

In brief, this patch enables the following code:
template<class T, int N> int *f(T (&&)[N]);
int *ip = f({1, 2, 3});




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255221 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-10 05:36:39 +00:00
David Majnemer e63176229a [MS Compat] Adjust thiscall to cdecl when deducing template arguments
Function types can be extracted from member pointer types.
However, the type is not appropriate without first adjusting the calling
convention.

This fixes PR25661.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254323 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-30 20:34:28 +00:00
Richard Smith ea21696b87 Add support for GCC's '__auto_type' extension, per the GCC manual:
https://gcc.gnu.org/onlinedocs/gcc/Typeof.html

Differences from the GCC extension:
 * __auto_type is also permitted in C++ (but only in places where
   it could appear in C), allowing its use in headers that might
   be shared across C and C++, or used from C++98
 * __auto_type can be combined with a declarator, as with C++ auto
   (for instance, "__auto_type *p")
 * multiple variables can be declared in a single __auto_type
   declaration, with the C++ semantics (the deduced type must be
   the same in each case)

This patch also adds a missing restriction on applying typeof to
a bit-field, which GCC has historically rejected in C (due to
lack of clarity as to whether the operand should be promoted).
The same restriction also applies to __auto_type in C (in both
GCC and Clang).

This also fixes PR25449.

Patch by Nicholas Allegra!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252690 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-11 02:02:15 +00:00
James Y Knight 1c07720974 Convert a few classes over to use the new TrailingObjects helper.
This initial commit serves as an example -- the remainder of the
classes using pointer arithmetic for trailing objects will be
converted in subsequent changes.

Differential Revision: http://reviews.llvm.org/D11298

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244262 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-06 20:26:32 +00:00
Benjamin Kramer 66889e0179 [AST] ArrayRefize template argument packs. No functionality change intended.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244026 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-05 09:40:22 +00:00
David Majnemer 87821a35a3 [Sema] Don't crash when deduction fails for decltype(auto)
We didn't check the return result of BuildDecltypeType, resulting in us
crashing when we tried to grab the canonical version of the type.

This fixes PR23995.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241131 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 00:29:28 +00:00
Hubert Tong e9d8c76e70 Consolidate and unify initializer list deduction
Summary:
This patch reduces duplication in the template argument deduction code
for handling deduction from initializer lists in a function call. This
extends the fix for PR12119 to also apply to the case where the
corresponding parameter is a trailing parameter pack.

Test Plan:
A test for deduction from nested initializer lists where the
corresponding parameter is a trailing parameter pack is added in
`clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp`.

Reviewers: fraggamuffin, rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D10681

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240612 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 00:25:49 +00:00
Alexander Kornienko 8ca7705aa3 Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240353 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-22 23:07:51 +00:00
Alexander Kornienko ac58acc7f2 Fixed/added namespace ending comments using clang-tidy. NFC
The patch is generated using this command:

  $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \
      -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \
      work/llvm/tools/clang

To reduce churn, not touching namespaces spanning less than 10 lines.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240270 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-22 09:47:44 +00:00
Yaron Keren 9591d15e42 Silence Visual C++ warning C4189: 'Result' : local variable is initialized but not referenced.
Sadly, LLVM_ATTRIBUTE_UNUSED does nothing with Visual C++ which means
we'll have to workaround such cases again and again.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237267 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 17:56:46 +00:00
Benjamin Kramer 846459b7bc Move private classes into anonymous namespaces
Also merge anonymous namespaces in Targets.cpp a bit. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232945 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-23 12:31:05 +00:00
Richard Smith bd0445fc63 PR22435: Correctly implement tiebreaker for reference ordering in function
template partial ordering rules. This rule applies per pair of types being
compared, not per pair of function templates being compared.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@229965 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-20 04:45:22 +00:00
Francisco Lopes da Silva 40785b0b94 Initial support for C++ parameter completion
The improved completion in call context now works with:

 - Functions.
 - Member functions.
 - Constructors.
 - New expressions.
 - Function call expressions.
 - Template variants of the previous.

There are still rough edges to be fixed:

 - Provide support for optional parameters.         (fix known)
 - Provide support for member initializers.         (fix known)
 - Provide support for variadic template functions. (fix unknown)
 - Others?

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226670 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-21 16:24:11 +00:00
Nathan Sidwell 5ae33bc0c5 restore fix for 18645, buildbot apparently gave a false positive.
Correct logic concerning 'T &&' deduction against lvalues.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226278 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-16 15:20:14 +00:00
Nathan Sidwell c9ebfb4b41 reverting due to build bot failure
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225684 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-12 20:13:20 +00:00
Nathan Sidwell 0c50e1a203 fix pr18645. Correct logic concerning 'T &&' deduction against lvalues.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225587 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-10 18:16:25 +00:00
Richard Smith b9d64a6123 PR22117: Fix a case where we would get confused about which function parameter
we're instantiating, if there's a ParmVarDecl within a FunctionDecl context
that is not a parameter of that function. Add some asserts to catch this kind
of issue more generally, and fix another bug exposed by those asserts where we
were missing a local instantiation scope around substitution of
explicitly-specified template arguments.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225490 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-09 01:19:56 +00:00
Aaron Ballman f1a2b5319f Adding a -Wunused-value warning for expressions with side effects used in an unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224465 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-17 21:57:17 +00:00
David Blaikie f8fdd74444 Update for LLVM API change to make Small(Ptr)Set::insert return pair<iterator, bool> as per the C++ standard's associative container concept.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222335 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-19 07:49:47 +00:00
David Blaikie 3b32ee4d36 PR21246: DebugInfo: Emit the appropriate type (cv qualifiers, reference-ness, etc) for non-type template parameters
Plumb through the full QualType of the TemplateArgument::Declaration, as
it's insufficient to only know whether the type is a reference or
pointer (that was necessary for mangling, but insufficient for debug
info). This shouldn't increase the size of TemplateArgument as
TemplateArgument::Integer is still longer by another 32 bits.

Several bits of code were testing that the reference-ness of the
parameters matched, but this seemed to be insufficient (various other
features of the type could've mismatched and wouldn't've been caught)
and unnecessary, at least insofar as removing those tests didn't cause
anything to fail.

(Richard - perchaps you can hypothesize why any of these checks might
need to test reference-ness of the parameters (& explain why
reference-ness is part of the mangling - I would've figured that for the
reference-ness to be different, a prior template argument would have to
be different). I'd be happy to add them in/beef them up and add test
cases if there's a reason for them)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219900 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-16 04:21:25 +00:00
Aaron Ballman fbc9c9f05e C++1y is now C++14!
Changes diagnostic options, language standard options, diagnostic identifiers, diagnostic wording to use c++14 instead of c++1y. It also modifies related test cases to use the updated diagnostic wording.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215982 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-19 15:55:55 +00:00
Nico Weber 6dc3bcd001 Wrap to 80 columns. No behavior change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214059 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-28 00:02:09 +00:00
Aaron Ballman 87caff73b6 Added the pack_elements range accessor. Refactoring some for loops to use range-based for loops instead. No functional changes intended.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213095 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-15 21:32:31 +00:00
Faisal Vali 4f1b413f41 Fix PR18498: Support explicit template arguments with variadic generic lambdas
http://llvm.org/bugs/show_bug.cgi?id=18498

This code was resulting in a crash:

auto L = [](auto ... v) { };
L.operator()<int>(3);

The reason is that the partially-substituted-pack is incorrectly retained within the current-instantiation-scope during template-argument-finalization, and because lambda's are local, there parent instantiation scopes are merged, which leads to the expansion-pattern being retained in the finalized specialization.

This patch ensures that once we have finalized deduction of a parameter-pack, we remove the partially-substituted-pack so that it doesn't cause CheckParameterPacksForExpansion to incorrectly inform the caller that it needs to retain the expansion pattern.


Thanks to Richard Smith for the review!

http://reviews.llvm.org/D2135


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209992 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-01 16:11:54 +00:00
Nikola Smiljanic 983c003add PR12961 - Extend DR532 to cover C++98/03.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209955 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-31 02:10:59 +00:00
Nikola Smiljanic be481708fb Refactoring. Remove release and take methods from ActionResult. Rename takeAs to getAs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209800 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-29 10:55:11 +00:00
Richard Smith c3684da1d4 PR19878: If a pack expansion appears within another pack expansion, correctly
deduce any packs that are expanded by both expansions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209786 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-29 01:12:14 +00:00
Craig Topper 6b8c5857eb [C++11] Use 'nullptr'. Sema edition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209613 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-26 06:22:03 +00:00
Aaron Ballman 7191c6b061 [C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with iterator_range bases(). Updating all of the usages of the iterators with range-based for loops.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203803 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-13 15:41:46 +00:00
Aaron Ballman 126b7b996c [C++11] Replacing FunctionDecl iterators param_begin() and param_end() with iterator_range params(). Updating all of the usages of the iterators with range-based for loops.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203248 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-07 15:12:56 +00:00
Benjamin Kramer ba9fd9e97e [C++11] Replace llvm::tie with std::tie.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202639 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-02 13:01:17 +00:00
Alp Toker 37545f747c Rename getResultType() on function and method declarations to getReturnType()
A return type is the declared or deduced part of the function type specified in
the declaration.

A result type is the (potentially adjusted) type of the value of an expression
that calls the function.

Rule of thumb:

  * Declarations have return types and parameters.
  * Expressions have result types and arguments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200082 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-25 16:55:45 +00:00
Alp Toker c50bf3d128 Rename FunctionProtoType accessors from 'arguments' to 'parameters'
Fix a perennial source of confusion in the clang type system: Declarations and
function prototypes have parameters to which arguments are supplied, so calling
these 'arguments' was a stretch even in C mode, let alone C++ where default
arguments, templates and overloading make the distinction important to get
right.

Readability win across the board, especially in the casting, ADL and
overloading implementations which make a lot more sense at a glance now.

Will keep an eye on the builders and update dependent projects shortly.

No functional change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199686 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-20 20:26:09 +00:00
Nick Lewycky 99d7f9f979 Use the appropriate SourceLocation for the template backtrace when doing
template argument deduction.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198995 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-11 02:37:12 +00:00
Douglas Gregor fb2ed8374b Objective-C ARC++: Prefer references to __strong/__weak over __unsafe_unretained.
Fixes <rdar://problem/15713945>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198343 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-02 19:42:02 +00:00
Richard Smith b7428b6366 PR18229: Fix typo in assert condition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197185 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-12 23:14:16 +00:00
Rafael Espindola 282b87a805 Handle CC and NoReturn when instantiating members of class templates.
Before we were considering them only when instantiating templates.

This fixes pr18033.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196050 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-01 16:54:29 +00:00
Rafael Espindola 1334490e37 Further fixes when thiscall is the default for methods.
The previous patches tried to deduce the correct function type. I now realize
this is not possible in general. Consider

class foo {
    template <typename T> static void bar(T v);
};
extern template void foo::bar(const void *);

We will only know that bar is static after a lookup, so we have to handle this
in the template instantiation code.

This patch reverts my previous two changes (but not the tests) and instead
handles the issue in DeduceTemplateArguments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195154 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-19 21:07:04 +00:00
Douglas Gregor 3940e3b9c7 Objective-C++ ARC: Improve the conversion to a const __unsafe_unretained reference.
Under ARC++, a reference to a const Objective-C pointer is implicitly
treated as __unsafe_unretained, and can be initialized with (e.g.) a
__strong lvalue. Make sure this behavior does not break template
argument deduction and (related) that partial ordering still prefers a
'T* const&' template over a 'T const&' template when this case kicks
in. Fixes <rdar://problem/14467941>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194239 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-08 02:04:24 +00:00
Faisal Vali 9bd1c1332f Refactor: Extract specializing the generic lambda call operator during conversion to fptr deduction into its own function.
No functionality change.

All clang regression tests pass.

Thanks!



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193383 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-24 23:40:02 +00:00