Commit Graph

983 Commits

Author SHA1 Message Date
Rafael Espindola c18086ae17 Add support for the weakref attribute. We still produce "alias weak" as llvm-gcc does, but are more strict on what uses of weakref we accept.
llvm-svn: 96992
2010-02-23 22:00:30 +00:00
Douglas Gregor 46841e1bd9 Implement crazy destructor name lookup semantics differently in
C++98/03 and C++0x, since the '0x semantics break valid C++98/03
code. This new mess is tracked by core issue 399, which is still
unresolved.

Fixes PR6358 and PR6359.

llvm-svn: 96836
2010-02-23 00:15:22 +00:00
Chris Lattner dd1cb5b2ec Add 'previous declaration is here' note for param redefinition
errors, e.g.:

t.c:1:21: error: redefinition of parameter 'x'
int test(int x, int x);
                    ^
t.c:1:14: note: previous declaration is here
int test(int x, int x);
             ^

llvm-svn: 96769
2010-02-22 00:40:25 +00:00
Douglas Gregor 90d554ecb3 Implement support for parsing pseudo-destructor expression with a nested-name-specifier, e.g.,
typedef int Int;
  int *p;
  p->Int::~Int();

This weakens the invariant that the only types in nested-name-specifiers are tag types (restricted to class types in C++98/03). However, we weaken this invariant as little as possible, accepting arbitrary types in nested-name-specifiers only when we're in a member access expression that looks like a pseudo-destructor expression.

llvm-svn: 96743
2010-02-21 18:36:56 +00:00
Chandler Carruth 8f2548112e Commiting a revert from dgregor of a bit of destructor logic until we can
figure out how not to break lots of code using this. See PR6358 and PR6359 for
motivating examples. FIXME's left in the code and the test.

llvm-svn: 96733
2010-02-21 10:19:54 +00:00
Fariborz Jahanian ffcfecdc1f Fixed a crash specific to blocks in c++ uncovered by an internal
test suite.

llvm-svn: 96608
2010-02-18 20:31:02 +00:00
Douglas Gregor 12ea0f4ef9 For -Wswitch-enum warnings, be sure to look through typedefs of enum
types. Fixes <rdar://problem/7643909>.

llvm-svn: 96531
2010-02-17 23:29:11 +00:00
Douglas Gregor b154fdc974 Introduce a new kind of failed result for isLvalue/isModifiableLvalue
which describes temporary objects of class type in C++. Use this to
provide a more-specific, remappable diagnostic when takin the address
of such a temporary.

llvm-svn: 96396
2010-02-16 21:39:57 +00:00
Douglas Gregor 71ad477ab3 Do not try to instantiate invalid declarations. It's a recipe for
disaster. Fixes PR6161.

llvm-svn: 96371
2010-02-16 19:28:15 +00:00
Douglas Gregor fe17d2550b Improve parsing and instantiation of destructor names, so that we can
now cope with the destruction of types named as dependent templates,
e.g.,

  y->template Y<T>::~Y()

Nominally, we implement C++0x [basic.lookup.qual]p6. However, we don't
follow the letter of the standard here because that would fail to
parse

  template<typename T, typename U>
  X0<T, U>::~X0() { }

properly. The problem is captured in core issue 339, which gives some
(but not enough!) guidance. I expect to revisit this code when the
resolution of 339 is clear, and/or we start capturing better source
information for DeclarationNames.

Fixes PR6152.

llvm-svn: 96367
2010-02-16 19:09:40 +00:00
John McCall d8d0d43fa3 Support local namespace aliases and permit them to be instantiated.
llvm-svn: 96335
2010-02-16 06:53:13 +00:00
Chandler Carruth 284bb2ec72 Defer covariance checks for dependent types. Add test cases that also ensure
they are re-checked on instantiation.

llvm-svn: 96217
2010-02-15 11:53:20 +00:00
Douglas Gregor f40863caff Work around an annoying, non-standard optimization in the glibc
headers, where malloc (and many other libc functions) are declared
with empty throw specifications, e.g.,  

  extern void *malloc (__SIZE_TYPE__ __size) throw () __attribute__
  ((__malloc__)) ;

The C++ standard doesn't seem to allow this, and redeclaring malloc as
the standard permits (as follows) resulted in Clang (rightfully!)
complaining about mis-matched exception specifications.

  void *malloc(size_t size);

We work around this by silently propagating an empty throw
specification "throw()" from a function with C linkage declared in a
system header to a redeclaration that has no throw specifier.

Ick.

llvm-svn: 95969
2010-02-12 07:32:17 +00:00
Douglas Gregor 87b4b4184c Improve a test slightly
llvm-svn: 95967
2010-02-12 06:08:51 +00:00
Douglas Gregor d3a5918742 In C++, allow builtins to be referred to via qualified name lookup, e.g.,
::__builtin_va_copy

Fixes one of the Firefox issues in PR5511.

llvm-svn: 95966
2010-02-12 05:48:04 +00:00
Douglas Gregor 50dc219e8b When we have a dependent direct initializer but not a dependent
variable type, we can (and should) still check for completeness of the
variable's type. Do so, to work around an assertion that shows up in
Boost's shared_ptr.

llvm-svn: 95934
2010-02-11 22:55:30 +00:00
John McCall 5b0829a321 Improve access control diagnostics. Perform access control on member-pointer
conversions.  Fix an access-control bug where privileges were not considered
at intermediate points along the inheritance path.  Prepare for friends.

llvm-svn: 95775
2010-02-10 09:31:12 +00:00
Douglas Gregor e6565625f4 Migrate the mish-mash of declaration checks in
Sema::ActOnUninitializedDecl over to InitializationSequence (with
default initialization), eliminating redundancy. More importantly, we
now check that a const definition in C++ has an initilizer, which was
an #if 0'd code for many, many months. A few other tweaks were needed
to get everything working again:

  - Fix all of the places in the testsuite where we defined const
    objects without initializers (now that we diagnose this issue)
  - Teach instantiation of static data members to find the previous
    declaration, so that we build proper redeclaration
    chains. Previously, we had the redeclaration chain but built it
    too late to be useful, because...
  - Teach instantiation of static data member definitions not to try
    to check an initializer if a previous declaration already had an
    initializer. This makes sure that we don't complain about static
    const data members with in-class initializers and out-of-line
    definitions.
  - Move all of the incomplete-type checking logic out of
    Sema::FinalizeDeclaratorGroup; it makes more sense in
    ActOnUnitializedDecl.

There may still be a few places where we can improve these
diagnostics. I'll address that as a separate commit.

llvm-svn: 95657
2010-02-09 07:26:29 +00:00
Douglas Gregor 1f53e803cd Fix PR number in test case
llvm-svn: 95640
2010-02-09 01:02:53 +00:00
Douglas Gregor 34c0a90265 Be more careful when checking initializer lists that involve reference
types; we don't want to give an expression reference type. Fixes PR6177.

llvm-svn: 95635
2010-02-09 00:50:06 +00:00
John McCall 69f9dbc3e4 Fix the crash-on-invalid from PR6259.
llvm-svn: 95554
2010-02-08 19:26:07 +00:00
Chandler Carruth 75cc359fdc Ensure that a operator delete overload is rocognized regardless of cv-quals.
llvm-svn: 95553
2010-02-08 18:54:05 +00:00
Douglas Gregor 0e027fb32b Workaround for friend template instantiation crash in PR5848, from Keir Mierle!
llvm-svn: 95517
2010-02-07 10:31:35 +00:00
Anders Carlsson 96c15b1816 Don't diagnose missing noreturns for uninstantiated templates. Fixes PR6247.
llvm-svn: 95487
2010-02-06 05:31:15 +00:00
Anders Carlsson 0da714a3e2 Implement a warning diagnostic for weak vtables. Fixes PR6116.
llvm-svn: 95472
2010-02-06 02:27:10 +00:00
John McCall 52cc0897f3 Per discussion, remove the explicit restriction on static const data members with
out-of-line initializers as integer constant expressions.  Fixes PR6206.

llvm-svn: 95463
2010-02-06 01:07:37 +00:00
Douglas Gregor 1aa3edbb99 A function declarator with a non-identifier name in an anonymous class
is a constructor for that class, right? Fixes PR6238. 

llvm-svn: 95367
2010-02-05 06:12:42 +00:00
Chandler Carruth 935384217d Teach the allocation function overload handling to deal with templates, and
prevent a crash on templates when looking for an existing declaration of the
predefined global operators. This fixes PR5918.

Added an easy test case for the overload handling, but testing the crash is
a bit trickier. Created a new test that can use multiple runs with a define to
trigger which test case is used so we can test this type of issue.

llvm-svn: 95220
2010-02-03 11:02:14 +00:00
Douglas Gregor b92a1565c3 Implement the lvalue-to-rvalue conversion where needed. The
lvalue-to-rvalue conversion adjusts lvalues of qualified, non-class
type to rvalue expressions of the unqualified variant of that
type. For example, given:

  const int i;
  (void)(i + 17);

the lvalue-to-rvalue conversion for the subexpression "i" will turn it
from an lvalue expression (a DeclRefExpr) with type 'const int' into
an rvalue expression with type 'int'. Both C and C++ mandate this
conversion, and somehow we've slid through without implementing it. 

We now have both DefaultFunctionArrayConversion and
DefaultFunctionArrayLvalueConversion, and which gets used depends on
whether we do the lvalue-to-rvalue conversion or not. Generally, we do
the lvalue-to-rvalue conversion, but there are a few notable
exceptions:
  - the left-hand side of a '.' operator
  - the left-hand side of an assignment
  - a C++ throw expression
  - a subscript expression that's subscripting a vector

Making this change exposed two issues with blocks:
  - we were deducing const-qualified return types of non-class type
  from a block return, which doesn't fit well
  - we weren't always setting the known return type of a block when it
  was provided with the ^return-type syntax

Fixes the current Clang-on-Clang compile failure and PR6076.

llvm-svn: 95167
2010-02-03 00:27:59 +00:00
Anders Carlsson 8abde4b447 Diagnose binding a non-const reference to a vector element.
llvm-svn: 94963
2010-01-31 17:18:49 +00:00
Chandler Carruth cd6d426075 Fix my dyslexia.
llvm-svn: 94958
2010-01-31 11:52:52 +00:00
Chandler Carruth 764cf41d92 Add a test case for a fixed PR just to ensure we don't regress.
llvm-svn: 94957
2010-01-31 11:51:51 +00:00
Douglas Gregor 7ae2d7758f Rework base and member initialization in constructors, with several
(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
2010-01-31 09:12:51 +00:00
Douglas Gregor 3edc4d5ec3 Fix a major oversight in the comparison of standard conversion
sequences, where we would occasionally determine (incorrectly) that
one standard conversion sequence was a proper subset of another when,
in fact, they contained completely incomparable conversions. 

This change records the types in each step within a standard
conversion sequence, so that we can check the specific comparison
types to determine when one sequence is a proper subset of the
other. Fixes this testcase (thanks, Anders!), which was distilled from
PR6095 (also thanks to Anders).

llvm-svn: 94660
2010-01-27 03:51:04 +00:00
Sebastian Redl 497c0a418d Fix two redefinitions in test cases that weren't diagnosed yet, but will be soon.
llvm-svn: 94565
2010-01-26 18:52:33 +00:00
John McCall 8fe6808de0 Handle redeclarations found by ADL deterministically and reasonably.
This solution relies on an O(n) scan of redeclarations, which means it might
scale poorly in crazy cases with tons of redeclarations brought in by a ton
of distinct associated namespaces.  I believe that avoiding this
is not worth the common-case cost.

llvm-svn: 94530
2010-01-26 07:16:45 +00:00
John McCall 91f61fc921 Allow ADL to find functions imported by using decls. Leave wordy comment
about interaction between ADL and default arguments.  Shrug shoulders, commit.

llvm-svn: 94524
2010-01-26 06:04:06 +00:00
Anders Carlsson 6515d877c0 Fix a pretty bad bug where if a constructor (or conversion function) was marked as 'explicit', but then defined out-of-line, we would not treat it as being explicit.
llvm-svn: 94366
2010-01-24 17:15:04 +00:00
Anders Carlsson 0bd52403d4 Use new initialization code when dealing with [dcl.init.aggr]p12. This fixes the bug where array elements and member initializers weren't copied correctly.
llvm-svn: 94340
2010-01-24 00:19:41 +00:00
Anders Carlsson 73eb7cd351 Use the new init code for member subobjects.
llvm-svn: 94329
2010-01-23 20:20:40 +00:00
Anders Carlsson 0cf999b663 Switch some array initialization over to the new init code.
llvm-svn: 94327
2010-01-23 20:13:41 +00:00
Anders Carlsson d0849254de Baby steps towards migrating the InitListChecker over to the new initialization code. Pass an InitializedEntity pointer through to most init checker functions. Right now, it's ignored everywhere except when initializing vectors in C++.
llvm-svn: 94325
2010-01-23 19:55:29 +00:00
John McCall 6d174646dd Produce a special diagnostic when users call a function with an argument of
incomplete type (or a pointer/reference to such).

The causes of this problem are different enough to justify a different "design"
for the diagnostic.  Most notably, it doesn't give an operand index:
it's usually pretty obvious which operand is the problem, it adds a lot of
clutter to mention it, and the fix is usually in a different part of the file
anyway.

This is yet another diagnostic that should really have an analogue in the
non-overloaded case --- which should be much easier to write because of
the weaker space constraints.

llvm-svn: 94303
2010-01-23 08:10:49 +00:00
Anders Carlsson 8e01dcf6f6 Fix the EntityKind order so that all entity kinds that can be copied (using 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
2010-01-23 05:47:27 +00:00
John McCall 553c0796ee Implement elementary access control.
llvm-svn: 94268
2010-01-23 00:46:32 +00:00
Fariborz Jahanian 53967e2abd Patch fixes a lookup bug in c++'s anonymous union member
lookup. Fixes radar 7562438.

llvm-svn: 94191
2010-01-22 18:30:17 +00:00
Anders Carlsson 7caa4cb87a No need to canonicalize the type and use dyn_cast. Also, correctly diagnose trying to override a function returning an lvalue reference with a function overriding an rvalue reference.
llvm-svn: 94183
2010-01-22 17:37:20 +00:00
Chandler Carruth df7fd5f8d5 Fix an obvious goof that caused us to only see the top level of return types
when checking for covariance. Added some fun test cases, fixes PR6110.

This felt obvious enough to just commit. ;] Let me know if anything needs
tweaking.

llvm-svn: 94173
2010-01-22 13:07:41 +00:00
Mike Stump 60dbeebee8 Improve unreachable code warnings with respect to dead member and
dead array references.

llvm-svn: 94115
2010-01-21 23:15:53 +00:00
Mike Stump fcd6f94ba7 Improve unreachable code warnings for with respect to dead functional casts in C++.
llvm-svn: 94106
2010-01-21 22:12:18 +00:00
Mike Stump c18c403670 Improve unreachable code warnings for with respect to ? :.
llvm-svn: 94093
2010-01-21 19:44:04 +00:00
Mike Stump cc3a853df7 Improve unreachable code warnings with respect to dead binary and
unary operators.

llvm-svn: 94084
2010-01-21 17:21:23 +00:00
Mike Stump 04c6851cd6 Speed up compilation by avoiding generating exceptional edges from
CallExprs as those edges help cause a n^2 explosion in the number of
destructor calls.  Other consumers, such as static analysis, that
would like to have more a more complete CFG can select the inclusion
of those edges as CFG build time.

This also fixes up the two compilation users of CFGs to be tolerant of
having or not having those edges.  All catch code is assumed be to
live if we didn't generate the exceptional edges for CallExprs.

llvm-svn: 94074
2010-01-21 15:20:48 +00:00
Douglas Gregor 5204248f96 When looking up enumerator names for redeclaration, use the
ForRedeclaration flag so that we don't look into base classes. 
Fixes PR6061.

llvm-svn: 93862
2010-01-19 06:06:57 +00:00
Douglas Gregor 27aa77ac08 Improve the test for unused-expression warnings slightly
llvm-svn: 93644
2010-01-16 18:17:21 +00:00
John McCall 4700099719 Improve overload diagnostics some more by calling out qualifier mismatches
for special diagnostics.  Unfortunately, the non-overload diagnostics are not
this good.

llvm-svn: 93420
2010-01-14 03:28:57 +00:00
John McCall a1709fd822 Improve the diagnostic for bad conversions in overload resolution to talk
about 'object argument' vs. 'nth argument'.

llvm-svn: 93395
2010-01-14 00:56:20 +00:00
John McCall e8c8cd2a58 Don't report ambiguities in the user-defined conversion if we weren't supposed
to be considering user-defined conversions in the first place.

Doug, please review;  I'm not sure what we should be doing if we see a real
ambiguity in selecting a copy constructor when otherwise suppressing
user-defined conversions.

Fixes PR6014.

llvm-svn: 93365
2010-01-13 22:30:33 +00:00
John McCall 6a61b5203d Record some basic information about bad conversion sequences. Use that
information to feed diagnostics instead of regenerating it.  Much room for
improvement here, but fixes some unfortunate problems reporting on method calls.

llvm-svn: 93316
2010-01-13 09:16:55 +00:00
Alexis Hunt c88db06565 Implement semantic checking for C++ literal operators.
This now rejects literal operators that don't meet the requirements.
Templates are not yet checked for.

llvm-svn: 93315
2010-01-13 09:01:02 +00:00
Mike Stump 1bacb81d6f Add an unreachable code checker.
llvm-svn: 93287
2010-01-13 02:59:54 +00:00
John McCall e1ac8d1742 Improve the reporting of non-viable overload candidates by noting the reason
why the candidate is non-viable.  There's a lot we can do to improve this, but
it's a good start.  Further improvements should probably be integrated with the
bad-initialization reporting routines.

llvm-svn: 93277
2010-01-13 00:25:19 +00:00
John McCall 53262c96d9 Reorganize some of the code to note overload candidates. Improves the
fidelity with which we note them as functions/constructors and templates
thereof.  Also will be helpful when reporting bad conversions (next).

llvm-svn: 93224
2010-01-12 02:15:36 +00:00
John McCall c54cf7373f Chris thinks these diagnostics are better now. :)
llvm-svn: 93216
2010-01-12 01:09:12 +00:00
John McCall 0d1da2298a Introduce a specific representation for the ambiguous implicit conversion
sequence.  Lots of small relevant changes.  Fixes some serious problems with
ambiguous conversions;  also possibly improves associated diagnostics.

llvm-svn: 93214
2010-01-12 00:44:57 +00:00
Douglas Gregor 7419ce72ae Add test case from PR5763
llvm-svn: 93190
2010-01-11 21:58:49 +00:00
Douglas Gregor 2159182078 When computing surrogates for calls to a value of object type, look
for all visible conversion functions.

llvm-svn: 93173
2010-01-11 19:36:35 +00:00
Sebastian Redl 9a8dd0db89 Make Clang complain about taking the address of an unqualified member function. Fixes PR5985.
llvm-svn: 93150
2010-01-11 15:56:56 +00:00
John McCall af07fbe210 Organize testcase into namespaces.
llvm-svn: 93015
2010-01-08 18:40:32 +00:00
John McCall 12f97bc48a Change the printing of OR_Deleted overload results to print all the candidates,
not just the viable ones.  This is reasonable because the most common use of
deleted functions is to exclude some implicit conversion during calls;  users
therefore will want to figure out why some other options were excluded.

Started sorting overload results.  Right now it just sorts by location in the
translation unit (after putting viable functions first), but we can do better than
that.

Changed bool OnlyViable parameter to PrintOverloadCandidates to an enum for better
self-documentation.

llvm-svn: 92990
2010-01-08 04:41:39 +00:00
Douglas Gregor fa1e36d0de Improve the fix-its for -Wparentheses to ensure that the fix-it
suggestions follow recovery. Additionally, add a note to these
diagnostics which suggests a fix-it for changing the behavior to what
the user probably meant. Examples:

t.cpp:2:9: warning: & has lower precedence than ==; == will be evaluated first
      [-Wparentheses]
  if (i & j == k) {
        ^~~~~~~~
          (     )
t.cpp:2:9: note: place parentheses around the & expression to evaluate it first
  if (i & j == k) {
        ^
      (    )

t.cpp:14:9: warning: using the result of an assignment as a condition
without
      parentheses [-Wparentheses]
  if (i = f()) {
      ~~^~~~~
      (      )
t.cpp:14:9: note: use '==' to turn this assignment into an equality
comparison
  if (i = f()) {
        ^
        ==

llvm-svn: 92975
2010-01-08 00:20:23 +00:00
John McCall 0237485287 Improve the lead diagnostic for C++ object subscript expressions with
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
2010-01-07 02:04:15 +00:00
Douglas Gregor dfdda291e0 Add testcase for PR5817, although the bug was already fixed
llvm-svn: 92858
2010-01-06 22:06:13 +00:00
Douglas Gregor 859f0ae041 Make sure that the key-function computation produces the correct
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
2010-01-06 17:00:51 +00:00
John McCall fd0b2f8fe4 Improve the diagnostics used to report implicitly-generated class members
as parts of overload sets.  Also, refer to constructors as 'constructors'
rather than functions.

Adjust a lot of tests.

llvm-svn: 92832
2010-01-06 09:43:14 +00:00
Douglas Gregor 0a0f04dcb9 Make our marking of virtual members functions in a class be
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
2010-01-06 04:44:19 +00:00
Anders Carlsson e60365b7b5 Make sure that an overriding return type is complete before checking if it's covariant. Fixes PR5920.
llvm-svn: 92365
2009-12-31 18:34:24 +00:00
Chris Lattner b0283c06b2 improve diagnostics for case when a field type is unknown by
not emitting a follow-on error about 'int', which the user
never wrote.  PR5924.

llvm-svn: 92339
2009-12-31 03:10:55 +00:00
Chris Lattner c3847ba3fa fix PR5917, L'x' was getting the wrong type in c++ mode. Per
C++2.13.2p2: "A wide-character literal has type wchar_t"

llvm-svn: 92313
2009-12-30 21:19:39 +00:00
John McCall 91f1a02648 Typedefs can be redeclared. That seems like something we should record in
the AST lest we run into some crazy canonicalization bug like PR5874.

llvm-svn: 92283
2009-12-30 00:31:22 +00:00
Chandler Carruth 585fb1e97e Fix support for const_cast<>s of array types which actual change the
CV-qualifiers. Remove an error expectation from the 'good' set of const-cast
test cases. With this patch, the final non-template test case from PR5542
passes. (It's the same as the one already in const-cast.cpp.)

llvm-svn: 92257
2009-12-29 08:05:19 +00:00
Chandler Carruth 607f38e05f Correctly refer to element CVR qualifications when determining if a type is
more or less cv-qualified than another during implicit conversion and overload
resolution ([basic.type.qualifier] p5). Factors the logic out of template
deduction and into the ASTContext so it can be shared.

This fixes several aspects of PR5542, but not all of them.

llvm-svn: 92248
2009-12-29 07:16:59 +00:00
Chandler Carruth c25c6ee3db Handle using declarations in overloaded and template functions during ADL and
address resolution. This fixes PR5751.

Also, while we're here, remove logic from ADL which mistakenly included the
definition namespaces of overloaded and/or templated functions whose name or
address is used as an argument.

llvm-svn: 92245
2009-12-29 06:17:27 +00:00
Nuno Lopes c095b5361a support the warn_unused_result in C++ class methods
llvm-svn: 92095
2009-12-24 00:28:18 +00:00
Nuno Lopes 0e7860f21e allow the noreturn attribute to be used in class methods
llvm-svn: 92090
2009-12-23 23:40:33 +00:00
Douglas Gregor 721fb2b6e4 Diagnose the use of incomplete types in C++ typeid expressions
llvm-svn: 92045
2009-12-23 21:06:06 +00:00
John McCall b50c443df2 Test case for PR5134.
llvm-svn: 91965
2009-12-23 01:09:14 +00:00
John McCall db3062cd4e Test case from PR5476.
llvm-svn: 91957
2009-12-23 00:44:38 +00:00
John McCall 0a4bb26ed0 Set a member's access specifier even if it doesn't match the previous specifier.
Prevents an assert on successive redeclarations.

Fixed PR5573.

llvm-svn: 91956
2009-12-23 00:37:40 +00:00
Douglas Gregor 684d7bdc43 Allow the first parameter of operator new to be a cv-qualified
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
2009-12-22 23:42:49 +00:00
Douglas Gregor b6ea60872d Switch Sema::AddCXXDirectInitializerToDecl over to InitializationSequence
llvm-svn: 91927
2009-12-22 22:17:25 +00:00
Douglas Gregor 96596c98fb Switch initialization of parameters in a call over to
InitializationSequence (when a FunctionDecl is present). This required
a few small fixes to initialization sequences:

  - Make sure to use the adjusted parameter type for initialization of
  function parameters.
  - Implement transparent union calling semantics in C

llvm-svn: 91902
2009-12-22 07:24:36 +00:00
Eli Friedman 5f101b95c6 Switch default arguments over to InitializationSequence.
llvm-svn: 91883
2009-12-22 02:46:13 +00:00
Eli Friedman 463e523ad8 Switch file-scope assignment initialization over to InitializationSequence.
llvm-svn: 91881
2009-12-22 02:10:53 +00:00
Douglas Gregor 8364e6b568 When a template-id refers to a single function template, and the
explicitly-specified template arguments are enough to determine the
instantiation, and either template argument deduction fails or is not
performed in that context, we can resolve the template-id down to a
function template specialization (so sayeth C++0x
[temp.arg.explicit]p3). Fixes PR5811.

llvm-svn: 91852
2009-12-21 23:17:24 +00:00
Douglas Gregor 39c778b443 Switch default-initialization of variables of class type (or array thereof) over to InitializationSequence. I could swear that this fixes a PR somewhere, but I couldn't figure out which one
llvm-svn: 91796
2009-12-20 22:01:25 +00:00
John McCall 1f4ee7bd2f Just push a new scope when parsing an out-of-line variable definition.
Magically fixes all the terrible lookup problems associated with not pushing
a new scope.  Resolves an ancient xfail and an LLVM misparse.

llvm-svn: 91769
2009-12-19 09:28:58 +00:00
Eli Friedman 7827520ce8 Initialization improvements: addition of string initialization and a few
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
2009-12-19 08:11:05 +00:00
Douglas Gregor a4b592a7d5 Switch more of Sema::CheckInitializerTypes over to
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
2009-12-19 03:01:41 +00:00
John McCall ea305edd63 Pull Sema::isAcceptableLookupResult into SemaLookup. Extract the criteria into
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
2009-12-18 10:40:03 +00:00
Douglas Gregor e1314a64b8 Switch the initialization required by return statements over to the
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
2009-12-18 05:02:21 +00:00
John McCall 90d3bb943e Patch over yet more problems with friend declarations which were provoking
problems on LLVM-Code-Syntax.  This proved remarkably easy to "fix" once
I settled on how I was going to approach it.

llvm-svn: 91633
2009-12-17 23:21:11 +00:00
Eli Friedman 8d0da8042b Fix test.
llvm-svn: 91566
2009-12-16 20:47:15 +00:00
Eli Friedman 6a8dc922b3 Make sure C-specific enum warning doesn't trigger in C++.
llvm-svn: 91563
2009-12-16 20:30:08 +00:00
Eli Friedman 5dd02a0f65 Correctly calcluate abstract-ness in the case where an implicitly declared
method overrides a pure virtual method.

llvm-svn: 91558
2009-12-16 20:00:27 +00:00
Douglas Gregor 4f4b186215 When value-initializing a class with no user-defined constructors but
with a non-trivial default constructor, zero-initialize the storage
and then call the default constructor. Fixes PR5800.

llvm-svn: 91548
2009-12-16 18:50:27 +00:00
Douglas Gregor 59ae3c8542 In Sema::CheckInitializerTypes, replace a use of CheckReferenceInit with an InitializationSequence
llvm-svn: 91542
2009-12-16 16:54:16 +00:00
John McCall d681c3959f Introduce a centralized routine in Sema for diagnosing failed lookups (when
used as expressions).  In dependent contexts, try to recover by doing a lookup
in previously-dependent base classes.  We get better diagnostics out, but    
unfortunately the recovery fails:  we need to turn it into a method call  
expression, not a bare call expression.  Thus this is still a WIP.

llvm-svn: 91525
2009-12-16 08:11:27 +00:00
Douglas Gregor 85dabae6ad Switch the C++ new expression over to InitializationSequence, rather
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
2009-12-16 01:38:02 +00:00
Daniel Dunbar 5618e98f33 Update tests to use %clang instead of 'clang', and forcibly disable use of '
clang ' or ' clang -cc1 ' or ' clang-cc ' in test lines (by substituting them to
garbage).

llvm-svn: 91460
2009-12-15 22:01:24 +00:00
Daniel Dunbar 8fbe78f6fc Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.
- 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
2009-12-15 20:14:24 +00:00
Douglas Gregor 202eb8fcfd Don't assume that all conversions to a void pointer are converting
from a PointerType. Fixes PR5756.

llvm-svn: 91253
2009-12-13 21:29:20 +00:00
Anders Carlsson 7e0b207e54 More improvements to checking allocation and deallocation functions.
llvm-svn: 91244
2009-12-13 17:53:43 +00:00
Douglas Gregor fab31f47b2 When certain diagnostics involving run-time behavior would be emitted
in a potentially potentially evaluated context, queue those
diagnostics and only emit them if the context ends up being
potentially evaluated. This completes the fix for PR5761.

llvm-svn: 91213
2009-12-12 07:57:52 +00:00
Douglas Gregor 7ca84af48e Suppress warnings and errors about certain uses of non-POD types (in
__builtin_offsetof, passing through an ellipsis) when we're in an
unevaluated context. This is the first part of the fix to PR5761,
which deals with the simple case of an unevaluated context.

llvm-svn: 91210
2009-12-12 07:25:49 +00:00
John McCall 2b058ef245 Don't enter a new scope for a namespace-qualified declarator unless we're
in a file context.  In well-formed code, only happens with friend functions.
Fixes PR 5760.

llvm-svn: 91146
2009-12-11 20:04:54 +00:00
Chris Lattner 56caf31afb Give the "cannot pass object of non-POD type 'class C' through variadic constructor; call will abort at runtime" warning a -W flag (non-pod-varargs) and default it being an error by default. There is no good reason to allow users to get bitten by this sort of thing by default.
llvm-svn: 91094
2009-12-11 01:52:50 +00:00
Douglas Gregor 5b747a169e Implement C++ DR437, which involves exception-specifications that name
a type currently being defined, from Nicola Gigante!

llvm-svn: 91052
2009-12-10 18:13:52 +00:00
Eli Friedman e919e382a4 Fix for PR5515: allow "merging" array bounds both forwards and backwards.
llvm-svn: 91044
2009-12-10 08:54:47 +00:00
Douglas Gregor 3e1e527826 Reimplement reference initialization (C++ [dcl.init.ref]) using the
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
2009-12-09 23:02:17 +00:00
John McCall 5677499fbf First pass at implementing C++ enum semantics: calculate (and store) an
"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
2009-12-09 09:09:27 +00:00
Anders Carlsson c50b340108 Look through using declarations when searching for allocation overloads.
llvm-svn: 90961
2009-12-09 07:39:44 +00:00
Anders Carlsson f9812782b7 In CXXRecordDecl::forallBases, add the base to the "queue", so we walk more than one heirarchy of classes. John, please review.
llvm-svn: 90948
2009-12-09 04:26:02 +00:00
Anders Carlsson a038825b1c Don't warn about function templates or function template specializations.
llvm-svn: 90943
2009-12-09 03:44:46 +00:00
Anders Carlsson 31c7e88667 Move the missing prototypes checking out into a new function. Don't warn about inline functions. Add a test.
llvm-svn: 90938
2009-12-09 03:30:09 +00:00
Anders Carlsson efa4732747 Pass the current SourceLocation to getAssignOperatorMethod, fixing a crash when the assign operator method needs to be instantiated. Doug, please review the updated default-assignment-operator.cpp change.
llvm-svn: 90935
2009-12-09 03:01:51 +00:00
Douglas Gregor 40cb9ad391 Implemented an implicit conversion from "noreturn" function types (and
pointers thereof) to their corresponding non-noreturn function
types. This conversion is considered an exact match for
overload-resolution purposes. Note that we are a little more strict
that GCC is, because we encode noreturn in the type system, but that's
a Good Thing (TM) because it does not allow us to pretend that
potentially-returning function pointers are non-returning function
pointers.

Fxies PR5620.

llvm-svn: 90913
2009-12-09 00:47:37 +00:00
Douglas Gregor a64c1e5452 When performing unqualified name lookup in C++, don't look directly
into transparent contexts; instead, we'll look into their nearest
enclosing non-transparent contexts further up the stack. Fixes PR5479.

llvm-svn: 90859
2009-12-08 15:38:36 +00:00
John McCall 3969e30d38 Correctly implement the C++03 and 0x restrictions on class-member using
declarations.

llvm-svn: 90843
2009-12-08 07:46:18 +00:00
Anders Carlsson 82fccd014a Rework how virtual member functions are marked. If a class has no key function, we now wait until the end of the translation unit to mark its virtual member functions as references. This lays the groundwork for fixing PR5557.
llvm-svn: 90752
2009-12-07 08:24:59 +00:00
Chris Lattner 1c4280328d reapply my patch for PR4451, which improves diagnostics for :: vs : confusion.
This time with a fix to bail out when in a dependent context.

llvm-svn: 90730
2009-12-07 01:36:53 +00:00
Chris Lattner ed085234dc revert my previous patch, it is breaking something and I don't have time
to fix it ATM.

llvm-svn: 90717
2009-12-06 20:58:07 +00:00
Chris Lattner 2b6651e908 this is really about both PR's, 4452 is "don't crash", 4451 is "recover nicely".
llvm-svn: 90714
2009-12-06 19:11:41 +00:00
Chris Lattner 71d5bf1c5d implement PR4451, improving error recovery for a mistaken : where a :: was
intended.  On the first testcase in the bug, we now produce:

cxx-decl.cpp:12:2: error: unexpected ':' in nested name specifier
y:a a2;
 ^
 ::

instead of:

t.cc:8:1: error: C++ requires a type specifier for all declarations
x:a a2;
^
t.cc:8:2: error: invalid token after top level declarator
x:a a2;
 ^
 ;
t.cc:9:11: error: use of undeclared identifier 'a2'
x::a a3 = a2;
          ^

llvm-svn: 90713
2009-12-06 19:08:11 +00:00
John McCall b96ec56871 Fix "using typename" and the instantiation of non-dependent using declarations.
llvm-svn: 90614
2009-12-04 22:46:56 +00:00
Anders Carlsson 1f78b2bf62 Diagnose declarations of implicit member functions.
llvm-svn: 90605
2009-12-04 22:33:25 +00:00
Eli Friedman 78cde14444 Make sure to call PerformObjectMemberConversion where necessary.
llvm-svn: 90555
2009-12-04 07:18:51 +00:00
Eli Friedman 5efba264cb Fix for PR5679: make __builtin_prefetch a bit more flexible in what it accepts
as a constant integer.  Also, some minor cleanup and improvements to the
diagnostics.

llvm-svn: 90504
2009-12-04 00:30:06 +00:00
John McCall 9f545181f7 When recovering from an invalid forward reference to an enum type in C++,
create the enum type in the same scope as you would a record type.

llvm-svn: 90500
2009-12-04 00:07:04 +00:00
Eli Friedman 1d6fb1669c Add recursion guards to ice-checking and evaluation for declrefs, so we
don't infinitely recurse for cases we can't evaluate.

llvm-svn: 90480
2009-12-03 20:31:57 +00:00
Douglas Gregor c99f155365 Unify the end-of-class code paths used by the parser and template
instantiation, to ensure that we mark class template specilizations as
abstract when we need to and perform checking of abstract classes.

Also, move the checking that determines whether we are creating a
variable of abstract class type *after* we check whether the type is
complete. Otherwise, we won't see when we have an abstract class
template specialization that is implicitly instantiated by this
declaration. This is the "something else" that Sebastian had noted
earlier.

llvm-svn: 90467
2009-12-03 18:33:45 +00:00
Anders Carlsson ae3c5cf76a When instantiating a class, if a base specifier is not dependent we still need to copy its attributes down to the instantiated class.
llvm-svn: 90463
2009-12-03 17:49:57 +00:00
Sebastian Redl 79eba1ca3b Introduce the notion of literal types, as specified in C++0x.
llvm-svn: 90361
2009-12-03 00:13:20 +00:00
John McCall 1a49e9dc87 Recognize that EnumConstantDecls can be found by lookup and are not instance
members.  Fixes PR5667.

llvm-svn: 90341
2009-12-02 19:59:55 +00:00
Anders Carlsson f98849eb8a In Sema, whenever we think that a function is going to cause a vtable to be generated, we mark any virtual implicit member functions as referenced.
llvm-svn: 90327
2009-12-02 17:15:43 +00:00
John McCall a6d407c296 Fix IsProvablyNotDerivedFrom to always use record definitions when available.
Gets clang-on-clang passing again.

llvm-svn: 90270
2009-12-01 22:28:41 +00:00
Douglas Gregor 6be3de3fa7 Funtion templates and function template specializations do not
override virtual functions. Also, eliminate a (now redundant) call to
AddOverriddenMethods.

llvm-svn: 90242
2009-12-01 17:35:23 +00:00
Douglas Gregor 21920e3758 Move the checking of overridden virtual functions into the code path
common to both parsing and template instantiation, so that we'll find
overridden virtuals for member functions of class templates when they
are instantiated. 

Additionally, factor out the checking for pure virtual functions, so
that it will be executed both at parsing time and at template
instantiation time. 

These changes fix PR5656 (for real), although one more tweak
w.r.t. member function templates will be coming along shortly.

llvm-svn: 90241
2009-12-01 17:24:26 +00:00
Douglas Gregor e7488b904c Don't automatically assume that an id-expression refers to a
ValueDecl, because that isn't always the case in ill-formed
code. Diagnose a common mistake (forgetting to provide a template
argument list for a class template, PR5655) and dyn_cast so that we
handle the general problem of referring to a non-value declaration
gracefully.

llvm-svn: 90239
2009-12-01 16:58:18 +00:00
Douglas Gregor f107aa63ee An inherited virtual (where "virtual" wasn't written explicitly) can
be defined as pure. Fixes PR5656.

llvm-svn: 90237
2009-12-01 16:18:00 +00:00
John McCall 10eae1851d Eliminate the use of OverloadedFunctionDecl in member expressions.
Create a new UnresolvedMemberExpr for these lookups.  Assorted hackery
around qualified member expressions;  this will all go away when we
implement the correct (i.e. extremely delayed) implicit-member semantics.

llvm-svn: 90161
2009-11-30 22:42:35 +00:00
Anders Carlsson 26a807d37a When we're trying to define an implicit virtual destructor, make sure that we have a valid delete operator.
llvm-svn: 90156
2009-11-30 21:24:50 +00:00
Daniel Dunbar 7427fe28dc Remove unnecessary -fms-extensions=0 from tests (this command line syntax is going away).
llvm-svn: 90066
2009-11-29 09:31:53 +00:00
Douglas Gregor f73b282bf0 Implement the rules in C++ [basic.link] and C99 6.2.2 for computing
the linkage of a declaration. Switch the lame (and completely wrong)
NamedDecl::hasLinkage() over to using the new NamedDecl::getLinkage(),
along with the "can this declaration be a template argument?" check
that started all of this.

Fixes -fsyntax-only for PR5597.

llvm-svn: 89891
2009-11-25 22:24:25 +00:00
Alexis Hunt 54a0254887 Parse C++ member check attributes - base_check, hiding, and override.
The attributes are currently ignored.

llvm-svn: 89837
2009-11-25 04:20:27 +00:00
Douglas Gregor 7bab5ff8e7 Eliminate CXXConditionDeclExpr with extreme prejudice.
All statements that involve conditions can now hold on to a separate
condition declaration (a VarDecl), and will use a DeclRefExpr
referring to that VarDecl for the condition expression. ForStmts now
have such a VarDecl (I'd missed those in previous commits).

Also, since this change reworks the Action interface for
if/while/switch/for, use FullExprArg for the full expressions in those
expressions, to ensure that we're emitting

Note that we are (still) not generating the right cleanups for
condition variables in for statements. That will be a follow-on
commit.

llvm-svn: 89817
2009-11-25 00:27:52 +00:00
Sebastian Redl d6f7850117 Have the parser tell sema whether a member declaration is a function definition. This allows sema to not emit spurious diagnostics in some invalid code.
llvm-svn: 89816
2009-11-24 23:38:44 +00:00
Anders Carlsson 0b11a3ef71 GNUNullExpr is a valid sentinel even though it isn't of pointer type.
llvm-svn: 89778
2009-11-24 17:24:21 +00:00
Sebastian Redl 03b67ea1a2 Make sure redeclaration chains are properly linked, even through invalid decls. This fixes PR5415.
llvm-svn: 89777
2009-11-24 17:14:34 +00:00
Sebastian Redl 22e2e5c423 Intercept sizeof and alignof references before they get into ASTContext methods. This fixes a crash when writing sizeof(Incomplete&), and lets ASTContext's methods do the right thing for CodeGen, which fixes PR5590.
llvm-svn: 89668
2009-11-23 17:18:46 +00:00
Sebastian Redl a6602e9e2a Let using directives refer to namespace aliases. Fixes PR5479.
llvm-svn: 89657
2009-11-23 15:34:23 +00:00
Douglas Gregor 378e1923b6 Require a class type to be complete before probing its conversion
functions for a switch condition's conversion to integral or
enumeration type. 

llvm-svn: 89656
2009-11-23 13:53:21 +00:00
Douglas Gregor d0c22e0d10 Implement conversion from a switch condition with class type to an
integral or enumeration type (vi user-defined conversions). Fixes PR5518.

llvm-svn: 89655
2009-11-23 13:46:08 +00:00
Anders Carlsson ba958400a2 When laying out bitfields, make sure that the data size is always aligned to a byte. This fixes PR5580.
llvm-svn: 89611
2009-11-22 19:13:51 +00:00
Alexis Hunt 12048d868b Use intptr_t rather than long so that this test will not fail on LLP64 systems,
where long is only 32-bits and so a reinterpret_cast would be ill-formed.

llvm-svn: 89583
2009-11-22 07:05:50 +00:00
John McCall a9ee325d71 If a C++ qualified id is followed by a postfix suffix, it is never the direct
operand of an addressof operator, and so we should not treat it as an abstract
member-pointer expression and therefore suppress the implicit member access.

This is really a well-formedness constraint on expressions:  a DeclRefExpr of
a FieldDecl or a non-static CXXMethodDecl (or template thereof, or unresolved
collection thereof) should not be allowed in an arbitrary location in the AST.
Arguably it shouldn't be allowed anywhere and we should have a different expr
node type for this.  But unfortunately we don't have a good way of enforcing
this kind of constraint right now.

llvm-svn: 89578
2009-11-22 02:49:43 +00:00
Alexis Hunt 96d5c76498 Added rudimentary C++0x attribute support.
The following attributes are currently supported in C++0x attribute
lists (and in GNU ones as well):
 - align() - semantics believed to be conformant to n3000, except for
   redeclarations and what entities it may apply to
 - final - semantics believed to be conformant to CWG issue 817's proposed
   wording, except for redeclarations
 - noreturn - semantics believed to be conformant to n3000, except for
   redeclarations
 - carries_dependency - currently ignored (this is an optimization hint)

llvm-svn: 89543
2009-11-21 08:43:09 +00:00
Douglas Gregor 2094c5e80f A previous commit fixed PR5519; here's the test case.
llvm-svn: 89494
2009-11-20 22:05:53 +00:00
Douglas Gregor a25d65d1b6 Implement C++ [basic.lookup.classref]p3, which states how the type
name 'T' is looked up in the expression

  t.~T()

Previously, we weren't looking into the type of "t", and therefore
would fail when T actually referred to an injected-class-name. Fixes
PR5530.

llvm-svn: 89493
2009-11-20 22:03:38 +00:00
Sebastian Redl 6a96bf7d6e Do overload resolution for compound assignment even if only the RHS is 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
2009-11-18 23:10:33 +00:00
John McCall 1f6339e1fb Resolve this FIXME: unelaborated lookups are ambiguous, too.
llvm-svn: 89266
2009-11-18 23:05:13 +00:00
John McCall 1f82f2462d Overhaul previous-declaration and overload checking to work on lookup results
rather than NamedDecl*.  This is a major step towards eliminating
OverloadedFunctionDecl.

llvm-svn: 89263
2009-11-18 22:49:29 +00:00
Fariborz Jahanian fff3fb2b35 ignore parens surounding the type when diagnosing
pointer-to-member cast types used in expressions.

llvm-svn: 89255
2009-11-18 22:16:17 +00:00
Fariborz Jahanian 1bc0f9affc This patch fixes a bug in misdiagnosing correct
use of pointer to data member.

llvm-svn: 89251
2009-11-18 21:54:48 +00:00
Sebastian Redl d5b2453722 Track overriding methods when instantiating a template class. Fixes PR5550.
llvm-svn: 89248
2009-11-18 21:51:29 +00:00
Sebastian Redl 4990a6347a Don't generate superfluous and ambiguous built-in candidates for multi-level array subscript and arithmetic. Fixes PR5546.
llvm-svn: 89242
2009-11-18 20:39:26 +00:00
Fariborz Jahanian 76197416ac Improve on diagnosing type mismatches because of
lack of viable convesion functions.

llvm-svn: 89216
2009-11-18 18:26:29 +00:00
Sebastian Redl 55db1ec3ec CastsAwayConstness shouldn't care if member pointers point into different classes. Fixes PR5545.
llvm-svn: 89215
2009-11-18 18:10:53 +00:00
John McCall e61f2ba7e4 Incremental progress on using declarations. Split UnresolvedUsingDecl into
two classes, one for typenames and one for values;  this seems to have some
support from Doug if not necessarily from the extremely-vague-on-this-point
standard.  Track the location of the 'typename' keyword in a using-typename
decl.  Make a new lookup result for unresolved values and deal with it in
most places.

llvm-svn: 89184
2009-11-18 02:36:19 +00:00
Eli Friedman 132e70bfa4 PR5520: Make sure to check whether the base type is complete before looking for
operator->.

llvm-svn: 89180
2009-11-18 01:28:03 +00:00
Sebastian Redl 6eedcc1b86 Adjust format attribute index for implicit object arguments. Fixes PR5521.
llvm-svn: 89113
2009-11-17 18:02:24 +00:00
Anders Carlsson 6aa503900f Fix PR5531.
llvm-svn: 89106
2009-11-17 17:11:23 +00:00
Sebastian Redl 658262fd26 Repair broken FindCompositePointerType. Correct early termination condition. Get CVR qualifiers from canonical types. Traverse collected qualifiers in reverse order on rebuilding the pointer, so that we don't swap inner and outer qualifiers. That last one fixes PR5509.
llvm-svn: 88960
2009-11-16 21:03:45 +00:00
Eli Friedman 794d4d8127 Fix test on Linux.
llvm-svn: 88889
2009-11-16 05:14:40 +00:00
Anders Carlsson 2c9e274e57 If we find a deallocation function in the class scope, but it is a placement function we should not look for a deallocation function in the global scope.
llvm-svn: 88851
2009-11-15 16:43:15 +00:00
Douglas Gregor 8f3952cda9 When performing a static downcast as part of a static_cast, make sure
that we're dealing with canonical types like the documentation say
(yay, CanQualType). Alas, this is another instance where using
getQualifiers() on a non-canonical QualType got us in trouble.

Good news: with this fix, Clang can now parse all of its own headers!

llvm-svn: 88848
2009-11-15 09:20:52 +00:00
Douglas Gregor 598caeee37 Don't gratuitously mark the default constructors of base or member initializers as used
llvm-svn: 88847
2009-11-15 08:51:10 +00:00
Douglas Gregor 54fdb417fe When adding the underlying declaration of a decl to a lookup-results
set, expand overloaded function declarations. Long-term, this should
actually be done by the name-lookup code rather than here, but this
part of the code (involving using declarations) is getting a makeover
now and the test-case is useful.

llvm-svn: 88846
2009-11-15 08:11:13 +00:00
Douglas Gregor c473cbb3b2 When looking for operator() to type-check a call to an object of class
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
2009-11-15 07:48:03 +00:00
Anders Carlsson 6d41727a95 Add an internal CreateRecordDecl that will create a CXXRecordDecl when compiling C++ and a RecordDecl otherwise.
llvm-svn: 88816
2009-11-14 21:45:58 +00:00
Anders Carlsson 461a2c0640 Always build a builtin operator expression for the __extension__ unary operator.
llvm-svn: 88811
2009-11-14 21:26:41 +00:00
Sebastian Redl 7c353685bc - Have TryStaticImplicitCast set the cast kind to NoOp when binding a reference. CheckReferenceInit already inserts implicit casts to the necessary types. This fixes an assertion in CodeGen for some casts and brings a fix for PR5453 close, if I understand that bug correctly.
- Also, perform calculated implicit cast sequences if they're determined to work. This finally diagnoses static_cast to ambiguous or implicit bases and fixes two long-standing fixmes in the test case. For the C-style cast, this requires propagating the access check suppression pretty deep into other functions.
- Pass the expressions for TryStaticCast and TryStaticImplicitCast by reference. This should lead to a better AST being emitted for such casts, and also fixes a memory leak, because CheckReferenceInit and PerformImplicitConversion wrap the node passed to them. These wrappers were previously lost.

llvm-svn: 88809
2009-11-14 21:15:49 +00:00
Eli Friedman a9ea959d04 PR5462: Don't run off the edge of the argument array for vararg handling
when there are more parameters in the prototype than arguments to the call.

llvm-svn: 88759
2009-11-14 04:43:10 +00:00
Douglas Gregor bf3f322034 When type-checking a static cast (or the static_cast part of a C-style
cast) that is converting to a class type, enumerate its constructors
as in any other direct initialization. This ensures that we get the
proper conversion sequence.

llvm-svn: 88751
2009-11-14 03:27:21 +00:00
Daniel Dunbar 9d5118a69c Fix broken tests, exposed by improved -verify.
llvm-svn: 88749
2009-11-14 03:24:04 +00:00
Anders Carlsson 654e5c7cf8 Diagnose ambiguity of operator delete and operator delete[]. Sebastian, please review.
llvm-svn: 88747
2009-11-14 03:17:38 +00:00
Douglas Gregor ff7028a55e Revert r88718, which does NOT solve the constructor-template-as-copy-constructor issue. Big thanks to John for finding this
llvm-svn: 88724
2009-11-13 23:59:09 +00:00
Douglas Gregor 5f235a21eb A constructor template cannot be instantiated to a copy
constructor. Make sure that such declarations can never be formed.

llvm-svn: 88718
2009-11-13 23:14:53 +00:00
Douglas Gregor 379d84b7ed When performing copy initialization (= "implicit conversion", here) to
a class type from itself or a derived class thereof, enumerate
constructors and permit user-defined conversions to the arguments of
those constructors. This fixes the wacky implicit conversion sequence
used in std::auto_ptr's lame emulation of move semantics.

llvm-svn: 88670
2009-11-13 18:44:21 +00:00
Fariborz Jahanian c3091c9118 Make test more platform independent (per Sebastian's comment).
llvm-svn: 86888
2009-11-11 22:45:41 +00:00
Fariborz Jahanian 4e088941ad Diagnose illegally typed operator new/new[].
llvm-svn: 86755
2009-11-10 23:47:18 +00:00
Fariborz Jahanian facfdd4d93 For array pointee type, get its cvr qualifier from
its element type. Fixes pr5432.

llvm-svn: 86587
2009-11-09 21:02:05 +00:00
Eli Friedman 9cf6b59400 Add additional note to mark the cause of synthesized constructors. Mark
declaration invalid if the constructor can't be properly built.  Addresses
remaining review comments from Fariborz for r86500.

llvm-svn: 86579
2009-11-09 19:20:36 +00:00
Eli Friedman d7686ef31c Unify the codepaths used to verify base and member initializers for explicitly
and implicitly defined constructors.  This has a number of benefits:

1. Less code.

2. Explicit and implicit constructors get the same diagnostics.

3. The AST explicitly contains constructor calls from implicit default
constructors.  This allows handing some cases that previously weren't handled
correctly in IRGen without any additional code. Specifically, implicit default
constructors containing calls to constructors with default arguments are now
handled correctly.

llvm-svn: 86500
2009-11-09 01:05:47 +00:00
Sebastian Redl afb8be743d When checking the namespace of a redeclaration or definition, look through linkage specs. Fixes PR5430.
llvm-svn: 86461
2009-11-08 11:36:54 +00:00
Daniel Dunbar 8b57697954 Eliminate &&s in tests.
- 'for i in $(find . -type f); do sed -e 's#\(RUN:.*[^ ]\) *&& *$#\1#g' $i | FileUpdate $i; done', for the curious.

llvm-svn: 86430
2009-11-08 01:45:36 +00:00
Anders Carlsson d3569efb5a Add bug number.
llvm-svn: 86357
2009-11-07 08:24:59 +00:00
Anders Carlsson f5dc6fa252 Don't treat variables with non-trivial ctors or dtors as unused. Fixes PR5407.
llvm-svn: 86352
2009-11-07 07:26:56 +00:00
John McCall 99ce6bfe28 Improve the -Wsign-compare heuristics:
* If the unsigned type is smaller than the signed type, never warn, because
    its value will not change when zero-extended to the larger type.
  * If we're testing for (in)equality, and the unsigned value is an integer
    constant whose sign bit is not set, never warn, because even though the
    signed value might change, it can't affect the result of the equality.

Also make the comparison test cases much more rigorous, and have them expose
the subtle differences between C and C++ here.

llvm-svn: 86242
2009-11-06 08:49:08 +00:00
Douglas Gregor d82ae38d53 Rework the fix-it hint for code like
get_origin->x

where get_origin is actually a function and the user has forgotten the
parentheses. Instead of giving a lame note for the fix-it, give a
full-fledge error, early, then build the call expression to try to
recover. 

llvm-svn: 86238
2009-11-06 06:30:47 +00:00
Douglas Gregor f4f2ff773b Improve recovery when we fail to parse the operand of a C++ named cast. Fixes PR5210
llvm-svn: 86234
2009-11-06 05:48:00 +00:00
Douglas Gregor 6af6c3ee56 Turn off -Wsign-compare warnings by default
llvm-svn: 86233
2009-11-06 05:24:12 +00:00
Douglas Gregor ad8b22269e If we have a C-style cast, functional cast, or a static_cast to a
class type, don't perform the array-to-pointer or function-to-pointer
conversions, because we may end up binding a reference to a function
or array.

With this change, FileCheck now passes -fsyntax-only!

llvm-svn: 86211
2009-11-06 01:14:41 +00:00
Douglas Gregor 02ba0ea461 When we encounter a derived-to-base conversion when performing an
implicit conversion sequence, check the validity of this conversion
and then perform it.

llvm-svn: 86210
2009-11-06 01:02:41 +00:00
Sebastian Redl 1060067dd1 Don't allow definitions of array variables without some size information in C++. Fixed PR5401
llvm-svn: 86165
2009-11-05 19:47:47 +00:00
Douglas Gregor 13a2c03801 Eliminate some false positives due to a thinko in the "'blah' is
always zero in this context" warning logic. Also, make the diagnostic
itself more precise when referring to pointer values ("NULL" vs. "zero").

llvm-svn: 86143
2009-11-05 17:49:26 +00:00
Sebastian Redl 65ae200a13 When collecting types for built-in candidates, make arrays decay to pointers. Otherwise, subscripting an array leads to no candidates at all. Fixes PR5360.
llvm-svn: 86140
2009-11-05 16:36:20 +00:00
John McCall 1fa36b7cab Implement the conditional-operator part of -Wsign-compare. Turn
DiagnoseSignCompare into Sema::CheckSignCompare and call it from more places.

Add some enumerator tests.  These seem to expose some oddities in the
types we're converting C++ enumerators to;  in particular, they're converting
to unsigned before int, which seems to contradict 4.5 [conv.prom] p2.

Note to self: stop baiting Doug in my commit messages.

llvm-svn: 86128
2009-11-05 09:23:39 +00:00
Mike Stump 5ff76e2fa2 Fix 80-col violation.
llvm-svn: 86115
2009-11-05 03:47:55 +00:00
Douglas Gregor 01df946664 Make sure to grab CVR qualifiers from the canonical type. ARGH!
llvm-svn: 86079
2009-11-05 00:07:36 +00:00
John McCall e22a04aba9 Diagnose using a field to initialize itself. Patch by Brandon Pearcy!
llvm-svn: 86061
2009-11-04 23:02:40 +00:00
Douglas Gregor 71395fa1d5 Implement support for parsing dependent template-ids that refer to
overloaded operators, e.g.,

  p->template operator+<T>()

llvm-svn: 85989
2009-11-04 00:56:37 +00:00
Fariborz Jahanian 7ad3616659 Remove previous patch for pr5296 due to further clarification
of value-initialization and trivial constructors.

llvm-svn: 85935
2009-11-03 20:38:53 +00:00
Douglas Gregor 30d60cb36e Replace the code that parses member access expressions after "." or
"->" with a use of ParseUnqualifiedId. Collapse
ActOnMemberReferenceExpr, ActOnDestructorReferenceExpr (both of them),
ActOnOverloadedOperatorReferenceExpr,
ActOnConversionOperatorReferenceExpr, and
ActOnMemberTemplateIdReferenceExpr into a single, new action
ActOnMemberAccessExpr that does the same thing more cleanly (and can
keep more source-location information).

llvm-svn: 85930
2009-11-03 19:44:04 +00:00
Douglas Gregor 7861a80346 Introduce a new class, UnqualifiedId, that provides a parsed
representation of a C++ unqualified-id, along with a single parsing
function (Parser::ParseUnqualifiedId) that will parse all of the
various forms of unqualified-id in C++.

Replace the representation of the declarator name in Declarator with
the new UnqualifiedId class, simplifying declarator-id parsing
considerably and providing more source-location information to
Sema. In the future, I hope to migrate all of the other
unqualified-id-parsing code over to this single representation, then
begin to merge actions that are currently only different because we
didn't have a unqualified notion of the name in the parser.

llvm-svn: 85851
2009-11-03 01:35:08 +00:00
Fariborz Jahanian 42f666342c Diagnose use of data pointer member in a function call
expression instead of crashing.

llvm-svn: 85401
2009-10-28 16:49:46 +00:00
Fariborz Jahanian 115654873d Generate constructor for value-initialization cases, even if the
implementation technique doesn't call the constructor at that point.
DR302. Fixes pr5296.

llvm-svn: 85249
2009-10-27 16:51:19 +00:00
John Thompson 995c845e5c Disabling some MS extensions which cause this test to fail
llvm-svn: 85242
2009-10-27 14:58:27 +00:00
John Thompson ec87bb5c46 Disabling some MS extensions which cause these tests to fail
llvm-svn: 85236
2009-10-27 14:31:53 +00:00
Sebastian Redl d7b3d7dd79 Remove the Skip parameter from GetTypeForDeclarator and dependents. Take the opportunity to improve an error message and fix PR4498.
llvm-svn: 85068
2009-10-25 21:45:37 +00:00
Sebastian Redl c057f423a0 Apply the special enum restrictions from [over.match.oper]p3b2 in argument-dependent lookup too. This fixes PR5244.
llvm-svn: 84963
2009-10-23 19:23:15 +00:00
John McCall fc93cf9777 When building types from declarators, instead of building two types (one for
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
2009-10-22 22:37:11 +00:00
Sebastian Redl 802f14ccde Try to instantiate templates before doing hierarchy checks in static_cast. Fixes PR5261.
llvm-svn: 84860
2009-10-22 15:07:22 +00:00
Douglas Gregor b8440a76c4 Don't generate pointer types for void or base classes when finding
conversion types for builtin overloaded operator candidates; I misread
this section in the standard the first time around.

llvm-svn: 84788
2009-10-21 22:01:30 +00:00
Douglas Gregor 74ba25ca5a Improve diagnostics and template instantiation behavior when calling
an overloaded function call operator.

llvm-svn: 84745
2009-10-21 06:18:39 +00:00
Fariborz Jahanian 9a587b0111 Patch implements ranking conversions between member pointers [over.ics.rank]
llvm-svn: 84660
2009-10-20 20:04:46 +00:00
Anders Carlsson 7001794302 It's OK for a pure virtual function to override another pure virtual function. Fixes PR5222.
llvm-svn: 84428
2009-10-18 19:34:08 +00:00
Douglas Gregor 0b3d95ae64 Fix a crash with qualified member access into a non-type, from Sean Hunt!
llvm-svn: 84370
2009-10-17 22:37:54 +00:00
Edward O'Callaghan 93135aad29 Fix for PR5190, Credit to Zhanyong Wan.
llvm-svn: 84346
2009-10-17 19:32:54 +00:00
Sebastian Redl 5371aed18c Add a DR437 testcase, but disable it for now, since it fails.
llvm-svn: 84345
2009-10-17 18:31:05 +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
Anders Carlsson 35a99d95b3 The result type of logical || and && is bool in C++. Fixes PR5206.
llvm-svn: 84231
2009-10-16 01:44:21 +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
Anders Carlsson 63dce02544 Check the return type when calling pointer to member functions.
llvm-svn: 84161
2009-10-15 00:41:48 +00:00
Sebastian Redl 7eb5d377d7 Use partial diagnostics properly in call to RequireCompleteType. Among other things, this means we get a note on the declaration of the incomplete type when it is used in an exception specification.
llvm-svn: 84099
2009-10-14 14:59:48 +00:00
Sebastian Redl 075b21d4dc Do exception spec compatibility tests for member pointers, too.
llvm-svn: 84098
2009-10-14 14:38:54 +00:00
Fariborz Jahanian 31481d8b22 Handle ambiguity of reference initialization.
Removes a FIXME.

llvm-svn: 84068
2009-10-14 00:52:43 +00:00
Douglas Gregor 15e5602e59 Improve diagnostics when the parser encounters a declarator with an
unknown type name, e.g.,

  foo::bar x;

when "bar" does not refer to a type in "foo". 

With this change, the parser now calls into the action to perform
diagnostics and can try to recover by substituting in an appropriate
type. For example, this allows us to easily diagnose some missing
"typename" specifiers, which we now do:

  test/SemaCXX/unknown-type-name.cpp:29:1: error: missing 'typename'
        prior to dependent type name 'A<T>::type'
  A<T>::type A<T>::f() { return type(); }
  ^~~~~~~~~~
  typename 

Fixes PR3990.

llvm-svn: 84053
2009-10-13 23:27:22 +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 834facc2b0 Check the return type of operator[]() and fix a thinko that lead to a crash in SemaCXX/overloaded-operator.cpp.
llvm-svn: 84041
2009-10-13 22:22:09 +00:00