Commit Graph

239 Commits

Author SHA1 Message Date
Fariborz Jahanian 9a587b0111 Patch implements ranking conversions between member pointers [over.ics.rank]
llvm-svn: 84660
2009-10-20 20:04:46 +00:00
Eli Friedman 06ed2a5c94 Remove default argument for ImpCastExprToType. Add appropriate argument
to all callers.  Switch a few other users of CK_Unknown to proper cast 
kinds.

Note that there are still some situations where we end up with 
CK_Unknown; they're pretty easy to find with grep. There 
are still a few missing conversion kinds, specifically 
pointer/int/float->bool and the various combinations of real/complex 
float/int->real/complex float/int.

llvm-svn: 84623
2009-10-20 08:27:19 +00:00
Fariborz Jahanian a4a9334a50 Builtin candidate minimization for
<<=, >>= and the rest.

llvm-svn: 84568
2009-10-20 00:04:40 +00:00
Fariborz Jahanian b9e8c42ee6 Add the built-in candidate set reduction hueristic
to '+=', '-=', '*=' and '/=' builtin operators and
fixes a logic bug exposed by doing this.

llvm-svn: 84538
2009-10-19 21:30:45 +00:00
Fariborz Jahanian 996a6aa3f1 Copy conversion of an expression to its base class
is a standard convesion and not a user-defined
conversion.

llvm-svn: 84525
2009-10-19 19:18:20 +00:00
Sebastian Redl df4b80e7c0 When resolving the address of an overloaded function or function template, mark the result as referenced.
The most important effect of this is that function templates only referenced by address expressions now get instantiated. This, in turn, means that Hello World compiles with the Apache stdcxx library even when using endl.

llvm-svn: 84363
2009-10-17 21:12:09 +00:00
Sebastian Redl fef1c0d54f Don't add implicit casts of explicit address-taking of overloaded functions.
Taking the address of an overloaded function with an explicit address-of operator wrapped the operator in an implicit cast that added yet another pointer level, leaving us with a corrupted AST, which crashed CodeGen in the test case I've added. Fix this by making FixOverloadedFunctionReference return whether there was an address-of operator and not adding the implicit cast in that case.

llvm-svn: 84362
2009-10-17 20:50:27 +00:00
Fariborz Jahanian 956127de22 Patch to clean up and improve visual display of
builtin function ambiguity.

llvm-svn: 84289
2009-10-16 23:25:02 +00:00
Fariborz Jahanian b06ec054fc Use VisibleQuals to control setting of Volatile/Restrict qualifiers on
candidate types in BuiltinCandidateTypeSet::AddPointerWithMoreQualifiedTypeVariants
further trimming the overload candidate set.

llvm-svn: 84281
2009-10-16 22:08:05 +00:00
Fariborz Jahanian 3b937fa298 Apply heuristics to cut back on number of candidate
sets of builtin operators. Currently, it is applied 
to '++' and '->*' operators. I need to apply it to others
as well. Also, heuristics need be applied to 
BuiltinCandidateTypeSet::AddPointerWithMoreQualifiedTypeVariants.
This is WIP.

llvm-svn: 84187
2009-10-15 17:14:05 +00:00
Douglas Gregor 4aa2dc41dc Implement support for overloaded operator uses that result to a call
to a member operator template. We missed updating this call site when
adding support for function templates; bug exposed by a test for
PR5072.

llvm-svn: 84111
2009-10-14 16:50:13 +00:00
Anders Carlsson e4f4b5e919 Check the return type of binary operators and the arrow operator.
llvm-svn: 84043
2009-10-13 22:43:21 +00:00
Anders Carlsson 3d5829cd4f More return type checking.
llvm-svn: 84034
2009-10-13 21:49:31 +00:00
Anders Carlsson f64a3dae04 Diagnose invalid return types for unary operators.
llvm-svn: 84030
2009-10-13 21:19:37 +00:00
Fariborz Jahanian e7196431c1 Handle built-in unary operators when reporting ambiguities.
wip - To prune excessive reporting.

llvm-svn: 83889
2009-10-12 20:11:40 +00:00
Fariborz Jahanian 574de2c5a4 If built-in operators could not be selected because of ambiguity in
user-defined type conversions, issue list of ambiguites in addition 
to the diagnostic. So, clang now issues the following:

b.cpp:19:19: error: left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'struct C1'
        int i = c1->*pmf;
                ~~^
b.cpp:19:19: note: because of ambiguity in conversion of 'struct C1' to 'struct E *'
b.cpp:5:5: note: candidate function
    operator E*();
    ^
b.cpp:11:5: note: candidate function
    operator E*();
    ^

llvm-svn: 83862
2009-10-12 17:51:19 +00:00
Anders Carlsson c4859baea4 Check that the return type is complete when calling a member function.
llvm-svn: 83694
2009-10-10 00:06:20 +00:00
Anders Carlsson 7f84ed9287 Add CheckCallReturnType and start using it for regular call expressions. This will improve error messages. For
struct B;

B f();

void g() {
f();
}

We now get

t.cpp:6:3: error: calling 'f' with incomplete return type 'struct B'
  f();
  ^~~
t.cpp:3:3: note: 'f' declared here
B f();
  ^
t.cpp:1:8: note: forward declaration of 'struct B'
struct B;
       ^

llvm-svn: 83692
2009-10-09 23:51:55 +00:00
Douglas Gregor 7d195b93d8 Add some FIXMEs
llvm-svn: 83685
2009-10-09 22:54:25 +00:00
John McCall 9f3059a192 Refactor the LookupResult API to simplify most common operations. Require users to
pass a LookupResult reference to lookup routines.  Call out uses which assume a single
result.

llvm-svn: 83674
2009-10-09 21:13:30 +00:00
Fariborz Jahanian 0fe5e0308e Produce good looking diagnostics on ambiguous built-in operators.
Now we produce things like:
bug1.cpp:21:11: error: use of overloaded operator '->*' is ambiguous
        int i = c->*pmf;        // expected-error {{use of overloaded operator '->*' is ambiguous}} \
                ~^  ~~~
bug1.cpp:21:11: note: built-in candidate operator ->* ('struct A volatile *', 'int const struct A::*')
bug1.cpp:21:11: note: built-in candidate operator ->* ('struct A volatile *', 'int restrict struct A::*')
...

Still need to look at an issue (indicated as FIXME in the test case).

llvm-svn: 83650
2009-10-09 17:09:58 +00:00
Fariborz Jahanian 4dc1246d87 Use the new API for applying the qualifiers on built-in '->*'
operator's types.

llvm-svn: 83648
2009-10-09 16:34:40 +00:00
Fariborz Jahanian 29f9d39568 Improve on reporting ambiguity involving built-in candidates.
I still don't like it but it is improvement over what we had.

llvm-svn: 83603
2009-10-09 00:13:15 +00:00
Anders Carlsson 6c966c458a Handle MemberExprs in ResolveAddressOfOverloadedFunction.
llvm-svn: 83495
2009-10-07 22:26:29 +00:00
Fariborz Jahanian ae01f78a31 When building candidate set for built-ins; when looking for
convesion functions, look in base classes to.
(Removes a FIXME).

llvm-svn: 83472
2009-10-07 17:26:09 +00:00
Fariborz Jahanian 12df37c5d7 Removed couple of unnecessary canonicalization
per Doug's obsevation.

llvm-svn: 83464
2009-10-07 16:56:50 +00:00
Fariborz Jahanian 34d93dcddd Patch to implement C++ [over.built]p11 of overload resolution.
Doug, please review. There is a FIXME in the test case with a question
which is unrelated to this patch (that is, error is issued
before set of builtins are added to the candidate list).

llvm-svn: 83429
2009-10-06 23:08:05 +00:00
Douglas Gregor 36d1b14dde Refactor the code that walks a C++ inheritance hierarchy, searching
for bases, members, overridden virtual methods, etc. The operations
isDerivedFrom and lookupInBases are now provided by CXXRecordDecl,
rather than by Sema, so that CodeGen and other clients can use them
directly.

llvm-svn: 83396
2009-10-06 17:59:45 +00:00
Fariborz Jahanian 333bb733a5 Refixed pr5086 by letting Expr::isNullPointerConstant
handle checking for a null pointer for a zero-valued
enumerator; moving the test case from CodeGen to Sema.

llvm-svn: 83350
2009-10-06 00:09:31 +00:00
Fariborz Jahanian a0f91ad59c enumerator value of 0 is not a null pointer constant for
deciding const of null pointer conversion. Fixes PR5086.

llvm-svn: 83217
2009-10-01 22:10:15 +00:00
Fariborz Jahanian b3c44f9ee9 Patch to implement static casting which requires one
user-defined type conversion. Fixes PR5040.

llvm-svn: 83211
2009-10-01 20:39:51 +00:00
Douglas Gregor 66950a32d9 When overload resolution fails for an overloaded operator, show the
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
2009-09-30 21:46:01 +00:00
Fariborz Jahanian ac3005cecc Note location of operators caused the circularity.
llvm-svn: 83153
2009-09-30 17:46:20 +00:00
Fariborz Jahanian 91ae9fd9e8 Fixes a nasty bug which only turned up in 32bit build of clang and
had to do with an initialized field when multiple type conversions
are ambiguous but must be treated as user defined conversion for
overload resolution purposes.

llvm-svn: 83079
2009-09-29 17:31:54 +00:00
Fariborz Jahanian 78cfcb56a1 Define and use a helper method to call a type conversion
function.

llvm-svn: 83027
2009-09-28 23:23:40 +00:00
Fariborz Jahanian 9021fc7026 Minor API change. No change in functionality.
llvm-svn: 83022
2009-09-28 22:03:07 +00:00
Fariborz Jahanian c9c3917a86 Multiple conversions to the same type are ambiguous but for the
purpose of overload resolution is to be treated as a uner-defined
conversion.

llvm-svn: 83004
2009-09-28 19:06:58 +00:00
Fariborz Jahanian 774cf79987 Patch for AST representation for the implicit conversion to a function
reference/pointer. And a test case for code gen.

llvm-svn: 83000
2009-09-28 18:35:46 +00:00
Douglas Gregor 5b0f2a2fbe Don't allow the same function to enter the overload candidate set
multiple times. This requires to be more careful about re-adding
candidates cached from the function template definition.

llvm-svn: 82967
2009-09-28 04:47:19 +00:00
Douglas Gregor fae1d71592 Yet another simplifying use of Sema::getMostSpecialized
llvm-svn: 82844
2009-09-26 03:56:17 +00:00
Douglas Gregor 56751b5981 Fix checking for a null pointer constant when the expression itself is
value-dependent. Audit (and fixed) all calls to
Expr::isNullPointerConstant() to provide the correct behavior with
value-dependent expressions. Fixes PR5041 and a crash in libstdc++
<locale>.

In the same vein, properly compute value- and type-dependence for
ChooseExpr. Fixes PR4996.

llvm-svn: 82748
2009-09-25 04:25:58 +00:00
Douglas Gregor 3a923c2d37 WIP implementation of explicit function template specialization. This
first implementation recognizes when a function declaration is an
explicit function template specialization (based on the presence of a
template<> header), performs template argument deduction + ambiguity
resolution to determine which template is being specialized, and hooks

There are many caveats here:
  - We completely and totally drop any explicitly-specified template
  arguments on the floor
  - We don't diagnose any of the extra semantic things that we should
  diagnose. 
  - I haven't looked to see that we're getting the right linkage for
  explicit specializations

On a happy note, this silences a bunch of errors that show up in
libstdc++'s <iostream>, although Clang still can't get through the
entire header.

llvm-svn: 82728
2009-09-24 23:14:47 +00:00
John McCall 8ccfcb51ee Refactor the representation of qualifiers to bring ExtQualType out of the
Type hierarchy.  Demote 'volatile' to extended-qualifier status.  Audit our
use of qualifiers and fix a few places that weren't dealing with qualifiers
quite right;  many more remain.

llvm-svn: 82705
2009-09-24 19:53:00 +00:00
Douglas Gregor c809cc2efa Improve diagnostic location information when checking the initialization of a reference
llvm-svn: 82666
2009-09-23 23:04:10 +00:00
Douglas Gregor 2a920014d3 When code-completion after a "," is building an overload set, note
that there is one more argument (the one following the comma) and make
the candidate non-viable if the function cannot accept any argument in
that position.

llvm-svn: 82625
2009-09-23 14:56:09 +00:00
Fariborz Jahanian 21ccf06352 Produce detailed diagnostics when overload
resolution failed to select a candidate due to
ambiguity in type conversion function selection.

llvm-svn: 82596
2009-09-23 00:58:07 +00:00
Fariborz Jahanian f0647a5fbc Code refactoring and cleanup.
llvm-svn: 82566
2009-09-22 20:24:30 +00:00
Fariborz Jahanian 0b51c729c9 Issue good ambiguity diagnostic when convesion fails.
llvm-svn: 82565
2009-09-22 19:53:15 +00:00
Douglas Gregor cabea40ea3 Implement code completion within a function call, triggered after the
opening parentheses and after each comma. We gather the set of visible
overloaded functions, perform "partial" overloading based on the set
of arguments that we have thus far, and return the still-viable
results sorted by the likelihood that they will be the best candidate.

Most of the changes in this patch are a refactoring of the overloading
routines for a function call, since we needed to separate out the
notion of building an overload set (common to code-completion and
normal semantic analysis) and then what to do with that overload
set. As part of this change, I've pushed explicit template arguments
into a few more subroutines.

There is still much more work to do in this area. Function templates
won't be handled well (unless we happen to deduce all of the template
arguments before we hit the completion point), nor will overloaded
function-call operators or calls to member functions.

llvm-svn: 82549
2009-09-22 15:41:20 +00:00
John McCall 9dd450bb78 Change all the Type::getAsFoo() methods to specializations of Type::getAs().
Several of the existing methods were identical to their respective
specializations, and so have been removed entirely.  Several more 'leaf'
optimizations were introduced.

The getAsFoo() methods which imposed extra conditions, like
getAsObjCInterfacePointerType(), have been left in place.

llvm-svn: 82501
2009-09-21 23:43:11 +00:00