summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Variable templates: handle instantiation of static data member templatesRichard Smith2013-09-271-1/+2
| | | | | | appropriately, especially when they appear within class templates. llvm-svn: 191548
* Fix error recovery when a return type correction includes a new name specifier.Kaelyn Uhrain2013-09-261-1/+6
| | | | llvm-svn: 191459
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-09-261-3/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix -Wmissing-variable-declarations regression.Eli Friedman2013-09-241-1/+1
| | | | | | | | This issue was introduced in r181677. PR17349. llvm-svn: 191339
* Parse: Don't crash during parsing if we lack a simple-type-specifierDavid Majnemer2013-09-221-0/+1
| | | | | | | | | | | | | | | | | Summary: Parsing cast expressions during error recovery can put us in a bad state. Check to see if the token for a simple-type-specifier makes sense before further parsing. Fixes PR17255. Reviewers: rsmith, doug.gregor, CornedBee, eli.friedman CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1696 llvm-svn: 191159
* Switch the semantic DeclContext for a block-scope declaration of a function orRichard Smith2013-09-201-33/+87
| | | | | | | | | | | | | | variable from being the function to being the enclosing namespace scope (in C++) or the TU (in C). This allows us to fix a selection of related issues where we would build incorrect redeclaration chains for such declarations, and fail to notice type mismatches. Such declarations are put into a new IdentifierNamespace, IDNS_LocalExtern, which is only found when searching scopes, and not found when searching DeclContexts. Such a declaration is only made visible in its DeclContext if there are no non-LocalExtern declarations. llvm-svn: 191064
* Remove a bogus diagnostic preventing static data member templates from beingRichard Smith2013-09-181-15/+0
| | | | | | defined with no initializer. llvm-svn: 190970
* Revert "Revert "[-cxx-abi microsoft] Mangle local TagDecls appropriately""David Majnemer2013-09-171-2/+10
| | | | | | This reverts commit r190895 which reverted r190892. llvm-svn: 190904
* Revert "[-cxx-abi microsoft] Mangle local TagDecls appropriately"David Majnemer2013-09-171-10/+2
| | | | | | This reverts commit r190892. llvm-svn: 190895
* [-cxx-abi microsoft] Mangle local TagDecls appropriatelyDavid Majnemer2013-09-171-2/+10
| | | | | | | | | | | | | | | | | | | | | | | Summary: When selecting a mangling for an anonymous tag type: - We should first try it's typedef'd name. - If that doesn't work, we should mangle in the name of the declarator that specified it as a declaration specifier. - If that doesn't work, fall back to a static mangling of <unnamed-type>. This should make our anonymous type mangling compatible. This partially fixes PR16994; we would need to have an implementation of scope numbering to get it right (a separate issue). Reviewers: rnk, rsmith, rjmccall, cdavis5x CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1540 llvm-svn: 190892
* [-cxx-abi microsoft] Correctly identify Win32 entry pointsDavid Majnemer2013-09-161-1/+27
| | | | | | | | | | | | | | | | | | | Summary: This fixes several issues with the original implementation: - Win32 entry points cannot be in namespaces - A Win32 entry point cannot be a function template, diagnose if we it. - Win32 entry points cannot be overloaded. - Win32 entry points implicitly return, similar to main. Reviewers: rnk, rsmith, whunt, timurrrr Reviewed By: rnk CC: cfe-commits, nrieck Differential Revision: http://llvm-reviews.chandlerc.com/D1683 llvm-svn: 190818
* Fix regression from r190382.Eli Friedman2013-09-101-8/+0
| | | | | | | | | Make sure we perform the correct "referenced-but-not-used" check for static member constants. Fixes bug reported on cfe-commits by Alexey Samsonov. llvm-svn: 190437
* [ms-cxxabi] Implement guard variables for static initializationReid Kleckner2013-09-101-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Static locals requiring initialization are not thread safe on Windows. Unfortunately, it's possible to create static locals that are actually externally visible with inline functions and templates. As a result, we have to implement an initialization guard scheme that is compatible with TUs built by MSVC, which makes thread safety prohibitively difficult. MSVC's scheme is that every function that requires a guard gets an i32 bitfield. Each static local is assigned a bit that indicates if it has been initialized, up to 32 bits, at which point a new bitfield is created. MSVC rejects inline functions with more than 32 static locals, and the externally visible mangling (?_B) only allows for one guard variable per function. On Eli's recommendation, I used MangleNumberingContext to track which bit each static corresponds to. Implements PR16888. Reviewers: rjmccall, eli.friedman Differential Revision: http://llvm-reviews.chandlerc.com/D1416 llvm-svn: 190427
* Make -Wunused warning rules more consistent.Eli Friedman2013-09-101-16/+26
| | | | | | | | | | | | | | | This patch does a few different things. This patch improves unused var diags for const vars: we no longer unconditionally suppress diagnostics for const vars, instead only suppressing the diagnostic when the declaration appears to be useful. This patch also makes us more consistently use whether a variable/function is declared in the main file to suppress diagnostics where appropriate. Fixes <rdar://problem/14907887>. llvm-svn: 190382
* Preserve exception specs in function decl merging.Eli Friedman2013-09-061-2/+4
| | | | | | | | | Exception specs are not part of the canonical type, but we shouldn't drop them just because we merged a noreturn attribute. Fixes PR17110. llvm-svn: 190206
* Note when a decl is used in AST files.Eli Friedman2013-09-051-4/+2
| | | | | | | | | | | | | | | When an AST file is built based on another AST file, it can use a decl from the fist file, and therefore mark the "isUsed" bit. We need to note this in the AST file so that the bit is set correctly when the second AST file is loaded. This patch introduces the distinction between setIsUsed() and markUsed() so that we don't call into the ASTMutationListener callback when it wouldn't be appropriate. Fixes PR16635. llvm-svn: 190016
* Switched FormatAttr to using an IdentifierArgument instead of a ↵Aaron Ballman2013-09-031-3/+5
| | | | | | StringArgument since that is a more accurate modeling. llvm-svn: 189851
* Refactor computation of whether a variable declaration's type should be mergedRichard Smith2013-09-031-39/+35
| | | | | | with a prior declaration. No functionality change intended. llvm-svn: 189850
* Remove Inheritable/NonInheritable flags from ProcessDeclAttributes. They don'tRichard Smith2013-08-291-6/+1
| | | | | | do anything useful. llvm-svn: 189548
* Delete CC_Default and use the target default CC everywhereReid Kleckner2013-08-271-50/+46
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Makes functions with implicit calling convention compatible with function types with a matching explicit calling convention. This fixes things like calls to qsort(), which has an explicit __cdecl attribute on the comparator in Windows headers. Clang will now infer the calling convention from the declarator. There are two cases when the CC must be adjusted during redeclaration: 1. When defining a non-inline static method. 2. When redeclaring a function with an implicit or mismatched convention. Fixes PR13457, and allows clang to compile CommandLine.cpp for the Microsoft C++ ABI. Excellent test cases provided by Alexander Zinenko! Reviewers: rsmith Differential Revision: http://llvm-reviews.chandlerc.com/D1231 llvm-svn: 189412
* Cleanup of OpaquePtr. No functionality changes.Serge Pavlov2013-08-271-1/+1
| | | | | | | | - Some documenation were added. - Usages of OpaquePtr<A>.getAsVal<A>() were replaced by OpaquePtr<A>.get(). - Methods getAs and getAsVal were renamed to getPtrTo and getPtrAs respectively. llvm-svn: 189346
* Revert "Implement a rudimentary form of generic lambdas."Manuel Klimek2013-08-221-42/+3
| | | | | | This reverts commit 606f5d7a99b11957e057e4cd1f55f931f66a42c7. llvm-svn: 189004
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-08-221-3/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Refactor for clarity and simplicity.Larisse Voufo2013-08-221-48/+42
| | | | llvm-svn: 188974
* Improve support for static data member templates. This revision still has at ↵Larisse Voufo2013-08-221-6/+1
| | | | | | least one bug, as it does not respect the variable template specialization hierarchy well. llvm-svn: 188969
* Refactor all diagnosing of TypoCorrections through a common function, inRichard Smith2013-08-171-136/+79
| | | | | | | preparation for teaching this function how to diagnose a correction that includes importing a module. llvm-svn: 188602
* Don't reject attribute used in an "extern const" variable definition.Rafael Espindola2013-08-161-0/+7
| | | | | | | Before this patch we would warn and drop the attribute in extern const char test3[] __attribute__((used)) = ""; llvm-svn: 188588
* PR16875: The return type of a dependent function type is visible when it'sRichard Smith2013-08-141-3/+22
| | | | | | | | | | | 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
* Bug fix: disallow a variable template to be redeclared as a non-templated ↵Larisse Voufo2013-08-141-10/+21
| | | | | | variable llvm-svn: 188350
* Fix implementation of C11 6.2.7/4 and C++11 [dcl.array]p3:Richard Smith2013-08-131-36/+97
| | | | | | | | | | | | | When a local extern declaration redeclares some other entity, the type of that entity is merged with the prior type if the prior declaration is visible (in C) or is declared in the same scope (in C++). - Make LookupRedeclarationWithLinkage actually work in C++, use it in the right set of cases, and make it track whether it found a shadowed declaration. - Track whether we found a declaration in the same scope (for C++) including across serialization and template instantiation. llvm-svn: 188307
* Fix crash w/BlockDecl and invalid qualified decl.Eli Friedman2013-08-121-1/+4
| | | | | | | | | I'm not really satisfied with the ad-hoc nature of Sema::diagnoseQualifiedDeclaration, but I'm not sure how to fix it. Fixes <rdar://problem/14639501>. llvm-svn: 188208
* Omit llvm:: before ArrayRef, as we have using llvm::ArrayRef in ↵Robert Wilhelm2013-08-091-8/+8
| | | | | | include/clang/Basic/LLVM.h. llvm-svn: 188089
* Implement [class.friend]p11's special name lookup rules for friend declarationsRichard Smith2013-08-091-29/+37
| | | | | | | | of local classes. We were previously handling this by performing qualified lookup within a function declaration(!!); replace it with the proper scope lookup. llvm-svn: 188050
* Moved diagnosis of forward declarations of variable templates from Parser to ↵Larisse Voufo2013-08-061-2/+18
| | | | | | Sema. llvm-svn: 187768
* Started implementing variable templates. Top level declarations should be ↵Larisse Voufo2013-08-061-37/+208
| | | | | | fully supported, up to some limitations documented as FIXMEs or TODO. Static data member templates work very partially. Static data member templates of class templates need particular attention... llvm-svn: 187762
* Error on more illegal kernel argument types for OpenCLMatt Arsenault2013-07-231-18/+170
| | | | | | | | bool, half, pointers and structs / unions containing any of these are not allowed. Does not yet reject size_t and related integer types that are also disallowed. llvm-svn: 186908
* Fixed implementation of C89 6.5.7 p3.Enea Zaffanella2013-07-221-0/+1
| | | | | | Warning should be emitted only for InitListExpr nodes. llvm-svn: 186859
* Implement the part of C89 6.5.7 p3 requiring a constant initializer listEnea Zaffanella2013-07-221-3/+13
| | | | | | when initializing aggregate/union types, no matter if static or not. llvm-svn: 186817
* Convert Sema::MatchTemplateParametersToScopeSpecifier to ArrayRef.Robert Wilhelm2013-07-211-27/+14
| | | | llvm-svn: 186794
* add type attribute warn_unused, for -Wunused-variable warnings (pr#14253)Lubos Lunak2013-07-201-2/+2
| | | | | | | | | The functionality is equivalent to the GCC attribute. Variables of tagged types will be warned about as unused if they are not used in any way except for possible (even non-trivial) ctors/dtors called. Useful for tagging classes like std::string (which is not part of this commit). llvm-svn: 186765
* Reinstate r186040, with additional fixes and more test coverage (reverted inRichard Smith2013-07-171-8/+4
| | | | | | | | | | | | | r186331). Original commit log: If we friend a declaration twice, that should not make it visible to name lookup in the surrounding context. Slightly rework how we handle friend declarations to inherit the visibility of the prior declaration, rather than setting a friend declaration to be visible whenever there was a prior declaration. llvm-svn: 186546
* MS wide bitfield error check in SemaReid Kleckner2013-07-171-5/+7
| | | | | | | | | | | | | cl.exe treats wide bitfields as an error. This patch causes them to be an error if IsMsStruct is true, as it is in straight C. Patch by Warren Hunt! Reviewers: eli.friedman Differential Revision: http://llvm-reviews.chandlerc.com/D1125 llvm-svn: 186536
* Make Expr::isConstantInitializer match IRGen.Eli Friedman2013-07-161-4/+10
| | | | | | | | | | Sema needs to be able to accurately determine what will be emitted as a constant initializer and what will not, so we get accurate errors in C and accurate -Wglobal-constructors warnings in C++. This makes Expr::isConstantInitializer match CGExprConstant as closely as possible. llvm-svn: 186464
* Merge attributes on typedef decls.Eli Friedman2013-07-161-0/+2
| | | | | | | | | Not completely sure this is right, but it's clearly better than what we did before this commit (effectively dropping the attribute). <rdar://problem/14413117> llvm-svn: 186373
* Re-revert r86040, which was un-reverted in r186199.Chandler Carruth2013-07-151-4/+8
| | | | | | | | | | | | | | | This breaks the build of basic patterns with repeated friend declarations. See the added test case in SemaCXX/friend.cpp or the test case reported to the original commit log. Original commit log: If we friend a declaration twice, that should not make it visible to name lookup in the surrounding context. Slightly rework how we handle friend declarations to inherit the visibility of the prior declaration, rather than setting a friend declaration to be visible whenever there was a prior declaration. llvm-svn: 186331
* Unrevert r186040, reverted in r186185, with fix for PR16597.Richard Smith2013-07-121-8/+4
| | | | | | | | | | | Original commit log: If we friend a declaration twice, that should not make it visible to name lookup in the surrounding context. Slightly rework how we handle friend declarations to inherit the visibility of the prior declaration, rather than setting a friend declaration to be visible whenever there was a prior declaration. llvm-svn: 186199
* Revert r186040 to fix PR16597 while Richard investigates what the bestChandler Carruth2013-07-121-4/+8
| | | | | | | | | | | | | fix is. Original commit log: If we friend a declaration twice, that should not make it visible to name lookup in the surrounding context. Slightly rework how we handle friend declarations to inherit the visibility of the prior declaration, rather than setting a friend declaration to be visible whenever there was a prior declaration. llvm-svn: 186185
* If we friend a declaration twice, that should not make it visible to nameRichard Smith2013-07-101-8/+4
| | | | | | | | | lookup in the surrounding context. Slightly rework how we handle friend declarations to inherit the visibility of the prior declaration, rather than setting a friend declaration to be visible whenever there was a prior declaration. llvm-svn: 186040
* More local mangling fixes.Eli Friedman2013-07-101-3/+34
| | | | | | | | | | | | Compute mangling numbers for externally visible local variables and tags. Change the mangler to consistently use discriminators where necessary. Tweak the scheme we use to number decls which are not externally visible to avoid unnecessary discriminators in common cases now that we request them more consistently. Fixes <rdar://problem/14204721>. llvm-svn: 185986
* ArrayRef'ize Sema::FinalizeDeclaratorGroup, Sema::BuildDeclaratorGroup andRafael Espindola2013-07-091-19/+17
| | | | | | | | Sema::ActOnDocumentableDecls. Patch by Robert Wilhelm. llvm-svn: 185931
OpenPOWER on IntegriCloud