summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplate.cpp
Commit message (Collapse)AuthorAgeFilesLines
* This reverts commit r224668 and r224667.Rafael Espindola2014-12-231-7/+0
| | | | | | | | | | r224667 broke bootstrap on Fedora 20 X86_64 (at least). See pr22006 for the details. r224668 depends on r224667. llvm-svn: 224770
* Fix for PR21758Richard Trieu2014-12-201-0/+7
| | | | | | | | | When a non-type template argument expression needs a conversion to change it into the argument type, preserve that information by remaking the TemplateArgument with an expression that has those conversions. Also a small fix to template type diffing to handle the extra conversions in some cases. llvm-svn: 224667
* Don't drop attributes when checking explicit specializations.Nico Weber2014-12-191-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider a template class with attributes on a method, and an explicit specialization of that method: template <int> struct A { void foo() final; }; template <> void A<0>::foo() {} In this example, the attribute is `final`, but it might also be an __attribute__((visibility("foo"))), noreturn, inline, etc. clang's current behavior is to strip all attributes, which for some attributes is wrong (the snippet above allows a subclass of A<0> to override the final method, for example) and for others disagrees with gcc. So stop dropping attributes. r95845 added this code without a test case, and r176728 added the code for dropping attributes on parameters (with tests, but they still pass). As an additional wrinkle, do drop dllimport and dllexport, since that's how these two attributes work. (This is covered by existing tests.) Fixes PR21942. The approach is by Richard Smith, initial analysis and typing was done by me. With this, clang also matches GCC and EDG on all attributes Richard tested. llvm-svn: 224651
* Revert "Don't build invalid AST nodes during recovery"Reid Kleckner2014-12-181-1/+1
| | | | | | | | | | | This reverts commit r224451. It caused us to reject some valid existing code. This code appears to run in non-error cases as well as error cases. If the scope of a DependentScopeDeclRefExpr is still incomplete it probably means we still have more instantiation to do. llvm-svn: 224526
* [c++1z] Fixes for generalized non-type template argument support: check forRichard Smith2014-12-171-42/+45
| | | | | | | | exact type match for deduced template arguments, and be sure to produce correct canonical TemplateArgument representations to enable correct redeclaration matching. llvm-svn: 224456
* Don't build invalid AST nodes during recoveryReid Kleckner2014-12-171-1/+1
| | | | | | | | | | | | | | A DependentScopeDeclRefExpr should always have a nested name specifier. During template instantiation, if we found that the named context was incomplete, we would previously build a DependentScopeDeclRefExpr with an empty qualifier. This error recovery path has been asserting for some time. The other error codepaths use ExprError, so we can do the same. Fixes PR21864. llvm-svn: 224451
* Perform correct lookup when '__super' is used in class with dependent base.Nikola Smiljanic2014-12-011-5/+1
| | | | llvm-svn: 223090
* [c++1z] Most of N4268 (allow constant evaluation for non-type template ↵Richard Smith2014-11-261-1/+99
| | | | | | | | | arguments). We don't yet support pointer-to-member template arguments that have undergone pointer-to-member conversions, mostly because we don't have a mangling for them yet. llvm-svn: 222807
* 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
* PR19372: Keep checking template arguments after we see an argument packRichard Smith2014-11-121-28/+11
| | | | | | | | expansion into a parameter pack; we know that we're still filling in that parameter's arguments. Previously, if we hit this case for an alias template, we'd try to substitute using non-canonical template arguments. llvm-svn: 221832
* PR21536: Fix a corner case where we'd get confused by a pack expanding into theRichard Smith2014-11-121-1/+1
| | | | | | | penultimate parameter of a template parameter list, where the last parameter is itself a pack, and build a bogus empty final pack argument. llvm-svn: 221748
* Fix for exception specification mismatch in explicit instantiation.Alexey Bataev2014-11-061-0/+23
| | | | | | | According to C++ standard if an exception-specification is specified in an explicit instantiation directive, it shall be compatible with the exception-specifications of other declarations of that function. This patch adds checks for this. Differential Revision: http://reviews.llvm.org/D5822 llvm-svn: 221448
* Remove StorageClass typedefs from VarDecl and FunctionDecl since ↵Craig Topper2014-10-311-1/+1
| | | | | | StorageClass is in the clang namespace. llvm-svn: 220956
* Pass around CorrectionCandidateCallbacks as unique_ptrs soKaelyn Takata2014-10-271-9/+8
| | | | | | TypoCorrectionConsumer can keep the callback around as long as needed. llvm-svn: 220693
* PR21246: DebugInfo: Emit the appropriate type (cv qualifiers, ↵David Blaikie2014-10-161-4/+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
* -ms-extensions: Implement __super scope specifier (PR13236).Nikola Smiljanic2014-09-261-1/+6
| | | | | | | | | We build a NestedNameSpecifier that records the CXXRecordDecl in which __super appeared. Name lookup is performed in all base classes of the recorded CXXRecordDecl. Use of __super is allowed only inside class and member function scope. llvm-svn: 218484
* Add -Wunused-local-typedef, a warning that finds unused local typedefs.Nico Weber2014-09-061-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The warning warns on TypedefNameDecls -- typedefs and C++11 using aliases -- that are !isReferenced(). Since the isReferenced() bit on TypedefNameDecls wasn't used for anything before this warning it wasn't always set correctly, so this patch also adds a few missing MarkAnyDeclReferenced() calls in various places for TypedefNameDecls. This is made a bit complicated due to local typedefs possibly being used only after their local scope has closed. Consider: template <class T> void template_fun(T t) { typename T::Foo s3foo; // YYY (void)s3foo; } void template_fun_user() { struct Local { typedef int Foo; // XXX } p; template_fun(p); } Here the typedef in XXX is only used at end-of-translation unit, when YYY in template_fun() gets instantiated. To handle this, typedefs that are unused when their scope exits are added to a set of potentially unused typedefs, and that set gets checked at end-of-TU. Typedefs that are still unused at that point then get warned on. There's also serialization code for this set, so that the warning works with precompiled headers and modules. For modules, the warning is emitted when the module is built, for precompiled headers each time the header gets used. Finally, consider a function using C++14 auto return types to return a local type defined in a header: auto f() { struct S { typedef int a; }; return S(); } Here, the typedef escapes its local scope and could be used by only some translation units including the header. To not warn on this, add a RecursiveASTVisitor that marks all delcs on local types returned from auto functions as referenced. (Except if it's a function with internal linkage, or the decls are private and the local type has no friends -- in these cases, it _is_ safe to warn.) Several of the included testcases (most of the interesting ones) were provided by Richard Smith. (gcc's spelling -Wunused-local-typedefs is supported as an alias for this warning.) llvm-svn: 217298
* [modules] Put class template declarations into the scope in which they'reRichard Smith2014-08-231-3/+7
| | | | | | | | | | | declared, rather than putting them into the template parameter scope. We previously had *no record* in the scope for class template declarations, once those declarations completed and their template parameter scopes were popped. This in turn caused us to be unable to merge class template declarations that were declared in the global scope (where we use scope lookup rather than DeclContext lookup for merging), when loading a module. llvm-svn: 216311
* Sema: Permit nullptr template args in MSVC compat modeDavid Majnemer2014-08-141-1/+1
| | | | | | This fixes a regression I caused back in r211766. llvm-svn: 215609
* Take the canonical type when forming a canonical template argument withRichard Smith2014-07-241-3/+6
| | | | | | | 'nullptr' value. Fixes profiling of such template arguments to always give the same value. llvm-svn: 213834
* PR20356: Fix all Sema warnings with mismatched ext_/warn_ versusRichard Smith2014-07-191-1/+1
| | | | | | | | ExtWarn/Warnings. Mostly the name of the warning was changed to match the semantics, but in the PR20356 cases, the warning was about valid code, so the diagnostic was changed from ExtWarn to Warning instead. llvm-svn: 213443
* Fix FriendDecl source location and range for class templates and function ↵Nikola Smiljanic2014-07-171-4/+4
| | | | | | declarations that don't start with 'friend' keyword. Add more unittests. llvm-svn: 213220
* Sema: Allow dllimport entities in template args for mingwDavid Majnemer2014-06-261-19/+26
| | | | | | | | | | | | | | Previously dllimport variables inside of template arguments relied on not using the C++11 codepath when -fms-compatibility was set. While this allowed us to achieve compatibility with MSVC, it did so at the expense of MingW. Instead, try to use the DeclRefExpr we dig out of the template argument. If it has the dllimport attribute, accept it and skip the C++11 null-pointer check. llvm-svn: 211766
* Convert some function arguments to use ArrayRef.Craig Topper2014-06-261-16/+7
| | | | llvm-svn: 211764
* Don't allow dllimport variables in constant initializersHans Wennborg2014-06-251-1/+1
| | | | | | | | | | | | | | | | | This is a follow-up to David's r211677. For the following code, we would end up referring to 'foo' in the initializer for 'arr', and then fail to link, because 'foo' is dllimport and needs to be accessed through the __imp_?foo. __declspec(dllimport) extern const char foo[]; const char* f() { static const char* const arr[] = { foo }; return arr[0]; } Differential Revision: http://reviews.llvm.org/D4299 llvm-svn: 211736
* Hide the concept of diagnostic levels from lex, parse and semaAlp Toker2014-06-151-6/+11
| | | | | | | | | | | | | | | | The compilation pipeline doesn't actually need to know about the high-level concept of diagnostic mappings, and hiding the final computed level presents several simplifications and other potential benefits. The only exceptions are opportunistic checks to see whether expensive code paths can be avoided for diagnostics that are guaranteed to be ignored at a certain SourceLocation. This commit formalizes that invariant by introducing and using DiagnosticsEngine::isIgnored() in place of individual level checks throughout lex, parse and sema. llvm-svn: 211005
* Recover from missing 'typename' in sizeof(T::InnerType)Reid Kleckner2014-06-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: 'sizeof' is a UnaryExprOrTypeTrait, and it can contain either a type or an expression. This change threads a RecoveryTSI parameter through the layers between TransformUnaryExprOrTypeTrait the point at which we look up the type. If lookup finds a single type result after instantiation, we now build TypeSourceInfo for it just like a normal transformation would. This fixes the last error in the hello world ATL app that I've been working with, and it now links and runs with clang. Please try it and file bugs! Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4108 llvm-svn: 210855
* Recover from missing typenames on template args for MSVC compatibilityReid Kleckner2014-06-101-10/+34
| | | | | | | | | | | | | While matching a non-type template argument against a known template type parameter we now modify the AST's TemplateArgumentLoc to assume the user wrote typename. Under -fms-compatibility, we downgrade our diagnostic from an error to an extwarn. Reviewed by: rsmith Differential Revision: http://reviews.llvm.org/D4049 llvm-svn: 210607
* PR14841: If partial substitution of explicitly-specified template argumentsRichard Smith2014-06-061-0/+11
| | | | | | | | results in a template having too many arguments, but all the trailing arguments are packs, that's OK if we have a partial pack substitution: the trailing pack expansions may end up empty. llvm-svn: 210350
* PR11306 - Variadic template fix-it suggestion. Recover from misplaced or ↵Nikola Smiljanic2014-06-061-3/+4
| | | | | | redundant ellipsis in parameter pack. llvm-svn: 210304
* Refactoring. Remove Owned method from Sema.Nikola Smiljanic2014-05-291-32/+23
| | | | llvm-svn: 209812
* Refactoring. Remove release and take methods from ActionResult. Rename ↵Nikola Smiljanic2014-05-291-13/+13
| | | | | | takeAs to getAs. llvm-svn: 209800
* [C++11] Use 'nullptr'. Sema edition.Craig Topper2014-05-261-64/+68
| | | | llvm-svn: 209613
* [modules] If a referenced-but-not-instantiated class template specializationRichard Smith2014-05-231-18/+1
| | | | | | | | | | gets explicitly specialized, don't reuse the previous class template specialization declaration as a new declaration. The benefit here is fairly marginal, it harms source fidelity, and this is horrible to model if the specialization was imported from another module (without this change, it asserts or worse). llvm-svn: 209552
* Permit duplicate explicit class instantiations if MSVCCompat is enabledWill Wilson2014-05-091-2/+6
| | | | llvm-svn: 208402
* Fix PR19169 [Crash on invalid attempting to specialize a template method as ↵Karthik Bhat2014-05-081-2/+11
| | | | | | | | | a template variable]. A template declaration of a template name can be null in case we have a dependent name or a set of function templates. Hence use dyn_cast_or_null instead of dyn_cast. Also improve the diagnostic emitted in this case. llvm-svn: 208313
* Fix a bunch of mislayered clang/Lex includes from SemaAlp Toker2014-05-031-4/+3
| | | | llvm-svn: 207896
* If we see an explicit instantiation declaration or definition of a functionRichard Smith2014-04-241-1/+6
| | | | | | | | | | | | | after we've already instantiated a definition for the function, pass it to the ASTConsumer again so that it knows the specialization kind has changed and can update the function's linkage. This only matters if we instantiate the definition of the function before we reach the end of the TU; this can happen in at least three different ways: C++11 constexpr functions, C++14 deduced return types, and functions instantiated within modules. llvm-svn: 207152
* Initial implementation of -modules-earch-all option, for searching for ↵John Thompson2014-04-231-1/+2
| | | | | | symbols in non-imported modules. llvm-svn: 206977
* SemaTemplate.cpp: Rework r206451. Removing an argument was really bad idea.NAKAMURA Takumi2014-04-171-4/+5
| | | | llvm-svn: 206452
* SemaTemplate.cpp: Appease msvc to get rid of default argument in lambda ↵NAKAMURA Takumi2014-04-171-2/+2
| | | | | | | | definition. clang\lib\Sema\SemaTemplate.cpp(1826) : error C2064: term does not evaluate to a function taking 1 arguments llvm-svn: 206451
* PR19340: If we see a declaration of a member of an unspecialized class templateRichard Smith2014-04-171-39/+46
| | | | | | | that looks like it might be an explicit specialization, don't recover as an explicit specialization (bypassing the check that would reject that). llvm-svn: 206444
* Refactor all the checking for missing 'template<>'s when a declaration has aRichard Smith2014-04-171-38/+60
| | | | | | template-id after its scope specifier into a single place. llvm-svn: 206442
* Render anonymous entities as '(anonymous <thing>)' (and lambdas as '(lambda ↵David Blaikie2014-04-021-2/+2
| | | | | | | | | | | | at ... )') For namespaces, this is consistent with mangling and GCC's debug info behavior. For structs, GCC uses <anonymous struct> but we prefer consistency between all anonymous entities but don't want to confuse them with template arguments, etc, so we'll just go with parens in all cases. llvm-svn: 205398
* [C++11] Replacing FunctionProtoType iterators param_type_begin() and ↵Aaron Ballman2014-03-171-4/+2
| | | | | | param_type_end() with iterator_range param_types(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 204045
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-121-3/+3
| | | | | | class. llvm-svn: 203640
* [C++11] Replacing FunctionDecl iterators param_begin() and param_end() with ↵Aaron Ballman2014-03-071-4/+2
| | | | | | iterator_range params(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203248
* Remove accidentally-committed debugging statement. Thanks to Faisal Vali forRichard Smith2014-02-211-1/+0
| | | | | | spotting this! llvm-svn: 201871
* PR16519, PR18009: When checking a partial specialization for uses of its ownRichard Smith2014-02-091-31/+94
| | | | | | | | | | template parameters, don't look for parameters of outer templates. If a problem is found in a default template argument, point the diagnostic at the partial specialization (with a note pointing at the default argument) instead of pointing it at the default argument and leaving it unclear which partial specialization os problematic. llvm-svn: 201031
* MS ABI: Tweak pointer-to-member mangling/inheritance model selectionDavid Majnemer2014-02-061-0/+3
| | | | | | | | | | | | Properly determine the inheritance model when dealing with nullptr: - If a nullptr template argument is being checked against pointer-to-member parameter, nail down an inheritance model. N.B. We will chose an inheritance model even if we won't ultimately choose the template to instantiate! Cooky, right? - Null pointer-to-datamembers have a virtual base table offset of -1, not zero. Previously, we chose an offset of 0. llvm-svn: 200920
OpenPOWER on IntegriCloud