summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclCXX.cpp
Commit message (Collapse)AuthorAgeFilesLines
* When a special member is explicitly defaulted outside its class, and we rejectRichard Smith2014-01-221-0/+1
| | | | | | | the defaulting because it would delete the member, produce additional notes explaining why the member is implicitly deleted. llvm-svn: 199829
* Introduce and use Decl::getAsFunction() to simplify templated function checksAlp Toker2014-01-221-7/+1
| | | | | | | | | | | | | | Lift the getFunctionDecl() utility out of the parser into a general Decl::getAsFunction() and use it to simplify other parts of the implementation. Reduce isFunctionOrFunctionTemplate() to a simple type check that works the same was as the other is* functions and move unwrapping of shadowed decls to callers so it doesn't get run twice. Shuffle around canSkipFunctionBody() to reduce virtual dispatch on ASTConsumer. There's no need to query when we already know the body can't be skipped. llvm-svn: 199794
* Enforce restrictions that 'main' is not allowed to be deleted, or to be used byRichard Smith2014-01-221-0/+5
| | | | | | | | the program, in C++. (We allow the latter as an extension, since we've always permitted it, and GCC does the same, and our supported C++ ABIs don't do anything special in main.) llvm-svn: 199782
* Update FunctionTypeLoc and related names to match r199686Alp Toker2014-01-211-8/+8
| | | | llvm-svn: 199699
* Rename FunctionProtoType accessors from 'arguments' to 'parameters'Alp Toker2014-01-201-18/+20
| | | | | | | | | | | | | | | | | 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
* PR18477: Create a function scope representing the constructor call whenRichard Smith2014-01-171-7/+18
| | | | | | | | handling C++11 default initializers. Without this, other parts of Sema (such as lambda capture) would think the default initializer is part of the surrounding function scope. llvm-svn: 199453
* Distinguish between attributes explicitly written at the request of the ↵Aaron Ballman2014-01-161-2/+2
| | | | | | | | user, and attributes implicitly generated to assist in bookkeeping by the compiler. This is done so by table generating a CreateImplicit method for each attribute. Additionally, remove the optional nature of the spelling list index when creating attributes. This is supported by table generating a Spelling enumeration when the spellings for an attribute are distinct enough to warrant it. llvm-svn: 199378
* Fix for PR9812: warn about bool instead of _Bool.Erik Verbruggen2014-01-151-1/+2
| | | | llvm-svn: 199311
* Rename language option MicrosoftMode to MSVCCompatAlp Toker2014-01-141-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | There's been long-standing confusion over the role of these two options. This commit makes the necessary changes to differentiate them clearly, following up from r198936. MicrosoftExt (aka. fms-extensions): Enable largely unobjectionable Microsoft language extensions to ease portability. This mode, also supported by gcc, is used for building software like FreeBSD and Linux kernel extensions that share code with Windows drivers. MSVCCompat (aka. -fms-compatibility, formerly MicrosoftMode): Turn on a special mode supporting 'heinous' extensions for drop-in compatibility with the Microsoft Visual C++ product. Standards-compilant C and C++ code isn't guaranteed to work in this mode. Implies MicrosoftExt. Note that full -fms-compatibility mode is currently enabled by default on the Windows target, which may need tuning to serve as a reasonable default. See cfe-commits for the full discourse, thread 'r198497 - Move MS predefined type_info out of InitializePredefinedMacros' No change in behaviour. llvm-svn: 199209
* Add a new attribute 'enable_if' which can be used to control overload ↵Nick Lewycky2014-01-111-0/+12
| | | | | | resolution based on the values of the function arguments at the call site. llvm-svn: 198996
* PR18234: Mark a tag definition as invalid early if it appears in aRichard Smith2014-01-081-4/+5
| | | | | | | | type-specifier in C++. Some checks will assert in this case otherwise (in particular, the access specifier may be missing if this happens inside a class definition, due to a violation of an AST invariant). llvm-svn: 198721
* It turns out the problem was a bit more wide-spread. Removing a lot of ↵Aaron Ballman2014-01-031-11/+7
| | | | | | | | unneeded typecasts. getScopeRep() already returns a NestedNameSpecifier. No functional changes intended. llvm-svn: 198414
* Removing an unneeded typecast. getScopeRep() already returns a ↵Aaron Ballman2014-01-031-1/+1
| | | | | | NestedNameSpecifier. llvm-svn: 198413
* [ms-cxxabi] Don't do destructor check on declarations if the dtor is deletedHans Wennborg2013-12-171-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | We would previously emit redundant diagnostics for the following code: struct S { virtual ~S() = delete; void operator delete(void*, int); void operator delete(void*, double); } s; First we would check on ~S() and error about the ambigous delete functions, and then we would error about using the deleted destructor. If the destructor is deleted, there's no need to check it. Also, move the check from Sema::ActOnFields to CheckCompleteCXXClass. These are run at almost the same time, called from ActOnFinishCXXMemberSpecification. However, CHeckCompleteCXXClass may mark a defaulted destructor as deleted, and if that's the case we don't want to check it. Differential Revision: http://llvm-reviews.chandlerc.com/D2421 llvm-svn: 197509
* Better diagnostic for static override when methods are thiscall by defaultHans Wennborg2013-12-111-0/+7
| | | | | | | | | | | | | | | | | | Methods are thiscall by default in the MS ABI, and also in MinGW targetting GCC 4.7 or later. This changes the diagnostic from the technically correct but hard to understand: virtual function 'foo' has different calling convention attributes ('void ()') than the function it overrides (which has calling convention 'void () __attribute__((thiscall))') to the more intuitive and also correct: 'static' member function 'foo' overrides a virtual function We already have a test for this. Let's just run it in both ABI modes. Differential Revision: http://llvm-reviews.chandlerc.com/D2375 llvm-svn: 197055
* Tiny cleanup, as suggested by David Blaikie.Richard Smith2013-12-101-2/+2
| | | | llvm-svn: 196959
* Implement DR1460: fix handling of default initializers in unions; don't allowRichard Smith2013-12-101-27/+91
| | | | | | | | | more than one such initializer in a union, make mem-initializers override default initializers for other union members, handle anonymous unions with anonymous struct members better. Fix a couple of semi-related bugs exposed by the tests for same. llvm-svn: 196892
* Fix a tranche of comment, test and doc typosAlp Toker2013-12-051-1/+1
| | | | llvm-svn: 196510
* PR17983: Fix crasher bug in C++1y mode when performing a non-global arrayRichard Smith2013-12-051-0/+4
| | | | | | | delete on a class which has no array cookie and has no class-specific operator new. llvm-svn: 196488
* Implement DR482: namespace members can be redeclared with a qualified nameRichard Smith2013-12-051-8/+10
| | | | | | | | | | within their namespace, and such a redeclaration isn't required to be a definition any more. Update DR status page to say Clang 3.4 instead of SVN and add new Clang 3.5 category (but keep Clang 3.4 yellow for now). llvm-svn: 196481
* Unify lookup from within not-yet-defined defaulted special members: use commonRichard Smith2013-11-271-47/+64
| | | | | | | code for handling triviality, deletedness and constexpr. Fix a few bugs in these, particularly related to mutable members, and remove some dead code. llvm-svn: 195809
* Take cv-qualifiers on fields of class type into account when determiningRichard Smith2013-11-251-0/+4
| | | | | | whether a defaulted special member function should be deleted. llvm-svn: 195620
* Add class-specific operator new to Decl hierarchy. This guarantees that DeclsRichard Smith2013-11-221-4/+2
| | | | | | | | | | | | | can't accidentally be allocated the wrong way (missing prefix data for decls from AST files, for instance) and simplifies the CreateDeserialized functions a little. An extra DeclContext* parameter to the not-from-AST-file operator new allows us to ensure that we don't accidentally call the wrong one when deserializing (when we don't have a DeclContext), allows some extra checks, and prepares for some planned modules-related changes to Decl allocation. No functionality change intended. llvm-svn: 195426
* Don't reject dependent range-based for loops in constexpr functions. The loopRichard Smith2013-11-151-1/+1
| | | | | | variable isn't really uninitialized, it's just not initialized yet. llvm-svn: 194767
* Issue a diagnostic if we see a templated friend declaration that we do notRichard Smith2013-11-081-0/+2
| | | | | | support. llvm-svn: 194273
* Issue a diagnostic if an implicitly-defined move assignment operator would moveRichard Smith2013-11-041-10/+99
| | | | | | | the same virtual base class multiple times (and the move assignment is used, and the move assignment for the virtual base is not trivial). llvm-svn: 193977
* Update a comment to match current core issues list.Richard Smith2013-11-041-8/+3
| | | | llvm-svn: 193970
* Implement final resolution of DR1402: implicitly-declared move operators thatRichard Smith2013-11-041-154/+15
| | | | | | | | | | | would be deleted are still declared, but are ignored by overload resolution. Also, don't delete such members if a subobject has no corresponding move operation and a non-trivial copy. This causes us to implicitly declare move operations in more cases, but risks move-assigning virtual bases multiple times in some circumstances (a warning for that is to follow). llvm-svn: 193969
* Sema: Disallow inheriting from classes with flexible array membersDavid Majnemer2013-11-021-0/+12
| | | | | | | | | | | Flexible array members inherently index off of the end of their parent type. We shouldn't allow this type to be used as a base, virtual or otherwise, because indexing off the end may find us inside of another base or the derived types members. llvm-svn: 193923
* Sema: Remove stray whitespace around Sema::CheckBaseSpecifierDavid Majnemer2013-11-021-3/+3
| | | | llvm-svn: 193922
* Simplify and refactor the uninitialized field warning.Richard Trieu2013-10-251-190/+90
| | | | | | | | | | | Change the uninitialized field warnings so that field initializers are checked inside the constructor. Previously, in class initializers were checked separately. Running one set of checks also simplifies the logic for preventing duplicate warnings. Added new checks to warn when an uninitialized field is used in base class initialization. Also fixed misspelling of uninitialized and moved all code for this warning together. llvm-svn: 193386
* Make UsingShadowDecls redeclarable. This fixes some visibility problems withRichard Smith2013-10-231-19/+25
| | | | | | | | | | modules. With this fixed, I no longer see any test regressions in the libc++ test suite when enabling a single-module module.map for libc++ (other than issues with my system headers). llvm-svn: 193219
* Allow CorrectTypo to replace CXXScopeSpecifiers that refer to classes.Kaelyn Uhrain2013-10-191-3/+10
| | | | | | | | | | | Now that CorrectTypo knows how to correctly search classes for typo correction candidates, there is no good reason to only replace an existing CXXScopeSpecifier if it refers to a namespace. While the actual enablement was a matter of changing a single comparison, the fallout from enabling the functionality required a lot more code changes (including my two previous commits). llvm-svn: 193020
* Fix missed exception spec checks and crashesAlp Toker2013-10-181-23/+24
| | | | | | | | | | | | | | | | | | | Delayed exception specification checking for defaulted members and virtual destructors are both susceptible to mutation during iteration so we need to swap and process the worklists. This resolves both accepts-invalid and rejects-valid issues and moreover fixes potential invalid memory access as the contents of the vectors change during iteration and recursive template instantiation. Checking can be further delayed where parent classes aren't yet fully defined. This patch adds two assertions at end of TU to ensure no specs are left unchecked as was happenning before the fix, plus a test case from Marshall Clow for the defaulted member crash extracted from the libcxx headers. Reviewed by Richard Smith. llvm-svn: 192947
* [-fms-extensions] Permit 'override' in C++98 and 'sealed' as a synonym for ↵David Majnemer2013-10-181-10/+19
| | | | | | | | | | | | | | 'final' Summary: Some MS headers use these features. Reviewers: rnk, rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1948 llvm-svn: 192936
* Revert "Fix missed exception spec checks and crashes"Alp Toker2013-10-171-23/+23
| | | | | | | | | | | The changes caused the sanitizer bot to hang: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/2311 Needs investigation. This reverts commit r192914. llvm-svn: 192921
* Fix missed exception spec checks and crashesAlp Toker2013-10-171-23/+23
| | | | | | | | | | | | | | | | | | Delayed exception specification checking for defaulted members and virtual destructors are both susceptible to mutation during iteration so we need to process the worklists fully. This resolves both accepts-invalid and rejects-valid issues and moreover fixes potential invalid memory access as the contents of the vectors change during iteration and recursive template instantiation. This patch also adds two assertions at end of TU to ensure no specs are left unchecked as was happenning before the fix, plus a test case from Marshall Clow for the defaulted member crash extracted from the libcxx headers. Reviewed by Richard Smith. llvm-svn: 192914
* Rename some functions for consistency.Rafael Espindola2013-10-171-1/+1
| | | | | | Every other function in Redeclarable.h was using Decl instead of Declaration. llvm-svn: 192900
* PR17567: Improve diagnostic for a mistyped constructor name. If we see somethingRichard Smith2013-10-151-0/+26
| | | | | | | | | | | that looks like a function declaration, except that it's missing a return type, try typo-correcting it to the relevant constructor name. In passing, fix a bug where the missing-type-specifier recovery codepath would drop a preceding scope specifier on the floor, leading to follow-on diagnostics and incorrect recovery for the auto-in-c++98 hack. llvm-svn: 192644
* Adds Microsoft compatiable C++ record layout code to clang.Warren Hunt2013-10-111-0/+7
| | | | llvm-svn: 192494
* Convert anachronistic use of 'void *' to 'DeclContext *' in Scope that was a ↵Ted Kremenek2013-10-081-1/+1
| | | | | | holdover from the long-dead Action interface. llvm-svn: 192203
* Add support for WG21 N3599 (literal operator template for strings) as a GNURichard Smith2013-10-071-3/+25
| | | | | | | | | extension. The GCC folks have decided to support this even though the standard committee have not yet approved this feature. Patch by Hristo Venev! llvm-svn: 192128
* Fix windows newlines :(Faisal Vali2013-09-291-1/+1
| | | | llvm-svn: 191641
* Implement conversion to function pointer for generic lambdas without captures.Faisal Vali2013-09-291-38/+73
| | | | | | | | | | | | | | | | 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
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-09-261-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Simplify code to equivalent code. No need to test for null after cast<>, useNick Lewycky2013-09-221-9/+5
| | | | | | | takeAs<> instead of cast<>(.take()). Fix 80-column violation in whitespace after comment. llvm-svn: 191170
* Modify the uninitialized field visitor to detect uninitialized use across theRichard Trieu2013-09-201-32/+180
| | | | | | | | | | | | | | | | | | fields in the class. This allows a better checking of member intiailizers and in class initializers in regards to initialization ordering. For instance, this code will now produce warnings: class A { int x; int y; A() : x(y) {} // y is initialized after x, warn here A(int): y(x) {} // default initialization of leaves x uninitialized, warn here }; Several test cases were updated with -Wno-uninitialized to silence this warning. llvm-svn: 191068
* Switch the semantic DeclContext for a block-scope declaration of a function orRichard Smith2013-09-201-5/+15
| | | | | | | | | | | | | | 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
* Move the uninitialized field check to after all the field initializers are addedRichard Trieu2013-09-161-17/+39
| | | | | | to the CXXConstructorDecl so that information from the constructor can be used. llvm-svn: 190810
* Pass additional information around the uninitialized field visitor.Richard Trieu2013-09-161-7/+12
| | | | llvm-svn: 190805
OpenPOWER on IntegriCloud