summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateDeduction.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [NFC] Switch CodeGenFunction to use value init instead of member init listsErich Keane2018-07-101-0/+57
| | | | | | | | The member init list for the sole constructor for CodeGenFunction has gotten out of hand, so this patch moves the non-parameter-dependent initializations into the member value inits. llvm-svn: 336726
* [Sema] When the address of a member function is used as a templateAkira Hatanaka2018-06-131-2/+8
| | | | | | | | | | | | | argument, use the context in which it is used for checking its accessibility. This fixes PR32898. rdar://problem/33737747 Differential Revision: https://reviews.llvm.org/D36918 llvm-svn: 334569
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-60/+60
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* Track the result of evaluating a computed noexcept specification on theRichard Smith2018-05-031-1/+1
| | | | | | | | | | | | | | FunctionProtoType. We previously re-evaluated the expression each time we wanted to know whether the type is noexcept or not. We now evaluate the expression exactly once. This is not quite "no functional change": it fixes a crasher bug during AST deserialization where we would try to evaluate the noexcept specification in a situation where we have not deserialized sufficient portions of the AST to permit such evaluation. llvm-svn: 331428
* [Sema] Do not match function type with const T in template argument deductionLei Liu2018-05-031-0/+6
| | | | | | | | | | | From http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1584, function type should not match cv-qualified type in template argument deduction. This also matches what GCC and EDG do in template argument deduction. Differential Revision: https://reviews.llvm.org/D45755 llvm-svn: 331424
* Fix typos in clangAlexander Kornienko2018-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found via codespell -q 3 -I ../clang-whitelist.txt Where whitelist consists of: archtype cas classs checkk compres definit frome iff inteval ith lod methode nd optin ot pres statics te thru Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few files that have dubious fixes reverted.) Differential revision: https://reviews.llvm.org/D44188 llvm-svn: 329399
* [Sema] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko2018-02-221-28/+71
| | | | | | other minor fixes (NFC). llvm-svn: 325834
* Fix assert when template argument deduction's original call arg checking ↵Richard Smith2018-02-201-1/+1
| | | | | | triggers class template instantiation. llvm-svn: 325646
* PR35045: Convert injected-class-name to its corresponding simple-template-idRichard Smith2018-01-041-0/+4
| | | | | | | | | | during template argument deduction. We already did this when the injected-class-name was in P, but missed the case where it was in A. This (probably) can't happen except in implicit deduction guides. llvm-svn: 321779
* Fix and simplify handling of return type for (generic) lambda conversion ↵Richard Smith2018-01-021-140/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function to function pointer. Previously, we would: * compute the type of the conversion function and static invoker as a side-effect of template argument deduction for a conversion * re-compute the type as part of deduced return type deduction when building the conversion function itself Neither of these turns out to be quite correct. There are other ways to reach a declaration of the conversion function than in a conversion (such as an explicit call or friend declaration), and performing auto deduction causes the function type to be rebuilt in the context of the lambda closure type (which is different from the context in which it originally appeared, resulting in spurious substitution failures for constructs that are valid in one context but not the other, such as the use of an enclosing class's "this" pointer). This patch switches us to use a different strategy: as before, we use the declared type of the operator() to form the type of the conversion function and invoker, but we now populate that type as part of return type deduction for the conversion function. And the invoker is now treated as simply being an implementation detail of building the conversion function, and isn't given special treatment by template argument deduction for the conversion function any more. llvm-svn: 321683
* Add explicit break (PR35700).Adrian Prantl2017-12-191-0/+1
| | | | llvm-svn: 321116
* Silence a bunch of implicit fallthrough warningsAdrian Prantl2017-12-191-1/+1
| | | | llvm-svn: 321115
* Now that C++17 is official (https://www.iso.org/standard/68564.html), start ↵Aaron Ballman2017-12-041-5/+5
| | | | | | changing the C++1z terminology over to C++17. NFC intended, these are all mechanical changes. llvm-svn: 319688
* [c++17] When deducing the type of a non-type template parameter from the typeRichard Smith2017-12-011-2/+3
| | | | | | | | | of its argument, perform function-to-pointer and array-to-pointer decay on the parameter type first. Otherwise deduction will fail, as the type of the argument will be decayed. llvm-svn: 319584
* Convert clang::LangAS to a strongly typed enumAlexander Richardson2017-10-151-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Convert clang::LangAS to a strongly typed enum Currently both clang AST address spaces and target specific address spaces are represented as unsigned which can lead to subtle errors if the wrong type is passed. It is especially confusing in the CodeGen files as it is not possible to see what kind of address space should be passed to a function without looking at the implementation. I originally made this change for our LLVM fork for the CHERI architecture where we make extensive use of address spaces to differentiate between capabilities and pointers. When merging the upstream changes I usually run into some test failures or runtime crashes because the wrong kind of address space is passed to a function. By converting the LangAS enum to a C++11 we can catch these errors at compile time. Additionally, it is now obvious from the function signature which kind of address space it expects. I found the following errors while writing this patch: - ItaniumRecordLayoutBuilder::LayoutField was passing a clang AST address space to TargetInfo::getPointer{Width,Align}() - TypePrinter::printAttributedAfter() prints the numeric value of the clang AST address space instead of the target address space. However, this code is not used so I kept the current behaviour - initializeForBlockHeader() in CGBlocks.cpp was passing LangAS::opencl_generic to TargetInfo::getPointer{Width,Align}() - CodeGenFunction::EmitBlockLiteral() was passing a AST address space to TargetInfo::getPointerWidth() - CGOpenMPRuntimeNVPTX::translateParameter() passed a target address space to Qualifiers::addAddressSpace() - CGOpenMPRuntimeNVPTX::getParameterAddress() was using llvm::Type::getPointerTo() with a AST address space - clang_getAddressSpace() returns either a LangAS or a target address space. As this is exposed to C I have kept the current behaviour and added a comment stating that it is probably not correct. Other than this the patch should not cause any functional changes. Reviewers: yaxunl, pcc, bader Reviewed By: yaxunl, bader Subscribers: jlebar, jholewinski, nhaehnle, Anastasia, cfe-commits Differential Revision: https://reviews.llvm.org/D38816 llvm-svn: 315871
* Dependent Address Space SupportAndrew Gozillon2017-10-021-0/+65
| | | | | | | | | | | | | | This patch relates to: https://reviews.llvm.org/D33666 This adds support for template parameters to be passed to the address_space attribute. The main goal is to add further flexibility to the attribute and allow for it to be used easily with templates. The main additions are a new type (DependentAddressSpaceType) alongside its TypeLoc and its mangling. As well as the logic required to support dependent address spaces which mainly resides in TreeTransform.h and SemaType.cpp. llvm-svn: 314649
* P0702R1: in class template argument deduction from a list of one element, ifRichard Smith2017-09-071-0/+11
| | | | | | | that element's type is (or is derived from) a specialization of the deduced template, skip the std::initializer_list special case. llvm-svn: 312703
* Give a better error if auto deduction fails due to inconsistent element ↵Richard Smith2017-08-301-25/+67
| | | | | | types in a braced initializer list. llvm-svn: 312085
* [c++1z] Support deducing B in noexcept(B).Richard Smith2017-06-071-30/+86
| | | | | | | | This is not required by the standard (yet), but there seems to be reasonable support for this being a defect according to CWG discussion, and libstdc++ 7.1 relies on it working. llvm-svn: 304946
* Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova2017-06-031-0/+1
| | | | llvm-svn: 304651
* Fix assertion failure if we can't deduce a template argument for a variableRichard Smith2017-06-021-1/+2
| | | | | | | | | | | | template partial specialization. In passing, fix the deduction-crash.cpp test to actually run all the tests. Due to a typo, the last third of the file was being skipped by the parser and some of the tests were not actually testing anything as a result. Switch from FileCheck to -verify to make the problem more obvious and prevent this happening again. llvm-svn: 304604
* [NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped EnumFaisal Vali2017-04-011-8/+16
| | | | | | | | - also replace direct equality checks against the ConstantEvaluated enumerator with isConstantEvaluted(), in anticipation of adding finer granularity to the various ConstantEvaluated contexts and reinstating certain restrictions on where lambda expressions can occur in C++17. - update the clang tablegen backend that uses these Enumerators, and add the relevant scope where needed. llvm-svn: 299316
* Rename ActiveTemplateInstantiation to CodeSynthesisContext in preparation forRichard Smith2017-02-231-8/+6
| | | | | | | using it for other kinds of context (where we currently produce context notes in a highly ad-hoc manner). llvm-svn: 295919
* Fix deduction of type of pack-expanded non-type template parameter.Richard Smith2017-02-211-50/+95
| | | | | | | | | We need to look through the PackExpansionType in the parameter type when deducing, and we need to consider the possibility of deducing arguments for packs that are not lexically mentioned in the pattern (but are nonetheless deducible) when figuring out which packs are covered by a pack deduction scope. llvm-svn: 295790
* When deducing an array bound from the length of an initializer list, don'tRichard Smith2017-02-211-3/+10
| | | | | | assume the bound has a non-dependent integral type. llvm-svn: 295698
* Add an explicit derived class of FunctionDecl to model deduction guides ratherRichard Smith2017-02-171-3/+3
| | | | | | | | than just treating them as FunctionDecls with a funny name. No functionality change intended. llvm-svn: 295491
* Revert r295277 to fix buildbot.Richard Smith2017-02-161-93/+61
| | | | llvm-svn: 295281
* Add missing "deduced A == A" check for function template partial ordering.Richard Smith2017-02-161-61/+93
| | | | | | | | | This appears to be the only template argument deduction context where we were missing this check. Surprisingly, other implementations also appear to miss the check in this case; it may turn out that important code is relying on the widespread non-conformance here, in which case we'll need to reconsider. llvm-svn: 295277
* [c++1z] Synthesize implicit deduction guides from constructors on demand. RankRichard Smith2017-02-141-33/+49
| | | | | | | | | | | | | | | | | | | such guides below explicit ones, and ensure that references to the class's template parameters are not treated as forwarding references. We make a few tweaks to the wording in the current standard: 1) The constructor parameter list is copied faithfully to the deduction guide, without losing default arguments or a varargs ellipsis (which the standard wording loses by omission). 2) If the class template declares no constructors, we add a T() -> T<...> guide (which will only ever work if T has default arguments for all non-pack template parameters). 3) If the class template declares nothing that looks like a copy or move constructor, we add a T(T<...>) -> T<...> guide. #2 and #3 follow from the "pretend we had a class type with these constructors" philosophy for deduction guides. llvm-svn: 295007
* Make helpers static. NFC.Benjamin Kramer2017-02-111-2/+2
| | | | llvm-svn: 294838
* [c++1z] P0091R3: Basic support for deducing class template arguments via ↵Richard Smith2017-02-091-35/+52
| | | | | | deduction-guides. llvm-svn: 294613
* PR31846: Don't replace 'auto' type with a template parameter type in a ↵Richard Smith2017-02-041-0/+7
| | | | | | | | generic lambda until after we've checked whether 'auto' is valid in the current language mode. llvm-svn: 294078
* PR0091R3: Implement parsing support for using templates as types.Richard Smith2017-01-261-1/+3
| | | | | | | | | | | | | | | This change adds a new type node, DeducedTemplateSpecializationType, to represent a type template name that has been used as a type. This is modeled around AutoType, and shares a common base class for representing a deduced placeholder type. We allow deduced class template types in a few more places than the standard does: in conditions and for-range-declarators, and in new-type-ids. This is consistent with GCC and with discussion on the core reflector. This patch does not yet support deduced class template types being named in typename specifiers. llvm-svn: 293207
* PR9551: Implement DR1004 (http://wg21.link/cwg1004).Richard Smith2017-01-181-5/+3
| | | | | | | | This rule permits the injected-class-name of a class template to be used as both a template type argument and a template template argument, with no extra syntax required to disambiguate. llvm-svn: 292426
* Implement C++ DR1391 (wg21.link/cwg1391)Richard Smith2017-01-091-18/+43
| | | | | | | | | | | | | | 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 and r291412, with a couple of fixes for handling of explicitly-specified non-trailing template argument packs. llvm-svn: 291427
* Implement DR1388 (wg21.link/cwg1388).Richard Smith2017-01-091-31/+52
| | | | | | | | | | | | This issue clarifies how deduction proceeds past a non-trailing function parameter pack. Essentially, the pack itself is skipped and consumes no arguments (except for those implied by an explicitly-specified template arguments), and nothing is deduced from it. As a small fix to the standard's rule, we do not allow subsequent deduction to change the length of the function parameter pack (by preventing extension of the explicitly-specified pack if present, and otherwise deducing all contained packs to empty packs). llvm-svn: 291425
* Revert r291410 and r291411.Richard Smith2017-01-091-31/+13
| | | | | | The test-suite bots are still failing even after r291410's fix. llvm-svn: 291412
* Implement C++ DR1391 (wg21.link/cwg1391)Richard Smith2017-01-091-13/+31
| | | | | | | | | | | | | 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
* Fix bug where types other than 'cv auto', 'cv auto &', and 'cv auto &&' couldRichard Smith2017-01-051-0/+6
| | | | | | incorrectly be deduced from an initializer list in pathological cases. llvm-svn: 291191
* Add missing "original call argument has same type as deduced parameter type"Richard Smith2017-01-051-21/+80
| | | | | | check for deductions from elements of a braced-init-list. llvm-svn: 291190
* If an explicitly-specified pack might have been extended by template argumentRichard Smith2017-01-051-13/+14
| | | | | | deduction, don't forget to check the argument is valid. llvm-svn: 291170
* Per [temp.deduct.call], do not deduce an array bound of 0 from an empty ↵Richard Smith2017-01-051-1/+3
| | | | | | initializer list. llvm-svn: 291075
* Factor out more common logic in template argument deduction from function ↵Richard Smith2017-01-051-71/+62
| | | | | | | | call arguments. No functionality change intended. llvm-svn: 291074
* Fix assertion failure on deduction failure due to too short template ↵Richard Smith2017-01-051-2/+3
| | | | | | | | | | | | 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
* Fix failure to treat overloaded function in braced-init-list as a ↵Richard Smith2017-01-041-4/+3
| | | | | | | | | | | | | 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
* Factor out duplicated code and simplify.Richard Smith2017-01-041-132/+81
| | | | | | No functionality change intended. llvm-svn: 290996
* Fix deduction of pack elements after a braced-init-list.Richard Smith2017-01-041-6/+2
| | | | | | | | | | 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
* Fix template argument deduction when only some of a parameter pack is a ↵Richard Smith2017-01-041-36/+41
| | | | | | | | | | | | | | | | | 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
* Revert "DR1391: Check for implicit conversion sequences for non-dependent ↵Renato Golin2017-01-021-26/+10
| | | | | | | | | | | | | | 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
* DR1391: Check for implicit conversion sequences for non-dependent functionRichard Smith2017-01-021-10/+26
| | | | | | | | | | | | 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
OpenPOWER on IntegriCloud