summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaInit.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Don't complain about missing field initializers when the initializerDouglas Gregor2010-06-181-1/+1
| | | | | | list is completely empty, from Lasse Kärkkäinen! Fixes PR7413. llvm-svn: 106320
* Use MaybeCreateCXXExprWithTemporaries for potential destruction ofFariborz Jahanian2010-06-071-0/+7
| | | | | | | created temporary. Use own initialized entity for copied in block variables. llvm-svn: 105533
* PR7245: Make binding a reference to a temporary without a usable copyJeffrey Yasskin2010-06-071-3/+7
| | | | | | constructor into an extension warning into the error that C++98 requires. llvm-svn: 105529
* More refactoring.John McCall2010-06-041-27/+29
| | | | llvm-svn: 105458
* Add a new failure kind, FK_Incomplete, to InitializationSequence, toDouglas Gregor2010-05-201-1/+11
| | | | | | | | | capture failures when we try to initialize an incomplete type. Previously, we would (ab)use FK_ConversionFailed, then occasionally dereference a null pointer when trying to diagnose the failure. Fixes <rdar://problem/7959007>. llvm-svn: 104286
* Substantially alter the design of the Objective C type AST by introducingJohn McCall2010-05-151-1/+1
| | | | | | | | | | | | | | | | | | | | | ObjCObjectType, which is basically just a pair of one of {primitive-id, primitive-Class, user-defined @class} with a list of protocols. An ObjCObjectPointerType is therefore just a pointer which always points to one of these types (possibly sugared). ObjCInterfaceType is now just a kind of ObjCObjectType which happens to not carry any protocols. Alter a rather large number of use sites to use ObjCObjectType instead of ObjCInterfaceType. Store an ObjCInterfaceType as a pointer on the decl rather than hashing them in a FoldingSet. Remove some number of methods that are no longer used, at least after this patch. By simplifying ObjCObjectPointerType, we are now able to easily remove and apply pointers to Objective-C types, which is crucial for a certain kind of ObjC++ metaprogramming common in WebKit. llvm-svn: 103870
* Recognize when the named return value optimization applies in aDouglas Gregor2010-05-151-9/+39
| | | | | | | | | | "return" statement and mark the corresponding CXXConstructExpr as elidable. Teach CodeGen that eliding a temporary is different from eliding an object construction. This is just a baby step toward NRVO. llvm-svn: 103849
* Rework when and how vtables are emitted, by tracking where vtables areDouglas Gregor2010-05-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "used" (e.g., we will refer to the vtable in the generated code) and when they are defined (i.e., because we've seen the key function definition). Previously, we were effectively tracking "potential definitions" rather than uses, so we were a bit too eager about emitting vtables for classes without key functions. The new scheme: - For every use of a vtable, Sema calls MarkVTableUsed() to indicate the use. For example, this occurs when calling a virtual member function of the class, defining a constructor of that class type, dynamic_cast'ing from that type to a derived class, casting to/through a virtual base class, etc. - For every definition of a vtable, Sema calls MarkVTableUsed() to indicate the definition. This happens at the end of the translation unit for classes whose key function has been defined (so we can delay computation of the key function; see PR6564), and will also occur with explicit template instantiation definitions. - For every vtable defined/used, we mark all of the virtual member functions of that vtable as defined/used, unless we know that the key function is in another translation unit. This instantiates virtual member functions when needed. - At the end of the translation unit, Sema tells CodeGen (via the ASTConsumer) which vtables must be defined (CodeGen will define them) and which may be used (for which CodeGen will define the vtables lazily). From a language perspective, both the old and the new schemes are permissible: we're allowed to instantiate virtual member functions whenever we want per the standard. However, all other C++ compilers were more lazy than we were, and our eagerness was both a performance issue (we instantiated too much) and a portability problem (we broke Boost test cases, which now pass). Notes: (1) There's a ton of churn in the tests, because the order in which vtables get emitted to IR has changed. I've tried to isolate some of the larger tests from these issues. (2) Some diagnostics related to implicitly-instantiated/implicitly-defined virtual member functions have moved to the point of first use/definition. It's better this way. (3) I could use a review of the places where we MarkVTableUsed, to see if I missed any place where the language effectively requires a vtable. Fixes PR7114 and PR6564. llvm-svn: 103718
* Merged Elaborated and QualifiedName types.Abramo Bagnara2010-05-111-2/+2
| | | | llvm-svn: 103517
* Reapply the reference-binding patch applied below, along with a fix toDouglas Gregor2010-05-071-3/+5
| | | | | | | | | | | | | | | | ensure that we complete the type when we need to look at constructors during reference binding. When determining whether the two types involved in reference binding are reference-compatible, reference-related, etc., do not complete the type of the reference itself because it is not necessary to determine well-formedness of the program. Complete the type that we are binding to, since that can affect whether we know about a derived-to-base conversion. Re-fixes PR7080. llvm-svn: 103283
* Diagnose deprecated/unavailable functions selected by overload resolution.John McCall2010-05-061-0/+4
| | | | | | Fixes rdar://problem/4232969, or at least the clang parts of it. llvm-svn: 103191
* Complain when we try to initialize an object of Objective-C class typeDouglas Gregor2010-05-031-3/+7
| | | | | | | | (which is ill-formed) with an initializer list. Also, change the fallback from an assertion to a generic error message, which is far friendlier. Fixes <rdar://problem/7730948>. llvm-svn: 102930
* Add an enum to CXXConstructExpr so we can determine if the construction ↵Anders Carlsson2010-05-021-2/+11
| | | | | | expression constructs a non-virtual or virtual base. llvm-svn: 102879
* When explicitly building a temporary object (CXXTemporaryObjectExpr),Douglas Gregor2010-04-271-1/+2
| | | | | | | | | | | keep track of whether we need to zero-initialize storage prior to calling its constructor. Previously, we were only tracking this when implicitly constructing the object (a CXXConstructExpr). Fixes Boost's value-initialization tests, which means that the Boost.Config library now passes all of its tests. llvm-svn: 102461
* Introduce Type::isStructureOrClassType(), which does the obviousDouglas Gregor2010-04-261-1/+1
| | | | | | | | thing. Audit all uses of Type::isStructure(), changing those calls to isStructureOrClassType() as needed (which is alsmost everywhere). Fixes the remaining failure in Boost.Utility/Swap. llvm-svn: 102386
* Ensure that we have completed a type before attempting initializationDouglas Gregor2010-04-261-39/+48
| | | | | | on that type. Fixes several problems in Boost.Interprocess. llvm-svn: 102339
* When copying a temporary object to initialize an entity for which theDouglas Gregor2010-04-251-2/+8
| | | | | | | temporary needs to be bound, bind the copy object. Otherwise, we won't end up calling the destructor for the copy. Fixes Boost.Optional. llvm-svn: 102290
* When we create a temporary of class type that we don't immediatelyDouglas Gregor2010-04-241-5/+46
| | | | | | | bind, check accessibility of the destructor and mark the declaration as referenced. Fixes a bunch of Boost.Regex failures. llvm-svn: 102287
* When we attempt to create a temporary object of class type, be sureDouglas Gregor2010-04-241-1/+5
| | | | | | | | | | that the type we're copying is complete. Boost.Regex now builds, although it's failing its regression tests with our favorite "Sema doesn't consider destructor as used." assertion. llvm-svn: 102271
* When we are performing copy initialization of a class type via itsDouglas Gregor2010-04-241-8/+31
| | | | | | | | | | | copy constructor, suppress user-defined conversions on the argument. Otherwise, we can end up in a recursion loop where the bind the argument of the copy constructor to another copy constructor call, whose argument is then a copy constructor call... Found by Boost.Regex which, alas, still isn't building. llvm-svn: 102269
* Actually produce base paths for CastExprs of kind CK_DerivedToBase.Anders Carlsson2010-04-241-3/+5
| | | | llvm-svn: 102259
* Pass the base specifiers through to CheckDerivedToBaseConversion. No ↵Anders Carlsson2010-04-241-1/+1
| | | | | | functionality change yet. llvm-svn: 102250
* CastExpr should not hold a pointer to the base path. More cleanup.Anders Carlsson2010-04-241-6/+6
| | | | llvm-svn: 102249
* Add an InheritancePath parameter to the ImplicitCastExpr constructor.Anders Carlsson2010-04-231-2/+4
| | | | llvm-svn: 102218
* Whenever we complain about a failed initialization of a function orDouglas Gregor2010-04-221-1/+23
| | | | | | | | | | | | | | | | | method parameter, provide a note pointing at the parameter itself so the user does not have to manually look for the function/method being called and match up parameters to arguments. For example, we now get: t.c:4:5: warning: incompatible pointer types passing 'long *' to parameter of type 'int *' [-pedantic] f(long_ptr); ^~~~~~~~ t.c:1:13: note: passing argument to parameter 'x' here void f(int *x); ^ llvm-svn: 102038
* Switch the initialization of Objective-C message parameters (as occursDouglas Gregor2010-04-211-1/+4
| | | | | | | | | during message sends) over to the new initialization code and away from the C-only CheckSingleAssignmentConstraints. The enables the use of C++ types in method parameters and message arguments, as well as unifying more initialiation code overall. llvm-svn: 102035
* Keep tack of whether a base in an InitializedEntity is an inherited virtual ↵Anders Carlsson2010-04-211-2/+6
| | | | | | base or not. Use this in CheckConstructorAccess. llvm-svn: 102020
* Pass the InitializedEntity to Sema::CheckConstructorAccess and use it to ↵Anders Carlsson2010-04-211-3/+3
| | | | | | report different diagnostics depending on which entity is being initialized. llvm-svn: 102010
* Fix comment to reflect recent code change.John Thompson2010-04-201-1/+1
| | | | llvm-svn: 101960
* reapply john's patch, he broke mainline again by changing the test.Chris Lattner2010-04-201-1/+1
| | | | llvm-svn: 101871
* revert r101863, whcih is causing Sema/altivec-init.c to fail on a tonChris Lattner2010-04-201-1/+1
| | | | | | | | | | of buildbots with: error: 'error' diagnostics expected but not seen: Line 9: too few elements in vector initialization (expected 8 elements, have 2) 1 warning and 1 error generated. llvm-svn: 101864
* Altivec vector literal initializer count mismatch error removed.John Thompson2010-04-201-1/+1
| | | | llvm-svn: 101863
* When checking the copy constructor for the optional copy during aDouglas Gregor2010-04-181-3/+19
| | | | | | | | | reference binding to an rvalue of reference-compatible type, check parameters after the first for complete parameter types and build any required default function arguments. We're effectively simulating the type-checking for a call without building the call itself. llvm-svn: 101705
* In C++98/03, when binding a reference to an rvalue ofDouglas Gregor2010-04-181-13/+73
| | | | | | | | | | | | | | | | | reference-compatible type, the implementation is permitted to make a copy of the rvalue (or many such copies, even). However, even though we don't make that copy, we are required to check for the presence of a suitable copy constructor. With this change, we do. Note that in C++0x we are not allowed to make these copies, so we test both dialects separately. Also note the FIXME in one of the C++03 tests, where we are not instantiating default function arguments for the copy constructor we pick (but do not call). The fix is obvious; eliminating the infinite recursion it causes is not. Will address that next. llvm-svn: 101704
* Do not consider explicit constructors when performing a copy to aDouglas Gregor2010-04-181-1/+2
| | | | | | | | | temporary object. This is blindingly obvious from reading C++ [over.match.ctor]p1, but somehow I'd missed it and it took DR152 to educate me. Adjust one test that was relying on this non-standard behavior. llvm-svn: 101688
* Improve our handling of user-defined conversions as part of overloadDouglas Gregor2010-04-171-15/+35
| | | | | | | | | | | | | | | | | resolution. There are two sources of problems involving user-defined conversions that this change eliminates, along with providing simpler interfaces for checking implicit conversions: - It eliminates a case of infinite recursion found in Boost. - It eliminates the search for the constructor needed to copy a temporary generated by an implicit conversion from overload resolution. Overload resolution assumes that, if it gets a value of the parameter's class type (or a derived class thereof), there is a way to copy if... even if there isn't. We now model this properly. llvm-svn: 101680
* Add raw_ostream operators to NamedDecl for convenience. Switch over all ↵Benjamin Kramer2010-04-171-2/+1
| | | | | | | | users of getNameAsString on a stream. The next step is to print the name directly into the stream, avoiding a temporary std::string copy. llvm-svn: 101632
* Collapse the three separate initialization paths inDouglas Gregor2010-04-161-1/+7
| | | | | | | | | | | | | | | | | | TryStaticImplicitCast (for references, class types, and everything else, respectively) into a single invocation of InitializationSequence. One of the paths (for class types) was the only client of Sema::TryInitializationByConstructor, which I have eliminated. This also simplified the interface for much of the cast-checking logic, eliminating yet more code. I've kept the representation of C++ functional casts with <> 1 arguments the same, despite the fact that I hate it. That fix will come soon. To satisfy my paranoia, I've bootstrapped + tested Clang with these changes. llvm-svn: 101549
* Switch the checking of implicit casts for static_cast, C-style, andDouglas Gregor2010-04-161-5/+8
| | | | | | | | | | functional casts over to InitializationSequence, eliminating a caller of Sema::TryImplicitConversion. We also get access and ambiguity checking "for free". More cleanups to come in this routine. llvm-svn: 101526
* Kill ForceRValue once and for allDouglas Gregor2010-04-161-2/+0
| | | | llvm-svn: 101502
* Eliminate ForceRValue parameters from reference binding. Did I mentionDouglas Gregor2010-04-161-5/+1
| | | | | | that we aren't using ForceRValue any more? llvm-svn: 101496
* Eliminate the Elidable parameter to PerformImplicitConversion; weDouglas Gregor2010-04-161-1/+1
| | | | | | don't need it. llvm-svn: 101481
* Teach typo correction about various language keywords. We can'tDouglas Gregor2010-04-141-1/+2
| | | | | | | | | | | | | generally recover from typos in keywords (since we would effectively have to mangle the token stream). However, there are still benefits to typo-correcting with keywords: - We don't make stupid suggestions when the user typed something that is similar to a keyword. - We can suggest the keyword in a diagnostic (did you mean "static_cast"?), even if we can't recover and therefore don't have a fix-it. llvm-svn: 101274
* Use ASTVector instead of std::vector for the Exprs in InitListExpr. PerformanceTed Kremenek2010-04-131-6/+8
| | | | | | | measurements of '-fsyntax-only' on combine.c (403.gcc) shows no real performance change, but now the vector isn't leaked. llvm-svn: 101195
* Rework our handling of copy construction of temporaries, which was aDouglas Gregor2010-04-021-61/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | poor (and wrong) approximation of the actual rules governing when to build a copy and when it can be elided. The correct implementation is actually simpler than the approximation. When we only enumerate constructors as part of initialization (e.g., for direct initialization or when we're copying from a class type or one of its derived classes), we don't create a copy. When we enumerate all conversion functions, we do create a copy. Before, we created some extra copies and missed some others. The new test copy-initialization.cpp shows a case where we missed creating a (required, non-elidable) copy as part of a user-defined conversion, which resulted in a miscompile. This commit also fixes PR6757, where the missing copy made us reject well-formed code in the ternary operator. This commit also cleans up our handling of copy elision in the case where we create an extra copy of a temporary object, which became necessary now that we produce the right copies. The code that seeks to find the temporary object being copied has moved into Expr::getTemporaryObject(); it used to have two different not-quite-the-same implementations, one in Sema and one in CodeGen. Note that we still do not attempt to perform the named return value optimization, so we miss copy elisions for return values and throw expressions. llvm-svn: 100196
* Reinstate my CodeModificationHint -> FixItHint renaming patch, withoutDouglas Gregor2010-03-311-10/+8
| | | | | | the C-only "optimization". llvm-svn: 100022
* Revert r100008, which inexplicably breaks the clang-i686-darwin10 builderDouglas Gregor2010-03-311-8/+10
| | | | llvm-svn: 100018
* Rename CodeModificationHint to FixItHint, since we've been using theDouglas Gregor2010-03-311-10/+8
| | | | | | | term "fix-it" everywhere and even *I* get tired of long names sometimes. No functionality change. llvm-svn: 100008
* Regularize support for naming conversion functions in using decls.John McCall2010-03-311-1/+1
| | | | llvm-svn: 99979
* Propagate the "found declaration" (i.e. the using declaration instead ofJohn McCall2010-03-301-10/+17
| | | | | | | | | | | | | the underlying/instantiated decl) through a lot of API, including "intermediate" MemberExprs required for (e.g.) template instantiation. This is necessary because of the access semantics of member accesses to using declarations: only the base class *containing the using decl* need be accessible from the naming class. This allows us to complete an access-controlled selfhost, if there are no recent regressions. llvm-svn: 99936
OpenPOWER on IntegriCloud