Commit Graph

410 Commits

Author SHA1 Message Date
Richard Smith 7950d82ab5 Revert r291410 and r291411.
The test-suite bots are still failing even after r291410's fix.

llvm-svn: 291412
2017-01-09 01:18:18 +00:00
Richard Smith d22652122d Implement C++ DR1391 (wg21.link/cwg1391)
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 re-commits r290808, reverted in r290811, with a fix for handling of
explicitly-specified template argument packs.

llvm-svn: 291410
2017-01-09 00:43:47 +00:00
Richard Smith c8a32e5ed2 Fix bug where types other than 'cv auto', 'cv auto &', and 'cv auto &&' could
incorrectly be deduced from an initializer list in pathological cases.

llvm-svn: 291191
2017-01-05 23:12:16 +00:00
Richard Smith c92d206ce4 Add missing "original call argument has same type as deduced parameter type"
check for deductions from elements of a braced-init-list.

llvm-svn: 291190
2017-01-05 23:02:44 +00:00
Richard Smith 9c0c98604a If an explicitly-specified pack might have been extended by template argument
deduction, don't forget to check the argument is valid.

llvm-svn: 291170
2017-01-05 20:27:28 +00:00
Richard Smith 9c5534ceb1 Per [temp.deduct.call], do not deduce an array bound of 0 from an empty initializer list.
llvm-svn: 291075
2017-01-05 04:16:30 +00:00
Richard Smith 707eab6655 Factor out more common logic in template argument deduction from function call arguments.
No functionality change intended.

llvm-svn: 291074
2017-01-05 04:08:31 +00:00
Richard Smith ec7176e223 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.

llvm-svn: 291064
2017-01-05 02:31:32 +00:00
Richard Smith 363ae815b1 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.

llvm-svn: 291014
2017-01-04 22:03:59 +00:00
Richard Smith a7d5ec9a1f Factor out duplicated code and simplify.
No functionality change intended.

llvm-svn: 290996
2017-01-04 19:47:19 +00:00
Richard Smith b576c17417 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.

llvm-svn: 290933
2017-01-04 02:59:16 +00:00
Richard Smith 539e8e3703 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.

llvm-svn: 290923
2017-01-04 01:48:55 +00:00
Renato Golin dad96d6751 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

llvm-svn: 290811
2017-01-02 11:15:42 +00:00
Richard Smith efcfe86072 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.

llvm-svn: 290808
2017-01-02 02:42:17 +00:00
Richard Smith aac13a7f2b Address post-commit review comments.
llvm-svn: 290807
2017-01-02 02:38:22 +00:00
Richard Smith 26b86ea8b1 [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.

llvm-svn: 290792
2016-12-31 21:41:23 +00:00
Richard Smith e8a94565d2 Remove redundant assertion.
llvm-svn: 290780
2016-12-31 03:33:42 +00:00
Richard Smith cf82486c90 Remove bogus assertion and add testcase that triggers it.
llvm-svn: 290743
2016-12-30 04:32:02 +00:00
Richard Smith 0e617ecdd1 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.)

llvm-svn: 290593
2016-12-27 07:56:27 +00:00
Richard Smith d92eddf02d 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.

llvm-svn: 290586
2016-12-27 06:14:37 +00:00
Richard Smith 5d10289639 Factor out repeated code for deducing a non-type template parameter as a given
argument value. No functionality change intended.

llvm-svn: 290576
2016-12-27 03:59:58 +00:00
Simon Pilgrim 6f3e1ea403 Wdocumentation fix
llvm-svn: 290547
2016-12-26 18:11:49 +00:00
Richard Smith 993f203278 Fix assertion failure when deducing an auto-typed argument against a different-width int.
llvm-svn: 290522
2016-12-25 20:21:12 +00:00
Richard Smith 87d263e870 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.)

llvm-svn: 290511
2016-12-25 08:05:23 +00:00
Richard Smith 0da6dc47d1 Factor out duplication between partial ordering for class template partial
specializations and variable template partial specializations.

llvm-svn: 290497
2016-12-24 16:40:51 +00:00
Richard Smith 0bda5b5ff4 ArrayRefize lists of TemplateArguments in template argument deduction.
llvm-svn: 290461
2016-12-23 23:46:56 +00:00
Richard Smith 9341790509 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).

llvm-svn: 290403
2016-12-23 02:00:24 +00:00
Richard Smith 593d6a168f 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.

llvm-svn: 290399
2016-12-23 01:30:39 +00:00
Richard Smith e824775399 Speculative revert of r290310 to see if that's the change that's making some of
the bots unhappy.

llvm-svn: 290329
2016-12-22 07:24:39 +00:00
Saleem Abdulrasool 78704fb6dc 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!

llvm-svn: 290315
2016-12-22 04:26:57 +00:00
Richard Smith e27c6dfd31 Only substitute into type of non-type template parameter once, rather than
twice, in finalization of template argumetn deduction.

llvm-svn: 290310
2016-12-22 03:52:37 +00:00
Richard Smith 1f5be4d5b6 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.)

llvm-svn: 290225
2016-12-21 01:10:31 +00:00
Richard Smith baa4783d31 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.

llvm-svn: 288301
2016-12-01 02:11:49 +00:00
Richard Smith 9095e5bf7e 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.

llvm-svn: 285663
2016-11-01 01:31:23 +00:00
Richard Smith 1be59c5106 [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.

llvm-svn: 284905
2016-10-22 01:32:19 +00:00
Richard Smith 3c4f8d2e96 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.

llvm-svn: 284337
2016-10-16 17:54:23 +00:00
Richard Smith 5f274389d1 P0127R2: Support type deduction for types of non-type template parameters in
C++1z.

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

llvm-svn: 282651
2016-09-28 23:55:27 +00:00
Richard Smith 38175a2e75 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!

llvm-svn: 282641
2016-09-28 22:08:38 +00:00
Simon Pilgrim 728134c277 Fix Wdocumentation unknown parameter warning
llvm-svn: 278503
2016-08-12 11:43:57 +00:00
Richard Smith 7873de0cf6 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.

llvm-svn: 278435
2016-08-11 22:25:46 +00:00
Hubert Tong e4a0c0ec78 Reapply r276069 with workaround for MSVC 2013
llvm-svn: 277286
2016-07-30 22:33:34 +00:00
Hubert Tong 286547a337 Revert r276069: MSVC bots not happy
llvm-svn: 276074
2016-07-20 01:05:31 +00:00
Hubert Tong 24ee98e4a5 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

llvm-svn: 276069
2016-07-20 00:30:15 +00:00
David Majnemer 6fbeee307e [AST] Use ArrayRef in more interfaces
ArrayRef is a little better than passing around a pointer/length
pair.

No functional change is intended.

llvm-svn: 274732
2016-07-07 04:43:07 +00:00
David Majnemer 8b62269391 [AST] Use ArrayRef in more interfaces
ArrayRef is a little better than passing around a pointer/length pair.

No functional change is intended.

llvm-svn: 274475
2016-07-03 21:17:51 +00:00
Erik Pilkington 6a16ac0ed7 [Sema] Disallow ambigious base classes in template argument deduction
Fixes PR28195.

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

llvm-svn: 274077
2016-06-28 23:05:09 +00:00
David Majnemer 59f7792136 Use more ArrayRefs
No functional change is intended, just a small refactoring.

llvm-svn: 273647
2016-06-24 04:05:48 +00:00
Benjamin Kramer 7320b99b2c Apply some suggestions from clang-tidy's performance-unnecessary-value-param.
No functionality change intended.

llvm-svn: 272789
2016-06-15 14:20:56 +00:00
Faisal Vali 683b074209 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.

llvm-svn: 270016
2016-05-19 02:28:21 +00:00
Richard Smith 2eba90e0db 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.

llvm-svn: 267453
2016-04-25 19:28:08 +00:00