summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExprCXX.cpp
Commit message (Collapse)AuthorAgeFilesLines
* When there are any member new operators, global versions aren't looked up at ↵Sebastian Redl2009-05-141-2/+0
| | | | | | all. llvm-svn: 71780
* Implement explicit instantiations of member classes of class templates, e.g.,Douglas Gregor2009-05-141-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | template<typename T> struct X { struct Inner; }; template struct X<int>::Inner; This change is larger than it looks because it also fixes some a problem with nested-name-specifiers and tags. We weren't requiring the DeclContext associated with the scope specifier of a tag to be complete. Therefore, when looking for something like "struct X<int>::Inner", we weren't instantiating X<int>. This, naturally, uncovered a problem with member pointers, where we were requiring the left-hand side of a member pointer access expression (e.g., x->*) to be a complete type. However, this is wrong: the semantics of this expression does not require a complete type (EDG agrees). Stuart vouched for me. Blame him. llvm-svn: 71756
* Implement C++0x nullptr.Sebastian Redl2009-05-101-0/+6
| | | | llvm-svn: 71405
* Fix a FIXME in new expression checking.Sebastian Redl2009-05-071-5/+4
| | | | llvm-svn: 71163
* Turns out that Sebastian already implemented the logic to compute theDouglas Gregor2009-05-051-71/+0
| | | | | | | composite pointer type, and his is better! Updated relational- and equality-operator checking accordingly. llvm-svn: 70963
* Implement support for comparing pointers with <, >, <=, >=, ==, and !=Douglas Gregor2009-05-041-0/+71
| | | | | | | | | | | | | | in C++, taking into account conversions to the "composite pointer type" so that we can compare, e.g., a pointer to a derived class to a pointer to a base class. Also, upgrade the "comparing distinct pointer types" from a warning to an error for C++, since this is clearly an error. Turns out that we hadn't gone through and audited this code for C++, ever. Fixes <rdar://problem/6816420>. llvm-svn: 70829
* Improve validation of C++ exception handling: diagnose throwing incomplete ↵Sebastian Redl2009-04-271-2/+31
| | | | | | types and jumps into protected try-catch scopes. llvm-svn: 70242
* Make reference class unification in conditional expressions check for ↵Sebastian Redl2009-04-261-6/+6
| | | | | | validity of the conversion. llvm-svn: 70121
* This is a pretty big cleanup for how invalid decl/type are handle.Chris Lattner2009-04-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This gets rid of a bunch of random InvalidDecl bools in sema, changing us to use the following approach: 1. When analyzing a declspec or declarator, if an error is found, we set a bit in Declarator saying that it is invalid. 2. Once the Decl is created by sema, we immediately set the isInvalid bit on it from what is in the declarator. From this point on, sema consistently looks at and sets the bit on the decl. This gives a very clear separation of concerns and simplifies a bunch of code. In addition to this, this patch makes these changes: 1. it renames DeclSpec::getInvalidType() -> isInvalidType(). 2. various "merge" functions no longer return bools: they just set the invalid bit on the dest decl if invalid. 3. The ActOnTypedefDeclarator/ActOnFunctionDeclarator/ActOnVariableDeclarator methods now set invalid on the decl returned instead of returning an invalid bit byref. 4. In SemaType, refering to a typedef that was invalid now propagates the bit into the resultant type. Stuff declared with the invalid typedef will now be marked invalid. 5. Various methods like CheckVariableDeclaration now return void and set the invalid bit on the decl they check. There are a few minor changes to tests with this, but the only major bad result is test/SemaCXX/constructor-recovery.cpp. I'll take a look at this next. llvm-svn: 70020
* Add an ASTContext parameter to CXXTemporaryObjectExpr.Anders Carlsson2009-04-241-2/+4
| | | | llvm-svn: 69959
* Add a VarDecl parameter to the CXXTemporaryObjectExpr constructor. It's ↵Anders Carlsson2009-04-241-2/+7
| | | | | | unused for now, so no functionality change yet. Also, create CXXTempVarDecls to pass to the CXXTemporaryObjectExpr ctor. llvm-svn: 69957
* Conditional operator C++ checking complete. What issues remain are in more ↵Sebastian Redl2009-04-191-0/+2
| | | | | | general code. llvm-svn: 69555
* Bring member pointer operands of the conditional operator to a common type. ↵Sebastian Redl2009-04-191-2/+55
| | | | | | We're getting there ... llvm-svn: 69548
* Another piece of the conditional operator puzzle. We'll want to use ↵Sebastian Redl2009-04-191-12/+92
| | | | | | FindCompositePointerType in some other places, too. llvm-svn: 69534
* Implement lvalue test for conditional expressions.Sebastian Redl2009-04-171-4/+31
| | | | | | Add a few commented lines to the test case that point out things that don't work yet. llvm-svn: 69354
* Fix a crash bug when comparing overload quality of conversion operators with ↵Sebastian Redl2009-04-161-0/+290
| | | | | | | | | | | conversion constructors. Remove an atrocious amount of trailing whitespace in the overloaded operator mangler. Sorry, couldn't help myself. Change the DeclType parameter of Sema::CheckReferenceInit to be passed by value instead of reference. It wasn't changed anywhere. Let the parser handle C++'s irregular grammar around assignment-expression and conditional-expression. And finally, the reason for all this stuff: implement C++ semantics for the conditional operator. The implementation is complete except for determining lvalueness. llvm-svn: 69299
* Parse deleted member functions. Parsing member declarations goes through a ↵Sebastian Redl2009-04-121-5/+15
| | | | | | | | | different code path that I forgot previously. Implement the rvalue reference overload dance for returning local objects. Returning a local object first tries to find a move constructor now. The error message when no move constructor is defined (or is not applicable) and the copy constructor is deleted is quite ugly, though. llvm-svn: 68902
* Propagate the ASTContext to various AST traversal and lookup functions.Douglas Gregor2009-04-091-3/+3
| | | | | | No functionality change (really). llvm-svn: 68726
* Introduce a new OpaquePtr<N> struct type, which is a simple POD wrapper for aChris Lattner2009-03-281-8/+10
| | | | | | | | | | | | | | | | | | | | pointer. Its purpose in life is to be a glorified void*, but which does not implicitly convert to void* or other OpaquePtr's with a different UID. Introduce Action::DeclPtrTy which is a typedef for OpaquePtr<0>. Change the entire parser/sema interface to use DeclPtrTy instead of DeclTy*. This makes the C++ compiler enforce that these aren't convertible to other opaque types. We should also convert ExprTy, StmtTy, TypeTy, AttrTy, BaseTy, etc, but I don't plan to do that in the short term. The one outstanding known problem with this patch is that we lose the bitmangling optimization where ActionResult<DeclPtrTy> doesn't know how to bitmangle the success bit into the low bit of DeclPtrTy. I will rectify this with a subsequent patch. llvm-svn: 67952
* Fix a few isObjectTypes that really need to be isIncompleteOrObjectDouglas Gregor2009-03-241-5/+6
| | | | | | types; add another use of RequireCompleteType. llvm-svn: 67644
* Make sure to use RequireCompleteType rather than testing forDouglas Gregor2009-03-241-22/+19
| | | | | | | incomplete types. RequireCompleteType is needed when the type may be completed by instantiating a template. llvm-svn: 67643
* More work on diagnosing abstract classes. We can now handle cases likeAnders Carlsson2009-03-241-3/+3
| | | | | | | | | | | | class C { void g(C c); virtual void f() = 0; }; In this case, C is not known to be abstract when doing semantic analysis on g. This is done by recursively traversing the abstract class and checking the types of member functions. llvm-svn: 67594
* More improvements to abstract type checking. Handle arrays correctly, and ↵Anders Carlsson2009-03-231-0/+4
| | | | | | make sure to check parameter types before they decay. llvm-svn: 67550
* It's an error to try to allocate an abstract object using new.Anders Carlsson2009-03-231-0/+4
| | | | llvm-svn: 67542
* Almost complete implementation of rvalue references. One bug, and a few ↵Sebastian Redl2009-03-161-3/+5
| | | | | | unclear areas. Maybe Doug can shed some light on some of the fixmes. llvm-svn: 67059
* Convert a bunch of actions to smart pointers, and also bring ↵Sebastian Redl2009-03-151-93/+105
| | | | | | PrintParserCallbacks a bit more in line with reality. llvm-svn: 67029
* Implement template instantiation for several more kinds of expressions:Douglas Gregor2009-03-131-2/+7
| | | | | | | | | | | | - C++ function casts, e.g., T(foo) - sizeof(), alignof() More importantly, this allows us to verify that we're performing overload resolution during template instantiation, with argument-dependent lookup and the "cached" results of name lookup from the template definition. llvm-svn: 66947
* Refactor the way we handle operator overloading and templateDouglas Gregor2009-03-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | instantiation for binary operators. This change moves most of the operator-overloading code from the parser action ActOnBinOp to a new, parser-independent semantic checking routine CreateOverloadedBinOp. Of particular importance is the fact that CreateOverloadedBinOp does *not* perform any name lookup based on the current parsing context (it doesn't take a Scope*), since it has to be usable during template instantiation, when there is no scope information. Rather, it takes a pre-computed set of functions that are visible from the context or via argument-dependent lookup, and adds to that set any member operators and built-in operator candidates. The set of functions is computed in the parser action ActOnBinOp based on the current context (both operator name lookup and argument-dependent lookup). Within a template, the set computed by ActOnBinOp is saved within the type-dependent AST node and is augmented with the results of argument-dependent name lookup at instantiation time (see TemplateExprInstantiator::VisitCXXOperatorCallExpr). Sadly, we can't fully test this yet. I'll follow up with template instantiation for sizeof so that the real fun can begin. llvm-svn: 66923
* Rename DiagnoseIncompleteType to RequireCompleteType, and update the ↵Douglas Gregor2009-03-091-2/+2
| | | | | | documentation to reflect the fact that we can instantiate templates here llvm-svn: 66421
* Eliminate CXXRecordTypeDouglas Gregor2009-02-281-2/+2
| | | | llvm-svn: 65671
* Make more AST nodes and semantic checkers dependent-expression-aware.Sebastian Redl2009-02-261-32/+45
| | | | llvm-svn: 65529
* C99 DR #316 implies that the function parameter types that are knownDouglas Gregor2009-02-251-1/+1
| | | | | | | | | | only from a function definition (that does not have a prototype) are only used to determine the compatible with other declarations of that same function. In particular, when referencing the function we pretend as if it does not have a prototype. Implement this behavior, which fixes PR3626. llvm-svn: 65460
* Downgrade complaints about calling unavailable functions to a warningDouglas Gregor2009-02-181-6/+15
| | | | | | | | | | | | | | | | | | (as GCC does), except when we've performed overload resolution and found an unavailable function: in this case, we actually error. Merge the checking of unavailable functions with the checking for deprecated functions. This unifies a bit of code, and makes sure that we're checking for unavailable functions in the right places. Also, this check can cause an error. We may, eventually, want an option to make "unavailable" warnings into errors. Implement much of the logic needed for C++0x deleted functions, which are effectively the same as "unavailable" functions (but always cause an error when referenced). However, we don't have the syntax to specify deleted functions yet :) llvm-svn: 64955
* remove "; candidates are/is:" from various ambiguity diagnostics.Chris Lattner2009-02-171-2/+2
| | | | | | 2 out of 2 people on irc prefer them gone :) llvm-svn: 64749
* Introduce _Complex conversions into the function overloadingDouglas Gregor2009-02-121-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | system. Since C99 doesn't have overloading and C++ doesn't have _Complex, there is no specification for this. Here's what I think makes sense. Complex conversions come in several flavors: - Complex promotions: a complex -> complex conversion where the underlying real-type conversion is a floating-point promotion. GCC seems to call this a promotion, EDG does something else. This is given "promotion" rank for determining the best viable function. - Complex conversions: a complex -> complex conversion that is not a complex promotion. This is given "conversion" rank for determining the best viable function. - Complex-real conversions: a real -> complex or complex -> real conversion. This is given "conversion" rank for determining the best viable function. These rules are the same for C99 (when using the "overloadable" attribute) and C++. However, there is one difference in the handling of floating-point promotions: in C99, float -> long double and double -> long double are considered promotions (so we give them "promotion" rank), while C++ considers these conversions ("conversion" rank). llvm-svn: 64343
* Initial implementation of function overloading in C.Douglas Gregor2009-02-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a new attribute, "overloadable", that enables C++ function overloading in C. The attribute can only be added to function declarations, e.g., int *f(int) __attribute__((overloadable)); If the "overloadable" attribute exists on a function with a given name, *all* functions with that name (and in that scope) must have the "overloadable" attribute. Sets of overloaded functions with the "overloadable" attribute then follow the normal C++ rules for overloaded functions, e.g., overloads must have different parameter-type-lists from each other. When calling an overloaded function in C, we follow the same overloading rules as C++, with three extensions to the set of standard conversions: - A value of a given struct or union type T can be converted to the type T. This is just the identity conversion. (In C++, this would go through a copy constructor). - A value of pointer type T* can be converted to a value of type U* if T and U are compatible types. This conversion has Conversion rank (it's considered a pointer conversion in C). - A value of type T can be converted to a value of type U if T and U are compatible (and are not both pointer types). This conversion has Conversion rank (it's considered to be a new kind of conversion unique to C, a "compatible" conversion). Known defects (and, therefore, next steps): 1) The standard-conversion handling does not understand conversions involving _Complex or vector extensions, so it is likely to get these wrong. We need to add these conversions. 2) All overloadable functions with the same name will have the same linkage name, which means we'll get a collision in the linker (if not sooner). We'll need to mangle the names of these functions. llvm-svn: 64336
* Update new expression to make use of Declarator::getSourceRange().Sebastian Redl2009-02-091-33/+27
| | | | | | References are not objects; implement this in Type::isObjectType(). llvm-svn: 64152
* Move CheckPointerToMemberOperands to SemaExprCXX.cppSebastian Redl2009-02-071-0/+67
| | | | llvm-svn: 64029
* Overhaul of Stmt allocation:Ted Kremenek2009-02-071-17/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Made allocation of Stmt objects using vanilla new/delete a *compiler error* by making this new/delete "protected" within class Stmt. - Now the only way to allocate Stmt objects is by using the new operator that takes ASTContext& as an argument. This ensures that all Stmt nodes are allocated from the same (pool) allocator. - Naturally, these two changes required that *all* creation sites for AST nodes use new (ASTContext&). This is a large patch, but the majority of the changes are just this mechanical adjustment. - The above changes also mean that AST nodes can no longer be deallocated using 'delete'. Instead, one most do StmtObject->Destroy(ASTContext&) or do ASTContextObject.Deallocate(StmtObject) (the latter not running the 'Destroy' method). Along the way I also... - Made CompoundStmt allocate its array of Stmt* using the allocator in ASTContext (previously it used std::vector). There are a whole bunch of other Stmt classes that need to be similarly changed to ensure that all memory allocated for ASTs comes from the allocator in ASTContext. - Added a new smart pointer ExprOwningPtr to Sema.h. This replaces the uses of llvm::OwningPtr within Sema, as llvm::OwningPtr used 'delete' to free memory instead of a Stmt's 'Destroy' method. Big thanks to Doug Gregor for helping with the acrobatics of making 'new/delete' private and the new smart pointer ExprOwningPtr! llvm-svn: 63997
* Fix our semantic analysis ofDouglas Gregor2009-02-041-2/+2
| | | | | | | | | | | | | | | | | | | | | unqualified-id '(' in C++. The unqualified-id might not refer to any declaration in our current scope, but declarations by that name might be found via argument-dependent lookup. We now do so properly. As part of this change, CXXDependentNameExpr, which was previously designed to express the unqualified-id in the above constructor within templates, has become UnresolvedFunctionNameExpr, which does effectively the same thing but will work for both templates and non-templates. Additionally, we cope with all unqualified-ids, since ADL also applies in cases like operator+(x, y) llvm-svn: 63733
* Allow taking the address of data members, resulting in a member pointer.Sebastian Redl2009-02-031-4/+7
| | | | | | Pointers to functions don't work yet, and pointers to overloaded functions even less. Also, far too much illegal code is accepted. llvm-svn: 63655
* Eliminated LookupCriteria, whose creation was causing a bottleneck forDouglas Gregor2009-01-301-2/+2
| | | | | | | | | | | | | | | | | | LookupName et al. Instead, use an enum and a bool to describe its contents. Optimized the C/Objective-C path through LookupName, eliminating any unnecessarily C++isms. Simplify IdentifierResolver::iterator, removing some code and arguments that are no longer used. Eliminated LookupDeclInScope/LookupDeclInContext, moving all callers over to LookupName, LookupQualifiedName, or LookupParsedName, as appropriate. All together, I'm seeing a 0.2% speedup on Cocoa.h with PTH and -disable-free. Plus, we're down to three name-lookup routines. llvm-svn: 63354
* move library-specific diagnostic headers into library private dirs. ReduceChris Lattner2009-01-291-1/+0
| | | | | | redundant #includes. Patch by Anders Johnsen! llvm-svn: 63271
* Refactor Sema::LookupDecl() into 2 functions: LookupDeclInScope() and ↵Steve Naroff2009-01-291-1/+1
| | | | | | | | | | LookupDeclInContext(). The previous interface was very confusing. This is much more explicit, which will be easier to understand/optimize/convert. The plan is to eventually deprecate both of these functions. For now, I'm focused on performance. llvm-svn: 63256
* Remove 'NamespaceNameOnly' argument to Sema::LookupDecl(). It is unused.Steve Naroff2009-01-281-2/+1
| | | | | | Even though Sema::LookupDecl() is deprecated, it's still used all over the place. Simplifying the interface will make it easier to understand/optimize/convert. llvm-svn: 63210
* Split the single monolithic DiagnosticKinds.def file into oneChris Lattner2009-01-271-1/+1
| | | | | | | | | .def file for each library. This means that adding a diagnostic to sema doesn't require all the other libraries to be rebuilt. Patch by Anders Johnsen! llvm-svn: 63111
* Implement implicit conversions for pointers-to-member.Sebastian Redl2009-01-251-2/+3
| | | | llvm-svn: 62971
* Remove ScopedDecl, collapsing all of its functionality into Decl, soDouglas Gregor2009-01-201-2/+2
| | | | | | | | | | | | | | | | that every declaration lives inside a DeclContext. Moved several things that don't have names but were ScopedDecls (and, therefore, NamedDecls) to inherit from Decl rather than NamedDecl, including ObjCImplementationDecl and LinkageSpecDecl. Now, we don't store empty DeclarationNames for these things, nor do we try to insert them into DeclContext's lookup structure. The serialization tests are temporarily disabled. We'll re-enable them once we've sorted out the remaining ownership/serialiazation issues between DeclContexts and TranslationUnion, DeclGroups, etc. llvm-svn: 62562
* Centralize error reporting of improper uses of incomplete types in theDouglas Gregor2009-01-191-6/+8
| | | | | | | | | | new DiagnoseIncompleteType. It provides additional information about struct/class/union/enum types when possible, either by pointing to the forward declaration of that type or by pointing to the definition (if we're in the process of defining that type). Fixes <rdar://problem/6500531>. llvm-svn: 62521
* Convert a few expression actions to smart pointers.Sebastian Redl2009-01-181-3/+3
| | | | | | These actions are extremely widely used (identifier expressions and literals); still no performance regression. llvm-svn: 62468
OpenPOWER on IntegriCloud