summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/overloaded-operator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Correctly resolve an overload set passed to an overloaded operator=. PR11784.Eli Friedman2012-01-171-0/+7
| | | | llvm-svn: 148335
* Modify how the -verify flag works. Currently, the verification string andRichard Trieu2011-12-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | diagnostic message are compared. If either is a substring of the other, then no error is given. This gives rise to an unexpected case: // expect-error{{candidate function has different number of parameters}} will match the following error messages from Clang: candidate function has different number of parameters (expected 1 but has 2) candidate function has different number of parameters It will also match these other error messages: candidate function function has different number of parameters number of parameters This patch will change so that the verification string must be a substring of the diagnostic message before accepting. Also, all the failing tests from this change have been corrected. Some stats from this cleanup: 87 - removed extra spaces around verification strings 70 - wording updates to diagnostics 40 - extra leading or trailing characters (typos, unmatched parens or quotes) 35 - diagnostic level was included (error:, warning:, or note:) 18 - flag name put in the warning (-Wprotocol) llvm-svn: 146619
* Teach the ARC compiler to not require __bridge casts whenJohn McCall2011-10-171-1/+1
| | | | | | | passing/receiving CF objects at +0 to/from Objective-C methods or audited C functions. llvm-svn: 142219
* Catch placeholder types in DefaultLvalueConversionJohn McCall2011-10-111-1/+1
| | | | | | | | | | | and DefaultFunctionArrayLvalueConversion. To prevent significant regression for should-this-be-a-call fixits, and to repair some such regression from the introduction of bound member placeholders, make those placeholder checks try to build calls appropriately. Harden the build-a-call logic while we're at it. llvm-svn: 141738
* Whitelist operator== and operator!= as valid for unused value warnings,Chandler Carruth2011-08-171-2/+2
| | | | | | | | even when overloaded and user-defined. These operators are both more valuable to warn on (due to likely typos) and extremely unlikely to be reasonable for use to trigger side-effects. llvm-svn: 137823
* With invalid overloaded operators, we can get into funny cases whereDouglas Gregor2011-05-051-4/+13
| | | | | | | | | | the overloading of member and non-member functions results in arity mismatches that don't fit well into our overload-printing scheme. This only happens for invalid code (which breaks the arity invariants for these cases), so just suppress the diagnostic rather than inventing anything new. Fixes <rdar://problem/9222009>. llvm-svn: 130902
* Make yet another placeholder type, this one marking that an expression is a ↵John McCall2011-04-261-4/+4
| | | | | | | | | | | bound member function, i.e. something of the form 'x.f' where 'f' is a non-static member function. Diagnose this in the general case. Some of the new diagnostics are probably worse than the old ones, but we now get this right much more universally, and there's certainly room for improvement in the diagnostics. llvm-svn: 130239
* Basic, untested implementation for an "unknown any" type requested by LLDB.John McCall2011-04-071-4/+3
| | | | | | | | | | | | The idea is that you can create a VarDecl with an unknown type, or a FunctionDecl with an unknown return type, and it will still be valid to access that object as long as you explicitly cast it at every use. I'm still going back and forth about how I want to test this effectively, but I wanted to go ahead and provide a skeletal implementation for the LLDB folks' benefit and because it also improves some diagnostic goodness for placeholder expressions. llvm-svn: 129065
* Don't indescriminately print overload candidates when we have invalidDouglas Gregor2011-03-161-0/+16
| | | | | | | | | operands to a binary expression; it doesn't make sense in all contexts. The right answer would be to see if the user forgot at (). Fixes <rdar://problem/9136502>. llvm-svn: 127740
* Implement -Wenum-compare, which warns when comparing two enums ofChandler Carruth2011-02-171-2/+2
| | | | | | | | | | | different types. We omit the warning when the enum types are anonymous. Unlike GCC, this warning does not distinguish between C++ and C/ObjC for controling whether it is on by default, it is always on by default. Original patch contributed by Richard Trieu (@ Google), I fixed some style issues, and cleaned it up for submission. llvm-svn: 125739
* When complaining about ambiguous overload resolution for a unary orDouglas Gregor2010-11-131-2/+2
| | | | | | binary operator, provide the types. llvm-svn: 119008
* Revert r114316, -Wunused-value enabled by default was intended.Argyrios Kyrtzidis2010-09-191-1/+1
| | | | llvm-svn: 114318
* Make -Wunused-value off by default, matching GCC. Fixes rdar://7126194.Argyrios Kyrtzidis2010-09-191-1/+1
| | | | llvm-svn: 114316
* 'const std::type_info*' instead of 'std::type_info const*'Chris Lattner2010-09-051-1/+1
| | | | llvm-svn: 113092
* Bowing to popular demand, reduce the "comma at end of enumerator list"Douglas Gregor2010-07-081-1/+1
| | | | | | ExtWarn to an Extension. Let the broken code propagate! llvm-svn: 107875
* By default, warn about commas at the end of an enumerator list in C++/C89.Douglas Gregor2010-07-021-1/+1
| | | | llvm-svn: 107485
* Fix rdar://8139785 "implement warning on dead expression in comma operator"Argyrios Kyrtzidis2010-06-301-1/+1
| | | | | | | | | | As a bonus, fix the warning for || and && operators; it was emitted even if one of the operands had side effects, e.g: x || test_logical_foo1(); emitted a bogus "expression result unused" for 'x'. llvm-svn: 107274
* Warn about comparisons between arrays and improve self-comparisonDouglas Gregor2010-06-081-0/+7
| | | | | | warnings, from Troy Straszheim! Fixes PR6163. llvm-svn: 105631
* When performing name lookup for an operator name, be sure to lookDouglas Gregor2010-04-251-0/+21
| | | | | | through using declarations. Fixes ~18 tests in Boost.Fusion. llvm-svn: 102311
* Change the 'declared at' diagnostic to say 'declared here'.Anders Carlsson2010-04-231-4/+4
| | | | llvm-svn: 102163
* Turn access control on by default in -cc1.John McCall2010-04-091-0/+1
| | | | | | | | Remove -faccess-control from -cc1; add -fno-access-control. Make the driver pass -fno-access-control by default. Update a bunch of tests to be correct under access control. llvm-svn: 100880
* When pretty-printing tag types, only print the tag if we're in C (andJohn McCall2010-03-101-4/+4
| | | | | | | | | | therefore not creating ElaboratedTypes, which are still pretty-printed with the written tag). Most of these testcase changes were done by script, so don't feel too sorry for my fingers. llvm-svn: 98149
* Rework base and member initialization in constructors, with severalDouglas Gregor2010-01-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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
* When computing surrogates for calls to a value of object type, lookDouglas Gregor2010-01-111-4/+11
| | | | | | for all visible conversion functions. llvm-svn: 93173
* Improve the lead diagnostic for C++ object subscript expressions withJohn McCall2010-01-071-0/+24
| | | | | | | | | no viable overloads. Use a different message when the class provides no operator[] overloads at all; use it for operator(), too. Partially addresses PR 5900. llvm-svn: 92894
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). llvm-svn: 91446
* Reimplement reference initialization (C++ [dcl.init.ref]) using theDouglas Gregor2009-12-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Do overload resolution for compound assignment even if only the RHS is ↵Sebastian Redl2009-11-181-0/+28
| | | | | | overloadable. Compound assignment may be overloaded as a non-member, and anyway the overload resolution is necessary because it triggers implicit (used-defined) conversions. Fixes PR5512, but not really the deeper issues lurking. Those are standard defects. llvm-svn: 89268
* Don't generate superfluous and ambiguous built-in candidates for multi-level ↵Sebastian Redl2009-11-181-0/+10
| | | | | | array subscript and arithmetic. Fixes PR5546. llvm-svn: 89242
* When looking for operator() to type-check a call to an object of classDouglas Gregor2009-11-151-1/+8
| | | | | | | | | type, use full qualified name lookup rather than the poking the declaration context directly. This makes sure that we see operator()'s in superclasses. Also, move the complete-type check before this name lookup. llvm-svn: 88842
* When collecting types for built-in candidates, make arrays decay to ↵Sebastian Redl2009-11-051-0/+11
| | | | | | pointers. Otherwise, subscripting an array leads to no candidates at all. Fixes PR5360. llvm-svn: 86140
* Apply the special enum restrictions from [over.match.oper]p3b2 in ↵Sebastian Redl2009-10-231-0/+28
| | | | | | argument-dependent lookup too. This fixes PR5244. llvm-svn: 84963
* When building types from declarators, instead of building two types (one forJohn McCall2009-10-221-1/+1
| | | | | | | | | | | | | | | | | | | | | the DeclaratorInfo, one for semantic analysis), just build a single type whose canonical type will reflect the semantic analysis (assuming the type is well-formed, of course). To make that work, make a few changes to the type system: * allow the nominal pointee type of a reference type to be a (possibly sugared) reference type. Also, preserve the original spelling of the reference type. Both of these can be ignored on canonical reference types. * Remove ObjCProtocolListType and preserve the associated source information on the various ObjC TypeLocs. Preserve the spelling of protocol lists except in the canonical form. * Preserve some level of source type structure on parameter types, but canonicalize on the canonical function type. This is still a WIP. Drops code size, makes strides towards accurate source location representation, slight (~1.7%) progression on Cocoa.h because of complexity drop. llvm-svn: 84907
* When overload resolution fails for an overloaded operator, show theDouglas Gregor2009-09-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | overload candidates (but not the built-in ones). We still rely on the underlying built-in semantic analysis to produce the initial diagnostic, then print the candidates following that diagnostic. One side advantage of this approach is that we can perform more validation of C++'s operator overloading with built-in candidates vs. the semantic analysis for those built-in operators: when there are no viable candidates, we know to expect an error from the built-in operator handling code. Otherwise, we are not modeling the built-in semantics properly within operator overloading. This is checked as: assert(Result.isInvalid() && "C++ binary operator overloading is missing candidates!"); if (Result.isInvalid()) PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false); The assert() catches cases where we're wrong in a +Asserts build. The "if" makes sure that, if this happens in a production clang (-Asserts), we still build the proper built-in operator and continue on our merry way. This is effectively what happened before this change, but we've added the assert() to catch more flies. llvm-svn: 83175
* Note location of operators caused the circularity.Fariborz Jahanian2009-09-301-4/+4
| | | | llvm-svn: 83153
* Detect operator-> chains of arbitrary length. Use a terrible data structureJohn McCall2009-09-301-0/+16
| | | | | | to strike fear into the hearts of CPUs everywhere. llvm-svn: 83133
* self-referecing operator '->' member function was causingFariborz Jahanian2009-09-301-0/+11
| | | | | | infinit recursion. This patch fixes it. [13.3.1.2]-p2 llvm-svn: 83124
* 13.1-p3 Overloadable declarationsFariborz Jahanian2009-09-291-1/+1
| | | | | | Parameter declarations that differ only in the presence or absence of const and/or volatile are equivalent. llvm-svn: 83104
* When looking for overloaded member operators, make sure to instantiateDouglas Gregor2009-08-271-0/+4
| | | | | | | | | class template specializations (when possible) and look into base classes. Thanks to Eli for the test case! FIXME -=1. llvm-svn: 80302
* Create a new PrintingPolicy class, which we pass down through the ASTDouglas Gregor2009-05-291-1/+1
| | | | | | | | | printing logic to help customize the output. For now, we use this rather than a special flag to suppress the "struct" when printing "struct X" and to print the Boolean type as "bool" in C++ but "_Bool" in C. llvm-svn: 72590
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* Almost complete implementation of rvalue references. One bug, and a few ↵Sebastian Redl2009-03-161-1/+1
| | | | | | unclear areas. Maybe Doug can shed some light on some of the fixmes. llvm-svn: 67059
* Bring operator name lookup (as required for C++ operator overloading)Douglas Gregor2009-02-041-2/+1
| | | | | | | into the general name-lookup fold. This cleans up some ugly, not-quite-working code in the handling of operator overloading. llvm-svn: 63735
* Initial implementation of argument dependent lookup (a.k.a. ADL,Douglas Gregor2009-02-041-0/+15
| | | | | | | | | | | | a.k.a. Koenig lookup) in C++. Most of the pieces are in place, but for two: - In an unqualified call g(x), even if the name does not refer to anything in the current scope, we can still find functions named "g" based on ADL. We don't yet have this ability. - ADL will need updating for friend functions and templates. llvm-svn: 63692
* Fix argument-passing bugs in a call to objectDouglas Gregor2009-01-131-2/+14
| | | | llvm-svn: 62147
* Make sure we don't name a constructor or destructor with a qualifiedDouglas Gregor2009-01-131-0/+11
| | | | | | type. It leads to very weird errors. llvm-svn: 62124
* Implement a %plural modifier for complex plural forms in diagnostics. Use it ↵Sebastian Redl2008-11-221-1/+1
| | | | | | in the overload diagnostics. llvm-svn: 59871
* Fix overloading of non-static member functions that differ in their ↵Douglas Gregor2008-11-211-3/+5
| | | | | | cv-qualifiers llvm-svn: 59819
* Don't print canonical types in overloading-related diagnosticsDouglas Gregor2008-11-211-2/+4
| | | | llvm-svn: 59789
* Add support for overloaded operator-> when used in a member accessDouglas Gregor2008-11-201-0/+18
| | | | | | expression (smart_ptr->mem). llvm-svn: 59732
OpenPOWER on IntegriCloud