summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Reimplement constructor declarator parsing to cope with template-idsDouglas Gregor2010-01-131-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | that name constructors, the endless joys of out-of-line constructor definitions, and various other corner cases that the previous hack never imagined. Fixes PR5688 and tightens up semantic analysis for constructor names. Additionally, fixed a problem where we wouldn't properly enter the declarator scope of a parenthesized declarator. We were entering the scope, then leaving it when we saw the ")"; now, we re-enter the declarator scope before parsing the parameter list. Note that we are forced to perform some tentative parsing within a class (call it C) to tell the difference between C(int); // constructor and C (f)(int); // member function which is rather unfortunate. And, although it isn't necessary for correctness, we use the same tentative-parsing mechanism for out-of-line constructors to improve diagnostics in icky cases like: C::C C::f(int); // error: C::C refers to the constructor name, but // we complain nicely and recover by treating it as // a type. llvm-svn: 93322
* Implement semantic checking for C++ literal operators.Alexis Hunt2010-01-131-1/+6
| | | | | | | This now rejects literal operators that don't meet the requirements. Templates are not yet checked for. llvm-svn: 93315
* Add an unreachable code checker.Mike Stump2010-01-131-28/+62
| | | | llvm-svn: 93287
* C++0x [dcl.typedef]p4, take 3, where we actually figure out what "thatDouglas Gregor2010-01-111-1/+1
| | | | | | | is not also a typedef-name" actually means. For anyone keeping score, that's John: 2, Doug: 0. llvm-svn: 93196
* Use isa<ElaboratedType> rather than getAs<ElaboratedType>, since theDouglas Gregor2010-01-111-1/+1
| | | | | | | latter may (eventually) perform multiple levels of desugaring (thus breaking the newly-added tests) and the former is faster. Thanks, John! llvm-svn: 93192
* Allow redefinitions of typedef-names within class scope when the typeDouglas Gregor2010-01-111-4/+29
| | | | | | | | | they redefine is a class-name but not a typedef-name, per C++0x [dcl.typedef]p4. The code in the test was valid C++98 and is valid C++0x, but an unintended consequence of DR56 made it ill-formed in C++03 (which we were luck enough to implement). Fixes PR5455. llvm-svn: 93188
* Whenever we emit a typo-correction diagnostic, also emit a noteDouglas Gregor2010-01-071-0/+6
| | | | | | | pointing to the declaration that we found that has that name (if it is unique). llvm-svn: 92877
* Make sure that the key-function computation produces the correctDouglas Gregor2010-01-061-10/+27
| | | | | | | | result for a nested class whose first non-pure virtual member function has an inline body. Previously, we were checking for the key function before we had seen the (delayed) inline body. llvm-svn: 92839
* Make our marking of virtual members functions in a class beDouglas Gregor2010-01-061-0/+10
| | | | | | | | | | | | | | | | | | | | | deterministic and work properly with templates. Once a class that needs a vtable has been defined, we now do one if two things: - If the class has no key function, we place the class on a list of classes whose virtual functions will need to be "marked" at the end of the translation unit. The delay until the end of the translation unit is needed because we might see template specializations of these virtual functions. - If the class has a key function, we do nothing; when the key function is defined, the class will be placed on the aforementioned list. At the end of the translation unit, we "mark" all of the virtual functions of the classes on the list as used, possibly causing template instantiation and other classes to be added to the list. This gets LLVM's lib/Support/CommandLine.cpp compiling again. llvm-svn: 92821
* Improve key-function computation for templates. In particular:Douglas Gregor2010-01-051-1/+1
| | | | | | | | | | | | | | | | - All classes can have a key function; templates don't change that. non-template classes when computing the key function. - We always mark all of the virtual member functions of class template instantiations. - The vtable for an instantiation of a class template has weak linkage. We could probably use available_externally linkage for vtables of classes instantiated by explicit instantiation declarations (extern templates), but GCC doesn't do this and I'm not 100% that the ABI permits it. llvm-svn: 92753
* Avoid warnings for functions that return a value using MS-style inlineMike Stump2010-01-041-0/+8
| | | | | | | | | | | | | assembly code. This avoids changing the bahvior when normal asm("") statements are used. The type of code affected would be: void* t4(void) { __asm mov eax, fs:[0x10] } I hope people like this version, if not, let me know. llvm-svn: 92531
* Implement typo correction for a variety of Objective-C-specificDouglas Gregor2010-01-031-1/+25
| | | | | | | | | | | | | | constructs: - Instance variable lookup ("foo->ivar" and, in instance methods, "ivar") - Property name lookup ("foo.prop") - Superclasses - Various places where a class name is required - Protocol names (e.g., id<proto>) This seems to cover many of the common places where typos could occur. llvm-svn: 92449
* when making a decl for __builtin_fabsf() make sure toChris Lattner2009-12-301-0/+4
| | | | | | | | attach the appropriate attributes to it. I don't think this manifests as any real change though, we're still not getting the right LLVM IR attributes out of codegen. llvm-svn: 92316
* Typo correction for type names when they appear in declarations, e.g., givenDouglas Gregor2009-12-301-1/+32
| | | | | | | | | | | | | | | | | | | | | | | | tring str2; we produce the following diagnostic + fix-it: typo.cpp:15:1: error: unknown type name 'tring'; did you mean 'string'? tring str2; ^~~~~ string To make this really useful, we'll need to introduce typo correction in many more places (wherever we do name lookup), and implement declaration-vs-expression heuristics that cope with typos better. However, for now this will handle the simple cases where we already get good "unknown type name" diagnostics. The LookupVisibleDecls functions are intended to be used by code completion as well as typo correction; that refactoring will happen later. llvm-svn: 92308
* Typedefs can be redeclared. That seems like something we should record inJohn McCall2009-12-301-3/+9
| | | | | | the AST lest we run into some crazy canonicalization bug like PR5874. llvm-svn: 92283
* Tweak the text of several main() diagnostics and punch a hole specifically forJohn McCall2009-12-241-2/+12
| | | | | | | | | | Darwin's sekrit fourth argument. This should probably be factored to let targets make target-specific decisions about what main() should look like. Fixes rdar://problem/7414990 or if different platforms have radically different ideas of what they want in llvm-svn: 92128
* allow the noreturn attribute to be used in class methodsNuno Lopes2009-12-231-1/+3
| | | | llvm-svn: 92090
* Switch file-scope assignment initialization over to InitializationSequence.Eli Friedman2009-12-221-13/+16
| | | | llvm-svn: 91881
* Eliminate the ASTContext argument to CXXConstructorDecl::isCopyConstructor, ↵Douglas Gregor2009-12-221-1/+1
| | | | | | since the context is available in the Decl llvm-svn: 91862
* Fix for PR5840: fix the kind of name lookup used for classes inEli Friedman2009-12-211-2/+6
| | | | | | | | | | Sema::getTypeName. "LookupNestedNameSpecifierName" isn't quite the right kind of lookup, though; it doesn't ignore namespaces. Someone more familiar with the lookup code should fix this properly. llvm-svn: 91809
* Make sure we instantiate the destructor for variables initialized byEli Friedman2009-12-201-0/+9
| | | | | | assignment. llvm-svn: 91798
* Switch default-initialization of variables of class type (or array thereof) ↵Douglas Gregor2009-12-201-20/+11
| | | | | | over to InitializationSequence. I could swear that this fixes a PR somewhere, but I couldn't figure out which one llvm-svn: 91796
* Revert accidental commitDouglas Gregor2009-12-201-11/+20
| | | | llvm-svn: 91795
* Fix CMake build on windows, from Cedric VenetDouglas Gregor2009-12-201-20/+11
| | | | llvm-svn: 91794
* Don't inject the class name until that magical lbrace.John McCall2009-12-201-24/+29
| | | | | | | | | | | | | | | | Because of the rules of base-class lookup* and the restrictions on typedefs, it was actually impossible for this to cause any problems more serious than the spurious acceptance of template <class T> class A : B<A> { ... }; instead of template <class T> class A : B<A<T> > { ... }; but I'm sure we can all agree that that is a very important restriction which is well worth making another Parser->Sema call for. (*) n.b. clang++ does not implement these rules correctly; we are not ignoring non-type names llvm-svn: 91792
* Refactor to remove more dependencies on PreDeclaratorDC. I seem to have madeJohn McCall2009-12-191-11/+35
| | | | | | | the redeclaration problems in the [temp.explicit]p3 testcase worse, but I can live with that; they'll need to be fixed more holistically anyhow. llvm-svn: 91771
* Don't use EnterDeclaratorContext when rebuilding a type in the currentJohn McCall2009-12-191-2/+5
| | | | | | instantiation, since we're not using a Scope object for that anyway. llvm-svn: 91770
* Initialization improvements: addition of string initialization and a fewEli Friedman2009-12-191-17/+13
| | | | | | | | 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
* Pull Sema::isAcceptableLookupResult into SemaLookup. Extract the criteria intoJohn McCall2009-12-181-18/+16
| | | | | | | | | | | | | | | different functions and pick the function at lookup initialization time. In theory we could actually divide the criteria functions into N different functions for the N cases, but it's so not worth it. Among other things, lets us invoke LookupQualifiedName without recomputing IDNS info every time. Do some refactoring in SemaDecl to avoid an awkward special case in LQN that was only necessary for redeclaration testing for anonymous structs/unions --- which could be done more efficiently with a scoped lookup anyway. llvm-svn: 91676
* Revert r91073.Mike Stump2009-12-171-5/+0
| | | | llvm-svn: 91629
* implement PR3962: diagnose more faulty cases of usage of the restrict ↵Nuno Lopes2009-12-171-1/+9
| | | | | | qualifier. this also removes a FIXME llvm-svn: 91601
* revert part of my last patch, and mark only the c++ global new operator as ↵Nuno Lopes2009-12-171-5/+0
| | | | | | noalias. the rest will be infered by llvm optz llvm-svn: 91600
* Make sure C-specific enum warning doesn't trigger in C++.Eli Friedman2009-12-161-1/+1
| | | | llvm-svn: 91563
* implement PR5654: add -fassume-sane-operator-new, which is enabled by ↵Nuno Lopes2009-12-161-0/+5
| | | | | | | | default, and adds the malloc attribute to the global function new() and to the overloaded new operators. feel free to chage the name to this lengthy argument llvm-svn: 91543
* Switch the C++ new expression over to InitializationSequence, ratherDouglas Gregor2009-12-161-14/+14
| | | | | | | | | | | | | | | | | | | | | 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
* ShouldDestroyTemporaries? I don't think so.Anders Carlsson2009-12-151-2/+1
| | | | llvm-svn: 91450
* This patch should fix PR2461. It allows clang to apply the noreturnMike Stump2009-12-151-5/+4
| | | | | | | | | attribute to function pointers. It also fixes Sema to check function pointers for the noreturn attribute when checking for fallthrough. Patch by Chip Davis, with a slight fix to pass the testsuite. llvm-svn: 91408
* Fix the handling of dependent enums per C++ DR 502.Eli Friedman2009-12-111-4/+18
| | | | llvm-svn: 91089
* Don't complain about falling off the end of a function with an asmMike Stump2009-12-101-0/+5
| | | | | | | block, if the function is supposed to return a value as we don't know exactly what the asm code does. llvm-svn: 91073
* Clean up enum constants so that they're finally sane. Fixes PR3173 and aEli Friedman2009-12-101-14/+4
| | | | | | recently introduced crash. llvm-svn: 91070
* Improve the diagnostic when a new declaration conflicts with a using shadowJohn McCall2009-12-101-0/+9
| | | | | | | | declaration. Rename note_using_decl to note_using, which is possibly less confusing. Add a test for non-class-scope using decl collisions and be sure to note the case we can't diagnose yet. llvm-svn: 91057
* Move initialization via initializer list over to InitializationSequences.Douglas Gregor2009-12-101-4/+5
| | | | llvm-svn: 91050
* Implement redeclaration checking and hiding semantics for using ↵John McCall2009-12-101-4/+7
| | | | | | | | | | | declarations. There are a couple of O(n^2) operations in this, some analogous to the usual O(n^2) redeclaration problem and some not. In particular, retroactively removing shadow declarations when they're hidden by later decls is pretty unfortunate. I'm not yet convinced it's worse than the alternative, though. llvm-svn: 91045
* Fix for PR5515: allow "merging" array bounds both forwards and backwards.Eli Friedman2009-12-101-4/+13
| | | | llvm-svn: 91044
* Reimplement reference initialization (C++ [dcl.init.ref]) using theDouglas Gregor2009-12-091-3/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* First pass at implementing C++ enum semantics: calculate (and store) anJohn McCall2009-12-091-15/+40
| | | | | | | | | | | | "integer promotion" type associated with an enum decl, and use this type to determine which type to promote to. This type obeys C++ [conv.prom]p2 and is therefore generally signed unless the range of the enumerators forces it to be unsigned. Kills off a lot of false positives from -Wsign-compare in C++, addressing rdar://7455616 llvm-svn: 90965
* Don't warn about function templates or function template specializations.Anders Carlsson2009-12-091-5/+13
| | | | llvm-svn: 90943
* Rename Sema::IsOverload to Sema::CheckOverload. Teach it to ignore unresolvedJohn McCall2009-12-091-24/+34
| | | | | | | | using value decls; we optimistically assume they won't turn into conflicts. Teach it to tell the caller *why* the function doesn't overload with the returned decl; this will be useful for using hiding. llvm-svn: 90939
* Move the missing prototypes checking out into a new function. Don't warn ↵Anders Carlsson2009-12-091-17/+38
| | | | | | about inline functions. Add a test. llvm-svn: 90938
* Fix for PR5710: make sure to put function template specializations into theEli Friedman2009-12-081-4/+4
| | | | | | | | | | DeclContext, so they don't completely disappear from the AST. I don't particularly like this fix, but I don't see any obviously better way to deal with it, and I think it's pretty clearly an improvement; comments welcome. llvm-svn: 90835
OpenPOWER on IntegriCloud