summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaDeclCXX.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Diagnose uses of deleted destructors and inaccessible defaulted destructors.Richard Smith2012-02-181-6/+8
| | | | | | | | | | | We had two separate issues here: firstly, varions functions were assuming that they did not need to perform semantic checks on trivial destructors (this is not true in C++11, where a trivial destructor can nonetheless be private or deleted), and a bunch of DiagnoseUseOfDecl calls were missing for uses of destructors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150866 91177308-0d34-0410-b5e6-96231b3b80d8
* Initial refactoring of 'ShouldDeleteSpecialMember', in preparation for providingRichard Smith2012-02-181-611/+306
| | | | | | | | | | decent diagnostics. Finish the work of combining all the 'ShouldDelete' functions into one. In unifying the code, fix a minor bug where an anonymous union with a deleted default constructor as a member of a union wasn't being considered as making the outer union's default constructor deleted. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150862 91177308-0d34-0410-b5e6-96231b3b80d8
* Rework the Sema/AST/IRgen dance for the lambda closure type'sDouglas Gregor2012-02-171-2/+35
| | | | | | | | | | | | | | | | | | | | | conversion to function pointer. Rather than having IRgen synthesize the body of this function, we instead introduce a static member function "__invoke" with the same signature as the lambda's operator() in the AST. Sema then generates a body for the conversion to function pointer which simply returns the address of __invoke. This approach makes it easier to evaluate a call to the conversion function as a constant, makes the linkage of the __invoke function follow the normal rules for member functions, and may make life easier down the road if we ever want to constexpr'ify some of lambdas. Note that IR generation is responsible for filling in the body of __invoke (Sema just adds a dummy body), because the body can't generally be expressed in C++. Eli, please review! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150783 91177308-0d34-0410-b5e6-96231b3b80d8
* Implicitly define a lambda's conversion functions (to functionDouglas Gregor2012-02-161-1/+54
| | | | | | | | | | | | | | pointers and block pointers). We use dummy definitions to keep the invariant that an implicit, used definition has a body; IR generation will substitute the actual contents, since they can't be represented as C++. For the block pointer case, compute the copy-initialization needed to capture the lambda object in the block, which IR generation will need later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150645 91177308-0d34-0410-b5e6-96231b3b80d8
* When overload resolution picks an implicitly-deleted special memberDouglas Gregor2012-02-151-0/+6
| | | | | | | | | | | function, provide a specialized diagnostic that indicates the kind of special member function (default constructor, copy assignment operator, etc.) and that it was implicitly deleted. Add a hook where we can provide more detailed information later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150611 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement C++ core issue 974, which permits default arguments forDouglas Gregor2012-02-141-1/+15
| | | | | | | | | lambda expressions. Because these issue was pulled back from Ready status at the Kona meeting, we still emit an ExtWarn when using default arguments for lambda expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150519 91177308-0d34-0410-b5e6-96231b3b80d8
* Generalize -Wempty-body: warn when statement body is empty (closes: PR11329)Dmitri Gribenko2012-02-141-10/+20
| | | | | | | | | | | | | | | | * if, switch, range-based for: warn if semicolon is on the same line. * for, while: warn if semicolon is on the same line and either next statement is compound statement or next statement has more indentation. Replacing the semicolon with {} or moving the semicolon to the next line will always silence the warning. Tests from SemaCXX/if-empty-body.cpp merged into SemaCXX/warn-empty-body.cpp. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150515 91177308-0d34-0410-b5e6-96231b3b80d8
* Use a simpler (and more efficient) pattern to pad vectors.Benjamin Kramer2012-02-141-2/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150475 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix another issue introduced by the proposed wording for core issue 1358: sinceRichard Smith2012-02-141-3/+12
| | | | | | | | | | | the instantiation of a constexpr function temploid is now always constexpr, a defaulted constexpr function temploid is often ill-formed by the rule in [dcl.fct.def.default]p2 that an explicitly-defaulted constexpr function must have a constexpr implicit definition. To avoid making loads of completely reasonable code ill-formed, do not apply that rule to templates. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150453 91177308-0d34-0410-b5e6-96231b3b80d8
* Update constexpr implementation to match CWG's chosen approach for core issuesRichard Smith2012-02-131-79/+37
| | | | | | | | | | | | | | | | | | | | | 1358, 1360, 1452 and 1453. - Instantiations of constexpr functions are always constexpr. This removes the need for separate declaration/definition checking, which is now gone. - This makes it possible for a constexpr function to be virtual, if they are only dependently virtual. Virtual calls to such functions are not constant expressions. - Likewise, it's now possible for a literal type to have virtual base classes. A constexpr constructor for such a type cannot actually produce a constant expression, though, so add a special-case diagnostic for a constructor call to such a type rather than trying to evaluate it. - Classes with trivial default constructors (for which value initialization can produce a fully-initialized value) are considered literal types. - Classes with volatile members are not literal types. - constexpr constructors can be members of non-literal types. We do not yet use static initialization for global objects constructed in this way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150359 91177308-0d34-0410-b5e6-96231b3b80d8
* Lambdas have a deleted default constructor and a deleted copyDouglas Gregor2012-02-121-0/+13
| | | | | | | assignment operator, per C++ [expr.prim.lambda]p19. Make it so. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150345 91177308-0d34-0410-b5e6-96231b3b80d8
* Change the way we store initialization kinds so that all direct inits can ↵Sebastian Redl2012-02-121-20/+30
| | | | | | distinguish between list and parens form. This allows us to correctly diagnose the last test cases from litb. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150343 91177308-0d34-0410-b5e6-96231b3b80d8
* Represent C++ direct initializers as ParenListExprs before semantic analysisSebastian Redl2012-02-111-252/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | instead of having a special-purpose function. - ActOnCXXDirectInitializer, which was mostly duplication of AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days ago), is dropped completely. - MultiInitializer, which was an ugly hack I added, is dropped again. - We now have the infrastructure in place to distinguish between int x = {1}; int x({1}); int x{1}; -- VarDecl now has getInitStyle(), which indicates which of the above was used. -- CXXConstructExpr now has a flag to indicate that it represents list- initialization, although this is not yet used. - InstantiateInitializer was renamed to SubstInitializer and simplified. - ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which always produces a ParenListExpr. Placed that so far failed to convert that back to a ParenExpr containing comma operators have been fixed. I'm pretty sure I could have made a crashing test case before this. The end result is a (I hope) considerably cleaner design of initializers. More importantly, the fact that I can now distinguish between the various initialization kinds means that I can get the tricky generalized initializer test cases Johannes Schaub supplied to work. (This is not yet done.) This commit passed self-host, with the resulting compiler passing the tests. I hope it doesn't break more complicated code. It's a pretty big change, but one that I feel is necessary. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150318 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement C++11 [expr.lambda.prim]p13, which prohibits lambdas inDouglas Gregor2012-02-101-0/+12
| | | | | | | default arguments if in fact those lambdas capture any entity. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150282 91177308-0d34-0410-b5e6-96231b3b80d8
* Make sure a variable with a C++ direct initializer triggers jump scope ↵Eli Friedman2012-02-091-0/+4
| | | | | | checking. Fixes PR10620 / <rdar://problem/9958362> . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150204 91177308-0d34-0410-b5e6-96231b3b80d8
* DR1359: A constexpr constructor does not need to initialize an empty struct orRichard Smith2012-02-091-5/+12
| | | | | | | | | empty union. This still rejects anonymous member structs or unions which only contain such empty class types, pending standard wording defining exactly what an empty class type is. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150157 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't complain about the lack of a constructor for a lambda expression. They ↵Douglas Gregor2012-02-091-1/+2
| | | | | | are constructed in different ways git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150136 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement the agreed resolution to DR1457: a signed left shift of a 1 bit intoRichard Smith2012-02-081-6/+1
| | | | | | | | | | | the sign bit doesn't have undefined behavior, but a signed left shift of a 1 bit out of the sign bit still does. As promised to Howard :) The suppression of the potential constant expression checking in system headers is also removed, since the problem it was working around is gone. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150059 91177308-0d34-0410-b5e6-96231b3b80d8
* Canonicalize the base class used in the nested-name-specifier of a generatedManuel Klimek2012-02-061-1/+2
| | | | | | | | assignment operator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149909 91177308-0d34-0410-b5e6-96231b3b80d8
* Removed redundant location info from ElaboratedTypeLoc / DependentNameLoc / ↵Abramo Bagnara2012-02-061-3/+3
| | | | | | DependentTSTLoc. Uniformed names referencing elaborated keyword. No intended functionality changes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149889 91177308-0d34-0410-b5e6-96231b3b80d8
* constexpr: Implement DR1358: An instantiation of a constexpr function whichRichard Smith2012-02-051-2/+3
| | | | | | | | can't produce a constant expression is not ill-formed (so long as some instantiation of that function can produce a constant expression). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149802 91177308-0d34-0410-b5e6-96231b3b80d8
* Basic: import SmallString<> into clang namespaceDylan Noblesmith2012-02-051-2/+2
| | | | | | | (I was going to fix the TODO about DenseMap too, but that would break self-host right now. See PR11922.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149799 91177308-0d34-0410-b5e6-96231b3b80d8
* A useful approximation of initializer list constructors.Sebastian Redl2012-02-041-3/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149792 91177308-0d34-0410-b5e6-96231b3b80d8
* Move a method from IdentifierTable.h out of line and remove the SmallString ↵Benjamin Kramer2012-02-041-0/+1
| | | | | | | | include. Fix all the transitive include users. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149783 91177308-0d34-0410-b5e6-96231b3b80d8
* In C++11 mode, when an integral constant expression is desired and we have aRichard Smith2012-02-041-3/+9
| | | | | | | | | | | | | | | | | | | value of class type, look for a unique conversion operator converting to integral or unscoped enumeration type and use that. Implements [expr.const]p5. Sema::VerifyIntegerConstantExpression now performs the conversion and returns the converted result. Some important callers of Expr::isIntegralConstantExpr have been switched over to using it (including all of those required for C++11 conformance); this switch brings a side-benefit of improved diagnostics and, in several cases, simpler code. However, some language extensions and attributes have not been moved across and will not perform implicit conversions on constant expressions of literal class type where an ICE is required. In passing, fix static_assert to perform a contextual conversion to bool on its argument. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149776 91177308-0d34-0410-b5e6-96231b3b80d8
* constexpr:Richard Smith2012-02-041-3/+18
| | | | | | | | | | | The recent support for potential constant expressions exposed a bug in the implementation of libstdc++4.6, where numeric_limits<int>::min() is defined as (int)1 << 31, which isn't a constant expression. Disable the 'constexpr function never produces a constant expression' error inside system headers to compensate. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149729 91177308-0d34-0410-b5e6-96231b3b80d8
* Split Sema::MarkDeclarationReferenced into multiple functions; the ↵Eli Friedman2012-02-021-14/+14
| | | | | | additional entry points are needed to implement C++11 odr-use marking correctly. No functional change in this patch; I'll actually make the change which fixes the odr-use marking in a followup patch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149586 91177308-0d34-0410-b5e6-96231b3b80d8
* Reject mismatched "#pragma GCC visibility push" and "#pragma GCC visibility ↵Rafael Espindola2012-02-011-2/+2
| | | | | | pop". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149559 91177308-0d34-0410-b5e6-96231b3b80d8
* Make the callback object to Sema::CorrectTypo mandatory.Kaelyn Uhrain2012-01-311-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149451 91177308-0d34-0410-b5e6-96231b3b80d8
* Added source location for the template keyword in AST template-id expressions.Abramo Bagnara2012-01-271-7/+16
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149127 91177308-0d34-0410-b5e6-96231b3b80d8
* constexpr: Implement the [dcl.constexpr]p5 check for whether a constexprRichard Smith2012-01-271-0/+9
| | | | | | | | function definition can produce a constant expression. This also provides the last few checks for [dcl.constexpr]p3 and [dcl.constexpr]p4. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149108 91177308-0d34-0410-b5e6-96231b3b80d8
* Promote the extension warning for attempts to catch a reference orDouglas Gregor2012-01-241-10/+3
| | | | | | | | | | | | pointer to incomplete type from an ExtWarn to an error. We put the ExtWarn in place as part of a workaround for Boost (PR6527), but it (1) doesn't actually match a GCC extension and (2) has been fixed for two years in Boost, and (3) causes us to emit code that fails badly at run time, so it's a bad idea to keep it. Fixes PR11803. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148838 91177308-0d34-0410-b5e6-96231b3b80d8
* Support decltype in member initializers.David Blaikie2012-01-241-3/+9
| | | | | | | | | | This is the last piece of N3031 (decltype in weird places) - supporting the use of decltype in a class ctor's member-initializer-list to specify the base classes to initialize. Reviewed by Richard Smith. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148789 91177308-0d34-0410-b5e6-96231b3b80d8
* Minor fixups for auto deduction of initializer lists.Sebastian Redl2012-01-231-4/+7
| | | | | | | | Fix some review comments. Add a test for deduction when std::initializer_list isn't available yet. Fix redundant error messages. This fixes and outstanding FIXME too. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148735 91177308-0d34-0410-b5e6-96231b3b80d8
* Eli says this should check MicrosoftMode instead.Nico Weber2012-01-231-3/+3
| | | | | | | | Also change a || that I accidentally changed to && back to ||. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148677 91177308-0d34-0410-b5e6-96231b3b80d8
* In ms mode, a move assignment operator shouldn't mark a copy ctor as deleted.Nico Weber2012-01-231-11/+15
| | | | | | | | | | | | | | | MSVC2010's pair class has a move assignment operator but no explicit copy constructor, which makes it unusable without this change. For symmetry, let move copy constructors not mark the default assignment operator as deleted either. Both changes match cl.exe's behavior. Fixes pr11826. Also update the standard excerpt to point to the right paragraph. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148675 91177308-0d34-0410-b5e6-96231b3b80d8
* Make sure the AST correctly represents lvalue-to-rvalue conversions where ↵Eli Friedman2012-01-231-6/+13
| | | | | | appropriate. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148673 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix some comments relating to ExpressionEvaluationContexts. Get rid of a ↵Eli Friedman2012-01-211-2/+1
| | | | | | couple of uses of ConstantEvaluated which don't make sense. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148624 91177308-0d34-0410-b5e6-96231b3b80d8
* More dead code removal (using -Wunreachable-code)David Blaikie2012-01-201-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148577 91177308-0d34-0410-b5e6-96231b3b80d8
* Add Sema::isInitListConstructor. This will be needed for upcoming work.Sebastian Redl2012-01-171-0/+17
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148354 91177308-0d34-0410-b5e6-96231b3b80d8
* Auto deduction support for std::initializer_list, including for-range ↵Sebastian Redl2012-01-171-3/+49
| | | | | | | | support. This means you can now write: for (int i : {1, 4, 512, 23, 251}) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148353 91177308-0d34-0410-b5e6-96231b3b80d8
* Template argument deduction for std::initializer_list arguments from ↵Sebastian Redl2012-01-171-13/+22
| | | | | | initializer lists. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148352 91177308-0d34-0410-b5e6-96231b3b80d8
* Add Sema::isStdInitializerList, which will be necessary for the upcoming ↵Sebastian Redl2012-01-171-0/+53
| | | | | | operations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148348 91177308-0d34-0410-b5e6-96231b3b80d8
* Add some calls to MarkDeclarationReferenced, towards a point where every ↵Eli Friedman2012-01-161-1/+5
| | | | | | declaration which is used is marked as used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148253 91177308-0d34-0410-b5e6-96231b3b80d8
* De-virtualize getPreviousDecl() and getMostRecentDecl() when we knowDouglas Gregor2012-01-141-4/+4
| | | | | | | | | | | | | we have a redeclarable type, and only use the new virtual versions (getPreviousDeclImpl() and getMostRecentDeclImpl()) when we don't have that type information. This keeps us from penalizing users with strict type information (and is the moral equivalent of a "final" method). Plus, settle on the names getPreviousDecl() and getMostRecentDecl() throughout. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148187 91177308-0d34-0410-b5e6-96231b3b80d8
* PR11754: Reject non-static constexpr member functions in classes with virtualRichard Smith2012-01-131-17/+19
| | | | | | | base classes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148094 91177308-0d34-0410-b5e6-96231b3b80d8
* constexpr is allowed on static member functions of non-literal classes. Per ↵Eli Friedman2012-01-131-1/+1
| | | | | | report on cfe-dev. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148090 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix the caching in CorrectTypo so that other non-keyword identifiersKaelyn Uhrain2012-01-111-1/+2
| | | | | | | | | | | | | | are still added if the cached correction fails validation. Also fix a copy-and-paste error in a comment from my previous commit. Finally, add an example of the benefit the typo correction callback adds to TryNamespaceTypoCorrection--which happens to also tickle the above caching problem, as the only way a non-namespace Decl would be added to the possible corrections is if it was cached as the correction for a previous instance of the same typo where the typo was corrected to a non-namespace via a different code path. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147968 91177308-0d34-0410-b5e6-96231b3b80d8
* Add initial callback object support to Sema::CorrectTypo.Kaelyn Uhrain2012-01-111-34/+69
| | | | | | | | | Also includes two examples of the callback: a wrapper/replacement for the CorrectTypoContext enum, and a conversion of the two calls to CorrectTypo in SemaDeclCXX.cpp (one of which provides verifiable improvement to the typo correction, as demonstrated in the added test). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147962 91177308-0d34-0410-b5e6-96231b3b80d8
* When something goes wrong in type-checking a namespace definition, make the ↵Douglas Gregor2012-01-101-1/+5
| | | | | | namespace declaration invalid git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147882 91177308-0d34-0410-b5e6-96231b3b80d8