summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateDeduction.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Sema] Don't crash when deduction fails for decltype(auto)David Majnemer2015-07-011-0/+2
| | | | | | | | | 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. llvm-svn: 241131
* Consolidate and unify initializer list deductionHubert Tong2015-06-251-33/+49
| | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 240612
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-2/+2
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-2/+2
| | | | | | | | | | | | 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. llvm-svn: 240270
* Silence Visual C++ warning C4189: 'Result' : local variable is initialized ↵Yaron Keren2015-05-131-2/+4
| | | | | | | | | but not referenced. Sadly, LLVM_ATTRIBUTE_UNUSED does nothing with Visual C++ which means we'll have to workaround such cases again and again. llvm-svn: 237267
* Move private classes into anonymous namespacesBenjamin Kramer2015-03-231-0/+2
| | | | | | Also merge anonymous namespaces in Targets.cpp a bit. NFC. llvm-svn: 232945
* PR22435: Correctly implement tiebreaker for reference ordering in functionRichard Smith2015-02-201-158/+47
| | | | | | | template partial ordering rules. This rule applies per pair of types being compared, not per pair of function templates being compared. llvm-svn: 229965
* Initial support for C++ parameter completionFrancisco Lopes da Silva2015-01-211-10/+16
| | | | | | | | | | | | | | | | | | | | 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? llvm-svn: 226670
* restore fix for 18645, buildbot apparently gave a false positive.Nathan Sidwell2015-01-161-30/+17
| | | | | | Correct logic concerning 'T &&' deduction against lvalues. llvm-svn: 226278
* reverting due to build bot failureNathan Sidwell2015-01-121-17/+30
| | | | llvm-svn: 225684
* fix pr18645. Correct logic concerning 'T &&' deduction against lvalues.Nathan Sidwell2015-01-101-30/+17
| | | | llvm-svn: 225587
* PR22117: Fix a case where we would get confused about which function parameterRichard Smith2015-01-091-0/+3
| | | | | | | | | | 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. llvm-svn: 225490
* Adding a -Wunused-value warning for expressions with side effects used in an ↵Aaron Ballman2014-12-171-1/+1
| | | | | | 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. llvm-svn: 224465
* Update for LLVM API change to make Small(Ptr)Set::insert return ↵David Blaikie2014-11-191-1/+1
| | | | | | pair<iterator, bool> as per the C++ standard's associative container concept. llvm-svn: 222335
* PR21246: DebugInfo: Emit the appropriate type (cv qualifiers, ↵David Blaikie2014-10-161-7/+4
| | | | | | | | | | | | | | | | | | | | | | | | | 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) llvm-svn: 219900
* C++1y is now C++14!Aaron Ballman2014-08-191-2/+2
| | | | | | 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. llvm-svn: 215982
* Wrap to 80 columns. No behavior change.Nico Weber2014-07-281-20/+23
| | | | llvm-svn: 214059
* Added the pack_elements range accessor. Refactoring some for loops to use ↵Aaron Ballman2014-07-151-8/+4
| | | | | | range-based for loops instead. No functional changes intended. llvm-svn: 213095
* Fix PR18498: Support explicit template arguments with variadic generic lambdasFaisal Vali2014-06-011-1/+11
| | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 209992
* PR12961 - Extend DR532 to cover C++98/03.Nikola Smiljanic2014-05-311-19/+9
| | | | llvm-svn: 209955
* Refactoring. Remove release and take methods from ActionResult. Rename ↵Nikola Smiljanic2014-05-291-4/+4
| | | | | | takeAs to getAs. llvm-svn: 209800
* PR19878: If a pack expansion appears within another pack expansion, correctlyRichard Smith2014-05-291-199/+178
| | | | | | deduce any packs that are expanded by both expansions. llvm-svn: 209786
* [C++11] Use 'nullptr'. Sema edition.Craig Topper2014-05-261-27/+27
| | | | llvm-svn: 209613
* [C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with ↵Aaron Ballman2014-03-131-5/+3
| | | | | | iterator_range bases(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203803
* [C++11] Replacing FunctionDecl iterators param_begin() and param_end() with ↵Aaron Ballman2014-03-071-5/+2
| | | | | | iterator_range params(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203248
* [C++11] Replace llvm::tie with std::tie.Benjamin Kramer2014-03-021-3/+3
| | | | llvm-svn: 202639
* Rename getResultType() on function and method declarations to getReturnType()Alp Toker2014-01-251-40/+36
| | | | | | | | | | | | | | | 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. llvm-svn: 200082
* Rename FunctionProtoType accessors from 'arguments' to 'parameters'Alp Toker2014-01-201-13/+12
| | | | | | | | | | | | | | | | | 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. llvm-svn: 199686
* Use the appropriate SourceLocation for the template backtrace when doingNick Lewycky2014-01-111-16/+12
| | | | | | template argument deduction. llvm-svn: 198995
* Objective-C ARC++: Prefer references to __strong/__weak over ↵Douglas Gregor2014-01-021-0/+11
| | | | | | | | __unsafe_unretained. Fixes <rdar://problem/15713945>. llvm-svn: 198343
* PR18229: Fix typo in assert condition.Richard Smith2013-12-121-1/+1
| | | | llvm-svn: 197185
* Handle CC and NoReturn when instantiating members of class templates.Rafael Espindola2013-12-011-17/+24
| | | | | | | | Before we were considering them only when instantiating templates. This fixes pr18033. llvm-svn: 196050
* Further fixes when thiscall is the default for methods.Rafael Espindola2013-11-191-0/+17
| | | | | | | | | | | | | | | | | | 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. llvm-svn: 195154
* Objective-C++ ARC: Improve the conversion to a const __unsafe_unretained ↵Douglas Gregor2013-11-081-7/+10
| | | | | | | | | | | | | 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>. llvm-svn: 194239
* Refactor: Extract specializing the generic lambda call operator during ↵Faisal Vali2013-10-241-141/+133
| | | | | | | | | | | | conversion to fptr deduction into its own function. No functionality change. All clang regression tests pass. Thanks! llvm-svn: 193383
* Make InstantiatingTemplate depth checks clearerAlp Toker2013-10-081-4/+4
| | | | | | | | | | The bool conversion operator on InstantiatingTemplate never added value and only served to obfuscate the template instantiation routines. This replaces the conversion and its callers with an explicit isInvalid() function to make it clear what's going on at a glance. llvm-svn: 192177
* Fix gcc -Wunused-but-set-variable warning in r191634.Patrik Hagglund2013-10-021-5/+2
| | | | llvm-svn: 191817
* SemaTemplateDeduction.cpp: Suppress a warning. [-Wunused-variable]NAKAMURA Takumi2013-09-301-1/+1
| | | | llvm-svn: 191648
* Fix windows newlines :(Faisal Vali2013-09-291-133/+133
| | | | llvm-svn: 191641
* Implement conversion to function pointer for generic lambdas without captures.Faisal Vali2013-09-291-12/+163
| | | | | | | | | | | | | | | | The general strategy is to create template versions of the conversion function and static invoker and then during template argument deduction of the conversion function, create the corresponding call-operator and static invoker specializations, and when the conversion function is marked referenced generate the body of the conversion function using the corresponding static-invoker specialization. Similarly, Codegen does something similar - when asked to emit the IR for a specialized static invoker of a generic lambda, it forwards emission to the corresponding call operator. This patch has been reviewed in person both by Doug and Richard. Richard gave me the LGTM. A few minor changes: - per Richard's request i added a simple check to gracefully inform that captures (init, explicit or default) have not been added to generic lambdas just yet (instead of the assertion violation). - I removed a few lines of code that added the call operators instantiated parameters to the currentinstantiationscope. Not only did it not handle parameter packs, but it is more relevant in the patch for nested lambdas which will follow this one, and fix that problem more comprehensively. - Doug had commented that the original implementation strategy of using the TypeSourceInfo of the call operator to create the static-invoker was flawed and allowed const as a member qualifier to creep into the type of the static-invoker. I currently kludge around it - but after my initial discussion with Doug, with a follow up session with Richard, I have added a FIXME so that a more elegant solution that involves the use of TrivialTypeSourceInfo call followed by the correct wiring of the template parameters to the functionprototypeloc is forthcoming. Thanks! llvm-svn: 191634
* Per latest drafting, switch to implementing init-captures as if by declaringRichard Smith2013-09-281-2/+6
| | | | | | and capturing a variable declaration, and complete the implementation of them. llvm-svn: 191605
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-09-261-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, the following features are not included in this commit: - any sort of capturing within generic lambdas - generic lambdas within template functions and nested within other generic lambdas - conversion operator for captureless lambdas - ensuring all visitors are generic lambda aware (Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit) As an example of what compiles through this commit: template <class F1, class F2> struct overload : F1, F2 { using F1::operator(); using F2::operator(); overload(F1 f1, F2 f2) : F1(f1), F2(f2) { } }; auto Recursive = [](auto Self, auto h, auto ... rest) { return 1 + Self(Self, rest...); }; auto Base = [](auto Self, auto h) { return 1; }; overload<decltype(Base), decltype(Recursive)> O(Base, Recursive); int num_params = O(O, 5, 3, "abc", 3.14, 'a'); Please see attached tests for more examples. This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics). Some implementation notes: - Add a new Declarator context => LambdaExprParameterContext to clang::Declarator to allow the use of 'auto' in declaring generic lambda parameters - Add various helpers to CXXRecordDecl to facilitate identifying and querying a closure class - LambdaScopeInfo (which maintains the current lambda's Sema state) was augmented to house the current depth of the template being parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth) so that SemaType.cpp::ConvertDeclSpecToType may use it to immediately generate a template-parameter-type when 'auto' is parsed in a generic lambda parameter context. (i.e we do NOT use AutoType deduced to a template parameter type - Richard seemed ok with this approach). We encode that this template type was generated from an auto by simply adding $auto to the name which can be used for better diagnostics if needed. - SemaLambda.h was added to hold some common lambda utility functions (this file is likely to grow ...) - Teach Sema::ActOnStartOfFunctionDef to check whether it is being called to instantiate a generic lambda's call operator, and if so, push an appropriately prepared LambdaScopeInfo object on the stack. - various tests were added - but much more will be needed. There is obviously more work to be done, and both Richard (weakly) and Doug (strongly) have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData in a future patch which is forthcoming. A greatful thanks to all reviewers including Eli Friedman, James Dennett, and especially the two gracious wizards (Richard Smith and Doug Gregor) who spent hours providing feedback (in person in Chicago and on the mailing lists). And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified! Thanks! llvm-svn: 191453
* SemaTemplateDeduction.cpp: Prune two stray \param(s), TPOC and ↵NAKAMURA Takumi2013-09-111-6/+0
| | | | | | NumCallArguments in Sema::getMostSpecialized(). They were removed since r190444. [-Wdocumentation] llvm-svn: 190501
* PR17075: When performing partial ordering of a member function against aRichard Smith2013-09-111-40/+43
| | | | | | | | | | | non-member function, the number of arguments in the two candidate calls will be different (the non-member call will have one extra argument). We used to get confused by this, and fail to compare the last argument when testing whether the member is better, resulting in us always thinking it is, even if the non-member is more specialized in the last argument. llvm-svn: 190470
* getMostSpecialized for function template sets is never used in the context of aRichard Smith2013-09-101-3/+2
| | | | | | | call; remove its 'number of explicit arguments' and 'what kind of call' parameters. llvm-svn: 190444
* A clean-up pass, exploring the unification of traversals of class, variable ↵Larisse Voufo2013-08-231-3/+15
| | | | | | and function templates. llvm-svn: 189152
* Use pop_back_val() instead of both back() and pop_back().Robert Wilhelm2013-08-231-4/+2
| | | | | | No functionality change intended. llvm-svn: 189112
* Revert "Implement a rudimentary form of generic lambdas."Manuel Klimek2013-08-221-12/+3
| | | | | | This reverts commit 606f5d7a99b11957e057e4cd1f55f931f66a42c7. llvm-svn: 189004
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-08-221-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, the following features are not included in this commit: - any sort of capturing within generic lambdas - nested lambdas - conversion operator for captureless lambdas - ensuring all visitors are generic lambda aware As an example of what compiles: template <class F1, class F2> struct overload : F1, F2 { using F1::operator(); using F2::operator(); overload(F1 f1, F2 f2) : F1(f1), F2(f2) { } }; auto Recursive = [](auto Self, auto h, auto ... rest) { return 1 + Self(Self, rest...); }; auto Base = [](auto Self, auto h) { return 1; }; overload<decltype(Base), decltype(Recursive)> O(Base, Recursive); int num_params = O(O, 5, 3, "abc", 3.14, 'a'); Please see attached tests for more examples. Some implementation notes: - Add a new Declarator context => LambdaExprParameterContext to clang::Declarator to allow the use of 'auto' in declaring generic lambda parameters - Augment AutoType's constructor (similar to how variadic template-type-parameters ala TemplateTypeParmDecl are implemented) to accept an IsParameterPack to encode a generic lambda parameter pack. - Add various helpers to CXXRecordDecl to facilitate identifying and querying a closure class - LambdaScopeInfo (which maintains the current lambda's Sema state) was augmented to house the current depth of the template being parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth) so that Sema::ActOnLambdaAutoParameter may use it to create the appropriate list of corresponding TemplateTypeParmDecl for each auto parameter identified within the generic lambda (also stored within the current LambdaScopeInfo). Additionally, a TemplateParameterList data-member was added to hold the invented TemplateParameterList AST node which will be much more useful once we teach TreeTransform how to transform generic lambdas. - SemaLambda.h was added to hold some common lambda utility functions (this file is likely to grow ...) - Teach Sema::ActOnStartOfFunctionDef to check whether it is being called to instantiate a generic lambda's call operator, and if so, push an appropriately prepared LambdaScopeInfo object on the stack. - Teach Sema::ActOnStartOfLambdaDefinition to set the return type of a lambda without a trailing return type to 'auto' in C++1y mode, and teach the return type deduction machinery in SemaStmt.cpp to process either C++11 and C++14 lambda's correctly depending on the flag. - various tests were added - but much more will be needed. A greatful thanks to all reviewers including Eli Friedman, James Dennett and the ever illuminating Richard Smith. And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified! Thanks! llvm-svn: 188977
* PR16875: The return type of a dependent function type is visible when it'sRichard Smith2013-08-141-5/+4
| | | | | | | | | | | referenced as a member of the current instantiation. In that case, deduce the type of the function to a dependent type rather than exposing an undeduced auto type to the rest of the current instantiation. The standard doesn't really say that the type is dependent in this case; I'll bring this up with CWG. llvm-svn: 188410
OpenPOWER on IntegriCloud