summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaInit.h
Commit message (Collapse)AuthorAgeFilesLines
* In C++98/03, when binding a reference to an rvalue ofDouglas Gregor2010-04-181-2/+21
| | | | | | | | | | | | | | | | | 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
* Collapse the three separate initialization paths inDouglas Gregor2010-04-161-0/+4
| | | | | | | | | | | | | | | | | | 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
* Propagate the "found declaration" (i.e. the using declaration instead ofJohn McCall2010-03-301-1/+2
| | | | | | | | | | | | | 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
* Switch semantic analysis of the conditional operator from usingDouglas Gregor2010-03-261-0/+7
| | | | | | CheckReferenceInit to using the new initialization sequence code. llvm-svn: 99647
* Remember the "found declaration" for an overload candidate, which is theJohn McCall2010-03-191-2/+5
| | | | | | | | | | | | | | | | entity (if applicable) which was actually looked up. If a candidate was found via a using declaration, this is the UsingShadowDecl; otherwise, if the candidate is template specialization, this is the template; otherwise, this is the function. The point of this exercise is that "found declarations" are the entities we do access control for, not their underlying declarations. Broadly speaking, this patch fixes access control for using declarations. There is a *lot* of redundant code calling into the overload-resolution APIs; we really ought to clean that up. llvm-svn: 98945
* Access checking for implicit user-defined conversions.John McCall2010-02-011-2/+10
| | | | llvm-svn: 94971
* Rework base and member initialization in constructors, with severalDouglas Gregor2010-01-311-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (necessarily simultaneous) changes: - CXXBaseOrMemberInitializer now contains only a single initializer rather than a set of initialiation arguments + a constructor. The single initializer covers all aspects of initialization, including constructor calls as necessary but also cleanup of temporaries created by the initializer (which we never handled before!). - Rework + simplify code generation for CXXBaseOrMemberInitializers, since we can now just emit the initializer as an initializer. - Switched base and member initialization over to the new initialization code (InitializationSequence), so that it - Improved diagnostics for the new initialization code when initializing bases and members, to match the diagnostics produced by the previous (special-purpose) code. - Simplify the representation of type-checked constructor initializers in templates; instead of keeping the fully-type-checked AST, which is rather hard to undo at template instantiation time, throw away the type-checked AST and store the raw expressions in the AST. This simplifies instantiation, but loses a little but of information in the AST. - When type-checking implicit base or member initializers within a dependent context, don't add the generated initializers into the AST, because they'll look like they were explicit. - Record in CXXConstructExpr when the constructor call is to initialize a base class, so that CodeGen does not have to infer it from context. This ensures that we call the right kind of constructor. There are also a few "opportunity" fixes here that were needed to not regress, for example: - Diagnose default-initialization of a const-qualified class that does not have a user-declared default constructor. We had this diagnostic specifically for bases and members, but missed it for variables. That's fixed now. - When defining the implicit constructors, destructor, and copy-assignment operator, set the CurContext to that constructor when we're defining the body. llvm-svn: 94952
* Fix reference binding of const lvalue references to bit-fields, whichDouglas Gregor2010-01-291-0/+12
| | | | | | | | | | | | | | | | | requires a temporary. Previously, we were building an initialization sequence that bound to the bit-field as if it were a real lvalue. Note that we previously (and still) diagnose binding of non-const references to bit-fields, as we should. There's no real way to test that this code is correct, since reference binding does not *currently* have any representation in the AST. This fix should make it easier for that to happen, so I've verified this fix with... Added InitializationSequence::dump(), to print an initialization sequence for debugging purposes. llvm-svn: 94826
* Fix the EntityKind order so that all entity kinds that can be copied (using ↵Anders Carlsson2010-01-231-5/+5
| | | | | | copy constructors) come first. Also, fix a bug where EK_New was left out of the err_init_conversion_failed diagnostic (It is now reported as 'new value'). Please review Doug :) llvm-svn: 94289
* Separate EK_ArrayOrVectorElement into EK_ArrayElement and EK_VectorElement; ↵Anders Carlsson2010-01-231-3/+6
| | | | | | arrays and vectors are pretty different beasts in C++. Doug, please review/comment. llvm-svn: 94279
* Allow the first parameter of operator new to be a cv-qualifiedDouglas Gregor2009-12-221-1/+1
| | | | | | | | size_t. Also, fix an issue with initialization of parameters in calls, where we weren't removing the cv-qualifiers on the parameter type itself. Fixes PR5823. llvm-svn: 91941
* Switch parameter-passing for calls via function pointers (where weDouglas Gregor2009-12-221-2/+9
| | | | | | don't have a FunctionDecl) over to InitializationSequence. llvm-svn: 91906
* Switch InitializedEntity from TypeLoc down to just QualTypes, since we don't ↵Douglas Gregor2009-12-221-33/+20
| | | | | | use the location information but we did spend a bunch of time building faked-up TypeLocs llvm-svn: 91905
* Initialization improvements: addition of string initialization and a fewEli Friedman2009-12-191-2/+10
| | | | | | | | small bug fixes in SemaInit, switch over SemaDecl to use it more often, and change a bunch of diagnostics which are different with the new initialization code. llvm-svn: 91767
* Switch more of Sema::CheckInitializerTypes over toDouglas Gregor2009-12-191-1/+5
| | | | | | | | | | InitializationSequence. Specially, switch initialization of a C++ class type (either copy- or direct-initialization). Also, make sure that we create an elidable copy-construction when performing copy initialization of a C++ class variable. Fixes PR5826. llvm-svn: 91750
* Switch the initialization required by return statements over to theDouglas Gregor2009-12-181-5/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | new InitializationSequence. This fixes some bugs (e.g., PR5808), changed some diagnostics, and caused more churn than expected. What's new: - InitializationSequence now has a "C conversion sequence" category and step kind, which falls back to - Changed the diagnostics for returns to always have the result type of the function first and the type of the expression second. CheckSingleAssignmentConstraints to peform checking in C. - Improved ASTs for initialization of return values. The ASTs now capture all of the temporaries we need to create, but intentionally do not bind the tempoary that is actually returned, so that it won't get destroyed twice. - Make sure to perform an (elidable!) copy of the class object that is returned from a class. - Fix copy elision in CodeGen to properly see through the subexpressions that occur with elidable copies. - Give "new" its own entity kind; as with return values and thrown objects, we don't bind the expression so we don't call a destructor for it. Note that, with this patch, I've broken returning move-only types in C++0x. We'll fix it later, when we tackle NRVO. llvm-svn: 91669
* Eliminate Sema::CheckValueInitialization; its callers now useDouglas Gregor2009-12-161-14/+59
| | | | | | | | | | | | | | InitializationSequence to perform the actual initialization. Also, introduced the notion of a tree of initialized entities, so that we can know where an initialization began when dealing with nested initializations (as occur when performing list initialization). This will, eventually, be useful for producing better diagnostics when list initialization fails, because we can show the path from the top-level object being initialized down to the actual subobject where initialization failed. llvm-svn: 91516
* Switch the C++ new expression over to InitializationSequence, ratherDouglas Gregor2009-12-161-4/+15
| | | | | | | | | | | | | | | | | | | | | than using its own partial implementation of initialization. Switched CheckInitializerTypes over to InitializedEntity/InitializationKind, to help move us closer to InitializationSequence. Added InitializedEntity::getName() to retrieve the name of the entity, for diagnostics that care about such things. Implemented support for default initialization in InitializationSequence. Clean up the determination of the "source expressions" for an initialization sequence in InitializationSequence::Perform. Taught CXXConstructExpr to store more location information. llvm-svn: 91492
* Implement value initialization in InitializationSequence; untestedDouglas Gregor2009-12-151-4/+15
| | | | | | WIP, yet again. llvm-svn: 91368
* Minor cleanups for constructor initialization in InitializationSequenceDouglas Gregor2009-12-141-1/+1
| | | | llvm-svn: 91325
* Constructor initialization for InitializationSequence. Untested WIP.Douglas Gregor2009-12-141-2/+13
| | | | llvm-svn: 91323
* Implement user-defined conversions in InitializationSequence. WPI thatDouglas Gregor2009-12-141-1/+6
| | | | | | isn't turned on anyway yet, so it cannot be tested. llvm-svn: 91294
* Fix a recent regression from the initialization changes.Eli Friedman2009-12-111-1/+1
| | | | llvm-svn: 91097
* Move initialization via initializer list over to InitializationSequences.Douglas Gregor2009-12-101-6/+28
| | | | llvm-svn: 91050
* Reimplement reference initialization (C++ [dcl.init.ref]) using theDouglas Gregor2009-12-091-0/+530
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | new notion of an "initialization sequence", which encapsulates the computation of the initialization sequence along with diagnostic information and the capability to turn the computed sequence into an expression. At present, I've only switched one CheckReferenceInit callers over to this new mechanism; more will follow. Aside from (hopefully) being much more true to the standard, the diagnostics provided by this reference-initialization code are a bit better than before. Some examples: p5-var.cpp:54:12: error: non-const lvalue reference to type 'struct Derived' cannot bind to a value of unrelated type 'struct Base' Derived &dr2 = b; // expected-error{{non-const lvalue reference to ... ^ ~ p5-var.cpp:55:9: error: binding of reference to type 'struct Base' to a value of type 'struct Base const' drops qualifiers Base &br3 = bc; // expected-error{{drops qualifiers}} ^ ~~ p5-var.cpp:57:15: error: ambiguous conversion from derived class 'struct Diamond' to base class 'struct Base': struct Diamond -> struct Derived -> struct Base struct Diamond -> struct Derived2 -> struct Base Base &br5 = diamond; // expected-error{{ambiguous conversion from ... ^~~~~~~ p5-var.cpp:59:9: error: non-const lvalue reference to type 'long' cannot bind to a value of unrelated type 'int' long &lr = i; // expected-error{{non-const lvalue reference to type ... ^ ~ p5-var.cpp:74:9: error: non-const lvalue reference to type 'struct Base' cannot bind to a temporary of type 'struct Base' Base &br1 = Base(); // expected-error{{non-const lvalue reference to ... ^ ~~~~~~ p5-var.cpp:102:9: error: non-const reference cannot bind to bit-field 'i' int & ir1 = (ib.i); // expected-error{{non-const reference cannot ... ^ ~~~~~~ p5-var.cpp:98:7: note: bit-field is declared here int i : 17; // expected-note{{bit-field is declared here}} ^ llvm-svn: 90992
* Improve source location information for C++ member initializers in aDouglas Gregor2009-12-021-0/+0
constructor, by keeping the DeclaratorInfo* rather than just the type and a single location. llvm-svn: 90355
OpenPOWER on IntegriCloud