Commit Graph

582 Commits

Author SHA1 Message Date
Fariborz Jahanian 3554b5a37c Patch to build list of inherited virtual base classes
in their order of construction for each class and use it 
to to check on propery order of base class construction 
under -Wreorder option.

llvm-svn: 75270
2009-07-10 20:13:23 +00:00
Anders Carlsson cf1441ab20 Fix another decltype crash.
llvm-svn: 75175
2009-07-09 22:00:53 +00:00
Fariborz Jahanian 341583c3ac Sema check on out of order object initialization of
class object's base and members under -Wreorder flag.

llvm-svn: 75168
2009-07-09 19:59:47 +00:00
Anders Carlsson 17973e684d Use getDeclName in DefineImplicitOverloadedAssign as well.
llvm-svn: 75152
2009-07-09 17:47:25 +00:00
Anders Carlsson 52b9180587 Pass the DeclName to the diagnostic builder so that member names will be quoted correctly.
llvm-svn: 75150
2009-07-09 17:37:12 +00:00
Douglas Gregor 197e5f7bb7 Improve argument-dependent lookup to find associated classes and
namespaces based on the template arguments of a class template
specialization type.

llvm-svn: 74993
2009-07-08 07:51:57 +00:00
Sebastian Redl 86be854fa8 Implement checking of exception spec compatibility for overriding virtual functions.
llvm-svn: 74943
2009-07-07 20:29:57 +00:00
Anders Carlsson 1f9648da17 Some (most) type trait expressions require that the argument passed in is a complete type.
llvm-svn: 74937
2009-07-07 19:06:02 +00:00
Douglas Gregor dce892e128 Parsing fix for out-of-line constructors, from Piotr Rak
llvm-svn: 74833
2009-07-06 16:40:48 +00:00
Eli Friedman c131d3b5a2 Fix for PR4502: add calculation of the integer conversion rank for
wchar_t.

llvm-svn: 74808
2009-07-05 23:44:27 +00:00
Sebastian Redl 4f4d7b5d8e Catch function redeclarations with incompatible exception specifications.
llvm-svn: 74787
2009-07-04 11:39:00 +00:00
Fariborz Jahanian 302bb6661f Patch to support optional nested-name-specifier in in ctor-initializer
list.

llvm-svn: 74571
2009-06-30 23:26:25 +00:00
Fariborz Jahanian cae5482f6c Diagnose multiple initialization of anonymous union
fields in the ctor-initializer list.

llvm-svn: 74554
2009-06-30 21:52:59 +00:00
Fariborz Jahanian 7baa71e2dd More diagnostics related to initialization of direct bases
in ctor-initializer list.

llvm-svn: 74541
2009-06-30 17:34:52 +00:00
Anders Carlsson 124f34c150 Make an error message more clear.
llvm-svn: 74481
2009-06-30 00:06:57 +00:00
Fariborz Jahanian 651185bf47 A more detailed diagnosis of ill-formed ctor-initializer
list.

llvm-svn: 74480
2009-06-30 00:02:17 +00:00
Anders Carlsson 074a18a8fd Improvements to decltype. We now don't crash anymore when the expr is an overloaded function decl.
llvm-svn: 74472
2009-06-29 22:58:55 +00:00
Fariborz Jahanian 2be8bf44cd Diagnose multiple initialzation of data-member/base
in the ctor-initializer list. More to come.

llvm-svn: 74465
2009-06-29 22:33:26 +00:00
Anders Carlsson 74d7f0dd65 Make it possible for using decls to point to operators. Fixes PR4441.
llvm-svn: 74362
2009-06-27 00:27:47 +00:00
Anders Carlsson 082acded44 Implement enough of the 'auto' keyword so we can claim to support N2546.
llvm-svn: 74307
2009-06-26 18:41:36 +00:00
Chris Lattner d86a13e02e Improve error recovery in C++: when we hit 'implicit int' cases in C++,
these are usually because the parser was thoroughly confused.  In addition
to typing the value being declared as an int and hoping for the best, we
mark the value as invalid so we don't get chains of errors when it is
used downstream.  In C, implicit int actually is valid, so typing the thing
as int is good and marking it invalid is bad. :)

llvm-svn: 74266
2009-06-26 04:45:06 +00:00
Chris Lattner 5558e9fc55 fix PR4452, a crash on invalid. The error recovery is still terrible in this case
but at least we don't crash :)

llvm-svn: 74264
2009-06-26 04:27:47 +00:00
Anders Carlsson 5f212cbb73 Fix another assert related to using decls.
llvm-svn: 74262
2009-06-26 03:54:13 +00:00
Anders Carlsson 8d0f6b7c87 When creating LookupResults, see through UsingDecls. Fixes PR4450.
llvm-svn: 74258
2009-06-26 03:37:05 +00:00
Anders Carlsson 5140b3c4a6 Fix PR4448.
llvm-svn: 74257
2009-06-26 03:02:18 +00:00
Fariborz Jahanian a158e018d4 Test case for my last patch.
llvm-svn: 74216
2009-06-25 22:40:36 +00:00
Douglas Gregor ad3f2fcf43 Improved semantic analysis and AST respresentation for function
templates.

For example, this now type-checks (but does not instantiate the body
of deref<int>):

  template<typename T> T& deref(T* t) { return *t; }

  void test(int *ip) {
    int &ir = deref(ip);
  }

Specific changes/additions:
  * Template argument deduction from a call to a function template.
  * Instantiation of a function template specializations (just the
  declarations) from the template arguments deduced from a call.
  * FunctionTemplateDecls are stored directly in declaration contexts
  and found via name lookup (all forms), rather than finding the
  FunctionDecl and then realizing it is a template. This is
  responsible for most of the churn, since some of the core
  declaration matching and lookup code assumes that all functions are
  FunctionDecls.

llvm-svn: 74213
2009-06-25 22:08:12 +00:00
Anders Carlsson 7d209570b6 Decltype needs to have a dependent type if the expr passed to it is type dependent. Fixes PR4444.
llvm-svn: 74175
2009-06-25 15:00:34 +00:00
Douglas Gregor 6127ca4561 Make sure that argument-dependent lookup looks into the global scope
when it should.

llvm-svn: 73992
2009-06-23 20:14:09 +00:00
Fariborz Jahanian 246219bc9f Fixed text of a diagnostics.
llvm-svn: 73885
2009-06-22 16:33:37 +00:00
Fariborz Jahanian 1c9d5d956c Made improvements in c++'s object model patch on Doug's review.
llvm-svn: 73833
2009-06-20 20:23:38 +00:00
Douglas Gregor fec52635f0 Parsing and AST support for using declarations, from John Thompson!
llvm-svn: 73812
2009-06-20 00:51:54 +00:00
Fariborz Jahanian 423a81f259 Patch for implementation of C++'s object model. This is
work in progress.

llvm-svn: 73782
2009-06-19 19:55:27 +00:00
Anders Carlsson 84613c4eba It's an error to use a function declared in a class definition as a default argument before the function has been declared.
llvm-svn: 73234
2009-06-12 16:51:40 +00:00
Eli Friedman 88681cce60 Move test to be with the other typename tests.
llvm-svn: 73178
2009-06-11 01:01:02 +00:00
Eli Friedman 6d692cc2e8 PR4364: fix parsing 'typename' in an expression.
llvm-svn: 73177
2009-06-11 00:33:41 +00:00
Douglas Gregor 0bdc1f5eef Handle member pointer types with dependent class types (e.g., int
T::*) and implement template instantiation for member pointer types.

llvm-svn: 73151
2009-06-09 22:17:39 +00:00
Argyrios Kyrtzidis b1d51aa18a Use "()" instead of "(void)" when pretty-printing a parameter-less function type for C++.
llvm-svn: 72747
2009-06-03 02:06:50 +00:00
Anders Carlsson 2418712039 Fix an off by one error when trying to perform copy initialization of operator new and operator delete arguments. Sebastian, please review.
llvm-svn: 72670
2009-05-31 19:49:47 +00:00
Sebastian Redl fb3f1794e1 Disallow exception specs on typedefs.
llvm-svn: 72664
2009-05-31 11:47:27 +00:00
Anders Carlsson 36b75a4619 Replace a cast with a dyn_cast as suggested by Doug.
llvm-svn: 72624
2009-05-30 17:26:39 +00:00
Anders Carlsson 65d5820892 Add a member lookup criteria constructor for searching for overridden virtual member functions. Use this instead of regular name lookup when checking for overriding functions so we will see declarations that would otherwise be hidden. Fixes 6902298.
llvm-svn: 72601
2009-05-30 00:52:53 +00:00
Douglas Gregor 7de5966d76 Create a new PrintingPolicy class, which we pass down through the AST
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
2009-05-29 20:38:28 +00:00
Sebastian Redl d643456d45 Reject incomplete types in exception specs.
llvm-svn: 72580
2009-05-29 18:02:33 +00:00
Sebastian Redl 10b9de45c3 Disallow exception specifications on multi-level indirections.
llvm-svn: 72571
2009-05-29 15:01:05 +00:00
Douglas Gregor d6ab8744dc When we parse a tag specifier, keep track of whether that tag
specifier resulted in the creation of a new TagDecl node, which
happens either when the tag specifier was a definition or when the tag
specifier was the first declaration of that tag type. This information
has several uses, the first of which is implemented in this commit:

  1) In C++, one is not allowed to define tag types within a type
  specifier (e.g., static_cast<struct S { int x; } *>(0) is
  ill-formed) or within the result or parameter types of a
  function. We now diagnose this.

  2) We can extend DeclGroups to contain information about any tags
  that are declared/defined within the declaration specifiers of a
  variable, e.g.,

    struct Point { int x, y, z; } p;

  This will help improve AST printing and template instantiation,
  among other things.

  3) For C99, we can keep track of whether a tag type is defined
  within the type of a parameter, to properly cope with cases like,
  e.g.,

    int bar(struct T2 { int x; } y) {
      struct T2 z;
    }

  We can also do similar things wherever there is a type specifier,
  e.g., to keep track of where the definition of S occurs in this
  legal C99 code:

    (struct S { int x, y; } *)0

  

llvm-svn: 72555
2009-05-28 23:31:59 +00:00
Sebastian Redl a81b0b7ef5 Add a big test case for I-C-Es in C++, and a fix to make it work. The fix might not be the right way to do it.
llvm-svn: 72490
2009-05-27 19:34:06 +00:00
Anders Carlsson 3b70b300b0 A block that returns a reference is an lvalue.
llvm-svn: 72409
2009-05-26 02:03:20 +00:00
Sebastian Redl 027de2adcd Avoid using the built-in type checker for assignment in C++ when classes are involved. Patch by Vyacheslav Kononenko.
llvm-svn: 72212
2009-05-21 11:50:50 +00:00
Douglas Gregor f907cbf634 Ban the use of __builtin_types_compatible_p in C++; g++ doesn't support it,
and it isn't clear exactly what it's supposed to mean. Thanks Eli!

llvm-svn: 72142
2009-05-19 22:28:02 +00:00
Anders Carlsson 32440a0f48 Use the Itanium ABI for member pointers. Add a missing 'break' statement and a test case
llvm-svn: 71972
2009-05-17 02:06:04 +00:00
Anders Carlsson 3c01271e93 Rewrite PureVirtualMethodCollector to use the overridden methods. Fixes <rdar://problem/6854087>
llvm-svn: 71970
2009-05-17 00:00:05 +00:00
Eli Friedman 15af3ee6a9 Make the RAII extension warning silencing for __extension__ a bit
narrower, so it doesn't catch expresions that aren't sub-expressions of
__extension__ operator.

llvm-svn: 71967
2009-05-16 23:40:44 +00:00
Anders Carlsson 7bf3c4227d Fix another case where the extern-ness of extern "C" wasn't being captured.
This makes me think that we should make hasExternalStorage perform this check...

llvm-svn: 71962
2009-05-16 22:05:23 +00:00
Anders Carlsson 5b53576fe4 Don't return member pointer types for static member functions. Fixes 6879261.
llvm-svn: 71961
2009-05-16 21:43:42 +00:00
Anders Carlsson 0a7c01ff2b Check that the function being overridden is virtual.
llvm-svn: 71802
2009-05-14 22:15:41 +00:00
Anders Carlsson 0224c67400 Fix the same speling error in the test case (Duh).
llvm-svn: 71793
2009-05-14 21:20:16 +00:00
Anders Carlsson 8fb0b8a2cb Better diagnostics for covariance when checking overriding return types.
llvm-svn: 71786
2009-05-14 19:52:19 +00:00
Sebastian Redl 4d226cf45f When there are any member new operators, global versions aren't looked up at all.
llvm-svn: 71780
2009-05-14 18:11:41 +00:00
Douglas Gregor d9034f0b89 In C++, warn when something previously declared as a "struct" is later
declared as a "class", or vice-versa. This warning is under the
control of -Wmismatched-tags, which is off by default.

llvm-svn: 71773
2009-05-14 16:41:31 +00:00
Anders Carlsson f2a2e338ff Add return type checking for overriding virtual functions. We currently don't check covariance but that's next.
llvm-svn: 71759
2009-05-14 01:09:04 +00:00
Douglas Gregor 2ec748cd5a Implement explicit instantiations of member classes of class templates, e.g.,
template<typename T>
  struct X {
    struct Inner;
  };

  template struct X<int>::Inner;

This change is larger than it looks because it also fixes some
a problem with nested-name-specifiers and tags. We weren't requiring
the DeclContext associated with the scope specifier of a tag to be
complete. Therefore, when looking for something like "struct
X<int>::Inner", we weren't instantiating X<int>. 

This, naturally, uncovered a problem with member pointers, where we
were requiring the left-hand side of a member pointer access
expression (e.g., x->*) to be a complete type. However, this is wrong:
the semantics of this expression does not require a complete type (EDG
agrees).

Stuart vouched for me. Blame him.

llvm-svn: 71756
2009-05-14 00:28:11 +00:00
Anders Carlsson 5879fbd933 Disable access control by default. It can be enabled with the -faccess-control option. When we have better support for it, we can enable it by default again.
llvm-svn: 71706
2009-05-13 19:49:53 +00:00
Anders Carlsson 3881170898 Friend declarations are only valid inside class definitions.
llvm-svn: 71489
2009-05-11 22:55:49 +00:00
Sebastian Redl 576fd424df Implement C++0x nullptr.
llvm-svn: 71405
2009-05-10 18:38:11 +00:00
Douglas Gregor 1bbffbceae Big update to the C++ status table to reflect "recent"
development. Still much more to write!

llvm-svn: 71167
2009-05-07 17:50:16 +00:00
Daniel Dunbar 4dbaaa6f43 Improve handling of (X86) target features.
- This is a WIP...

 - This adds -march= handling to the driver, and fixes the defaulting
   of -mcpu on Darwin (which was using the wrong test).

Instead of handling -m{sse, ...} in the driver, pass them to clang-cc as
 -target-feature [+-]name

In clang-cc, communicate with the (clang) target to discover the legal
features of a target, and the features which are enabled based on
-mcpu. This is currently hardcoded just enough to not be a feature
regression, we need to get this information from the backend's
TableGen information somehow.

This is used to construct the full list of features which are being
used, which is in turn used to initialize the predefines.

llvm-svn: 71061
2009-05-06 03:16:41 +00:00
Douglas Gregor 5b07c7ec05 Implement support for comparing pointers with <, >, <=, >=, ==, and !=
in C++, taking into account conversions to the "composite pointer
type" so that we can compare, e.g., a pointer to a derived class to a
pointer to a base class. 

Also, upgrade the "comparing distinct pointer types" from a warning to
an error for C++, since this is clearly an error. Turns out that we
hadn't gone through and audited this code for C++, ever. 

Fixes <rdar://problem/6816420>.

llvm-svn: 70829
2009-05-04 06:07:12 +00:00
Eli Friedman 8469bc7c73 Fix/re-enable test.
llvm-svn: 70800
2009-05-03 21:22:18 +00:00
Daniel Dunbar 110c800cee Disable this test case, I'm tired of seeing red. :)
llvm-svn: 70799
2009-05-03 21:10:32 +00:00
Douglas Gregor f9aa5260a9 One can use "class" and "struct" interchangeably to refer to a class
in C++. Fixes <rdar://problem/6815995>.

llvm-svn: 70784
2009-05-03 17:18:57 +00:00
Anders Carlsson 38ebcaa8c8 Fix a thinko and a test.
llvm-svn: 70637
2009-05-02 18:36:10 +00:00
Anders Carlsson 8b98d02976 Downgrade the invalid offsetof error to a warning.
llvm-svn: 70634
2009-05-02 17:45:47 +00:00
Anders Carlsson 2bbb86b02e It's an error to call offsetof on a non-POD type.
llvm-svn: 70595
2009-05-01 23:20:30 +00:00
Anders Carlsson 5e965472b9 C++ destructors can have a single unnamed void parameter. Fixes <rdar://problem/6841210>.
llvm-svn: 70519
2009-04-30 23:18:11 +00:00
Anders Carlsson a088693557 Rework the way we handle constructor decls to be less hacky and fix PR3948 completely.
llvm-svn: 70516
2009-04-30 22:41:11 +00:00
Anders Carlsson 118b098cd9 Just because a declaration has the same name as its containing class doesn't mean that it's a constructor. Fixes rdar://problem/6815988.
llvm-svn: 70436
2009-04-29 23:19:39 +00:00
Eli Friedman ba94471e6e PR4103: improve source location information for members of the current
class.  This isn't perfect, but it's a big improvement over not having 
any location information.

llvm-svn: 70390
2009-04-29 17:56:47 +00:00
Eli Friedman debdc1d732 PR4103: Silence bogus unused expression warning.
llvm-svn: 70384
2009-04-29 16:35:53 +00:00
Eli Friedman 4058a842e6 Fix a minor edge case in C89 mode related to the definition of a
"function designator".

(This causes a minor glitch in the 
diagnostics for C++ member pointers, but we weren't printing the 
right diagnostic there anyway.)

llvm-svn: 70307
2009-04-28 17:59:09 +00:00
Eli Friedman 6bba2adc95 Emit keyword extension warning in all modes, not just C99 mode.
llvm-svn: 70283
2009-04-28 03:59:15 +00:00
Sebastian Redl 4c018663b2 Track down return statements in the handlers of a function-try-block of constructors. Meh ...
llvm-svn: 70256
2009-04-27 21:33:24 +00:00
Sebastian Redl 2f38ba57c8 Don't allow catch declarations to name an abstract class
llvm-svn: 70248
2009-04-27 21:03:30 +00:00
Sebastian Redl 4de47b445b Improve validation of C++ exception handling: diagnose throwing incomplete types and jumps into protected try-catch scopes.
llvm-svn: 70242
2009-04-27 20:27:31 +00:00
Sebastian Redl f79d397081 Make reference class unification in conditional expressions check for validity of the conversion.
llvm-svn: 70121
2009-04-26 11:21:02 +00:00
Chris Lattner b41df4f622 change a couple more c++ sema methods to be based on isinvalid bits.
llvm-svn: 70022
2009-04-25 08:35:12 +00:00
Chris Lattner 38378bf61f various "is invalid" cleanups for C++ ctors/dtors.
llvm-svn: 70021
2009-04-25 08:28:21 +00:00
Chris Lattner f6d1c9c7f0 This is a pretty big cleanup for how invalid decl/type are handle.
This gets rid of a bunch of random InvalidDecl bools in sema, changing
us to use the following approach:

1. When analyzing a declspec or declarator, if an error is found, we 
   set a bit in Declarator saying that it is invalid.
2. Once the Decl is created by sema, we immediately set the isInvalid
   bit on it from what is in the declarator.  From this point on, sema
   consistently looks at and sets the bit on the decl.

This gives a very clear separation of concerns and simplifies a bunch
of code.  In addition to this, this patch makes these changes:

1. it renames DeclSpec::getInvalidType() -> isInvalidType().
2. various "merge" functions no longer return bools: they just set the
   invalid bit on the dest decl if invalid.
3. The ActOnTypedefDeclarator/ActOnFunctionDeclarator/ActOnVariableDeclarator
   methods now set invalid on the decl returned instead of returning an
   invalid bit byref.
4. In SemaType, refering to a typedef that was invalid now propagates the
   bit into the resultant type.  Stuff declared with the invalid typedef
   will now be marked invalid.
5. Various methods like CheckVariableDeclaration now return void and set the
   invalid bit on the decl they check.


There are a few minor changes to tests with this, but the only major bad
result is test/SemaCXX/constructor-recovery.cpp.  I'll take a look at this
next.

llvm-svn: 70020
2009-04-25 08:06:05 +00:00
Sebastian Redl 8ce189f9ce Conditional operator C++ checking complete. What issues remain are in more general code.
llvm-svn: 69555
2009-04-19 21:53:20 +00:00
Sebastian Redl 0753c6f591 Bring member pointer operands of the conditional operator to a common type. We're getting there ...
llvm-svn: 69548
2009-04-19 21:15:26 +00:00
Sebastian Redl 3b7ef5e374 Another piece of the conditional operator puzzle. We'll want to use FindCompositePointerType in some other places, too.
llvm-svn: 69534
2009-04-19 19:26:31 +00:00
Sebastian Redl 5775af1afd Implement lvalue test for conditional expressions.
Add a few commented lines to the test case that point out things that don't work yet.

llvm-svn: 69354
2009-04-17 16:30:52 +00:00
Anders Carlsson 6dc3575220 Add support for the __has_trivial_destructor type trait.
llvm-svn: 69345
2009-04-17 02:34:54 +00:00
Sebastian Redl 1a99f441e6 Fix a crash bug when comparing overload quality of conversion operators with conversion constructors.
Remove an atrocious amount of trailing whitespace in the overloaded operator mangler. Sorry, couldn't help myself.
Change the DeclType parameter of Sema::CheckReferenceInit to be passed by value instead of reference. It wasn't changed anywhere.
Let the parser handle C++'s irregular grammar around assignment-expression and conditional-expression.
And finally, the reason for all this stuff: implement C++ semantics for the conditional operator. The implementation is complete except for determining lvalueness.

llvm-svn: 69299
2009-04-16 17:51:27 +00:00
Anders Carlsson fe63dc52f9 Add support for the __has_trivial_constructor type trait.
llvm-svn: 69245
2009-04-16 00:08:20 +00:00
Chris Lattner b4a8fe8dcc Make the implicit-int handling error recovery stuff handle C++
nested name specifiers.  Now we emit stuff like:

t.cpp:8:13: error: unknown type name 'X'
static foo::X  P;
       ~~~~ ^

instead of:

t.cpp:8:16: error: invalid token after top level declarator
static foo::X  P;
               ^

This is inspired by a really awful error message I got from 
g++ when I misspelt diag::kind as diag::Kind.

llvm-svn: 69086
2009-04-14 22:17:06 +00:00
Douglas Gregor 712a351c42 Make the selection of type declarations in Sema::getTypeName
deterministic when faced with an ambiguity. This eliminates the
annoying test/SemaCXX/using-directive.cpp failure.

llvm-svn: 68952
2009-04-13 15:14:38 +00:00
Chris Lattner 869c6610c7 Fix some C++ error recovery problems in init declarator parsing
that I noticed working on other things.

Instead of emitting:

t2.cc:1:8: error: use of undeclared identifier 'g'
int x(*g);
       ^
t2.cc:1:10: error: expected ')'
int x(*g);
         ^
t2.cc:1:6: note: to match this '('
int x(*g);
     ^

We now only emit:

t2.cc:1:7: warning: type specifier missing, defaults to 'int'
int x(*g);
      ^


Note that the example in SemaCXX/nested-name-spec.cpp:f4 is still
not great, we now produce both of:

void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \
                      expected-error {{variable has incomplete type 'void'}}

The second diagnostic should be silenced by something getting marked invalid.
I don't plan to fix this though.

llvm-svn: 68919
2009-04-12 22:23:27 +00:00
Sebastian Redl d1309a3c4d Add deleted functions and rvalue references to C++ status.
llvm-svn: 68903
2009-04-12 17:41:24 +00:00
Sebastian Redl 42e92c4bc3 Parse deleted member functions. Parsing member declarations goes through a different code path that I forgot previously.
Implement the rvalue reference overload dance for returning local objects. Returning a local object first tries to find a move constructor now.
The error message when no move constructor is defined (or is not applicable) and the copy constructor is deleted is quite ugly, though.

llvm-svn: 68902
2009-04-12 17:16:29 +00:00
Eli Friedman 574c745370 Diagnose uses of function specifiers on declarations which don't declare
functions.  Fixes PR3941.

llvm-svn: 68541
2009-04-07 19:37:57 +00:00
Douglas Gregor 40a8e0fbce XFAIL a failing test
llvm-svn: 68519
2009-04-07 16:32:03 +00:00
Douglas Gregor 68bc53967e Move the fix-it tests into their own subdirectory
llvm-svn: 68325
2009-04-02 17:19:13 +00:00
Douglas Gregor 7e70204613 Update comments in fixit tests
llvm-svn: 68279
2009-04-02 03:20:30 +00:00
Douglas Gregor 578dae57ca Introduce a "-fixit" mode to clang-cc that applies code-modification hints.
llvm-svn: 68268
2009-04-02 01:08:08 +00:00
Douglas Gregor 170512fa78 Add some more code modification hints
llvm-svn: 68261
2009-04-01 23:51:29 +00:00
Douglas Gregor e3e01a20d0 Add code modification hints to various parsing-related diagnostics.
Plus, reword a extension warnings to avoid talking about "ISO C" when
the extension might also be available in C++ or C++0x. 

llvm-svn: 68257
2009-04-01 22:41:11 +00:00
Douglas Gregor fe3d7d0880 Make parsing a semantic analysis a little more robust following Sema
failures that involve malformed types, e.g., "typename X::foo" where
"foo" isn't a type, or "std::vector<void>" that doens't instantiate
properly.

Similarly, be a bit smarter in our handling of ambiguities that occur
in Sema::getTypeName, to eliminate duplicate error messages about
ambiguous name lookup.

This eliminates two XFAILs in test/SemaCXX, one of which was crying
out to us, trying to tell us that we were producing repeated error
messages.

llvm-svn: 68251
2009-04-01 21:51:26 +00:00
Douglas Gregor 2e0757f319 Give Type::getDesugaredType a "for-display" mode that can apply more
heuristics to determine when it's useful to desugar a type for display
to the user. Introduce two C++-specific heuristics:

  - For a qualified type (like "foo::bar"), only produce a new
    desugred type if desugaring the qualified type ("bar", in this
    case) produces something interesting. For example, if "foo::bar"
    refers to a class named "bar", don't desugar. However, if
    "foo::bar" refers to a typedef of something else, desugar to that
    something else. This gives some useful desugaring such as
    "foo::bar (aka 'int')".
  - Don't desugar class template specialization types like
    "basic_string<char>" down to their underlying "class
    basic_string<char, char_traits<char>, allocator<char>>, etc.";
    it's better just to leave such types alone. 

Update diagnostics.html with some discussion and examples of type
preservation in C++, showing qualified names and class template
specialization types.

llvm-svn: 68207
2009-04-01 15:47:24 +00:00
Anders Carlsson dafd621b22 Check in test for namespace aliases+using directives.
llvm-svn: 68086
2009-03-31 05:47:19 +00:00
Sebastian Redl 4c0cd856b1 Reintroduce r67870 (rval ref overloading), since I can't reproduce any test failures on i386 or x86_64. If this fails for someone, please contact me.
llvm-svn: 67999
2009-03-29 15:27:50 +00:00
Anders Carlsson bb1e4724f1 More improvements to namespace aliases. We now support everything except aliases in using directives.
llvm-svn: 67966
2009-03-28 23:53:49 +00:00
Anders Carlsson 3694935cd2 Fix lookup bug
llvm-svn: 67964
2009-03-28 23:49:35 +00:00
Anders Carlsson b81608499e As Eli pointed out, it is possible that a namespace lookup is ambiguous!
llvm-svn: 67932
2009-03-28 07:51:31 +00:00
Anders Carlsson ac2c96528f Check that the alias points to a valid namespace.
llvm-svn: 67925
2009-03-28 06:42:02 +00:00
Anders Carlsson dca83c4676 Check that the namespace alias doesn't conflict with a previous declaration in this scope.
llvm-svn: 67921
2009-03-28 06:23:46 +00:00
Anders Carlsson 72f307a26e Revert Sebastian's rvalue patch (r67870) since it caused test failures in
SemaCXX//overload-member-call.cpp
SemaCXX//overloaded-operator.cpp
SemaTemplate//instantiate-method.cpp

llvm-svn: 67912
2009-03-28 04:17:27 +00:00
Anders Carlsson 0cb4cc106c Implement access checking for protected base classes.
llvm-svn: 67887
2009-03-28 01:09:05 +00:00
Sebastian Redl ec74096050 Better overload resolution for rvalue references.
llvm-svn: 67870
2009-03-27 21:36:42 +00:00
Anders Carlsson af06b977f9 It is OK to cast to a private base class if the current member belongs to the class that the private base class is a base of:
class A {};
class B : private A {
  void f(B *b) { A* a = b; }
};

llvm-svn: 67860
2009-03-27 19:01:12 +00:00
Anders Carlsson 733d77f1b4 Implement checking for base class access. Right now it's overly conservative but that will change. (Also, protected isn't implemented right now).
llvm-svn: 67827
2009-03-27 06:03:27 +00:00
Douglas Gregor 0b08ba44a1 If the user is trying to apply the -> or . member reference operator
to a function or function pointer, it's probably because the user
forgot to put in parentheses () to call the function.

llvm-svn: 67826
2009-03-27 06:00:30 +00:00
Douglas Gregor f4d17c4f22 Improve recovery when a constructor fails to type-check. Test case from Anders
llvm-svn: 67818
2009-03-27 04:38:56 +00:00
Anders Carlsson 137108da15 Set the access specifier for templates inside classes.
llvm-svn: 67726
2009-03-26 01:24:28 +00:00
Anders Carlsson 2ed6ceba1d Check that the access specifier of a member redeclaration is the same as the original declaration.
llvm-svn: 67722
2009-03-26 00:24:17 +00:00
Anders Carlsson a28908d575 Tighten the setAccess assert. We now allow AS_none if the decl contex is not a C++ record decl.
Also, fix fallout from the change.

llvm-svn: 67717
2009-03-25 23:38:06 +00:00
Anders Carlsson 75fdaa465f Improve handling of base initializers. We now parse initializers in out of line decls, such as:
class C {
    C() { }
    
    int a;
};

C::C() : a(10) { }

We also diagnose when initializers are used on declarations that aren't constructors:

t.cpp:1:10: error: only constructors take base initializers
void f() : a(10) { }
         ^

Doug and/or Sebastian: I'd appreciate a review, especially the nested-name-spec test results (from the looks of it we now match gcc in that test.)

llvm-svn: 67672
2009-03-25 02:58:17 +00:00
Sebastian Redl f769df5ef9 Parse deleted function definitions and hook them up to Doug's machinery.
llvm-svn: 67653
2009-03-24 22:27:57 +00:00
Douglas Gregor ac1fb65d0c Make sure to use RequireCompleteType rather than testing for
incomplete types. RequireCompleteType is needed when the type may be
completed by instantiating a template.

llvm-svn: 67643
2009-03-24 19:52:54 +00:00
Anders Carlsson b57738b09c Fix the bug that Eli noticed where we wouldn't look at function decls outside the class declaration.
llvm-svn: 67627
2009-03-24 17:23:42 +00:00
Daniel Dunbar a45cf5b6b0 Rename clang to clang-cc.
Tests and drivers updated, still need to shuffle dirs.

llvm-svn: 67602
2009-03-24 02:24:46 +00:00
Anders Carlsson 8f0d218598 Handle pointers to arrays of abstract types.
llvm-svn: 67598
2009-03-24 01:46:45 +00:00
Anders Carlsson b5a27b460c More work on diagnosing abstract classes. We can now handle cases like
class C {
  void g(C c);

  virtual void f() = 0;
};

In this case, C is not known to be abstract when doing semantic analysis on g. This is done by recursively traversing the abstract class and checking the types of member functions. 

llvm-svn: 67594
2009-03-24 01:19:16 +00:00
Douglas Gregor f4f296de01 Template instantiation for the declarations of member functions within
a class template. At present, we can only instantiation normal
methods, but not constructors, destructors, or conversion operators.

As ever, this contains a bit of refactoring in Sema's type-checking. In
particular:

  - Split ActOnFunctionDeclarator into ActOnFunctionDeclarator
    (handling the declarator itself) and CheckFunctionDeclaration
    (checking for the the function declaration), the latter of which
    is also used by template instantiation.
  - We were performing the adjustment of function parameter types in
    three places; collect those into a single new routine.
  - When the type of a parameter is adjusted, allocate an
    OriginalParmVarDecl to keep track of the type as it was written.
  - Eliminate a redundant check for out-of-line declarations of member
    functions; hide more C++-specific checks on function declarations
    behind if(getLangOptions().CPlusPlus).

llvm-svn: 67575
2009-03-23 23:06:20 +00:00
Anders Carlsson eb0c532faa More improvements to abstract type checking. Handle arrays correctly, and make sure to check parameter types before they decay.
llvm-svn: 67550
2009-03-23 19:10:31 +00:00
Anders Carlsson 0d5ca29b78 It's an error to try to allocate an abstract object using new.
llvm-svn: 67542
2009-03-23 17:49:10 +00:00
Sebastian Redl b28b407121 Disallow catching exceptions by rvalue reference.
llvm-svn: 67492
2009-03-22 23:49:27 +00:00
Sebastian Redl e97585f717 Implement static_cast from lvalue to rvalue reference.
llvm-svn: 67487
2009-03-22 22:30:06 +00:00
Eli Friedman 3164fb15e2 Check that the return/argument types of calls are complete.
llvm-svn: 67485
2009-03-22 22:00:50 +00:00
Anders Carlsson 576cc6f725 Disallow abstract types where appropriate.
llvm-svn: 67476
2009-03-22 20:18:17 +00:00
Anders Carlsson 7cbd8fb6b0 Keep track of whether a class is abstract or not. This is currently only used for the __is_abstract type trait.
llvm-svn: 67461
2009-03-22 01:52:17 +00:00
Douglas Gregor 63b4ff6aad Some minor tweaks and additional tests for rvalue references
llvm-svn: 67397
2009-03-20 20:21:37 +00:00
Douglas Gregor 975e6d0ccd Print the context of tag types as part of pretty-printing, e.g.,
struct N::M::foo

llvm-svn: 67284
2009-03-19 04:25:59 +00:00
Douglas Gregor 1835391025 Generalize printing of nested-name-specifier sequences for use in both
QualifiedNameType and QualifiedDeclRefExpr. We now keep track of the
exact nested-name-specifier spelling for a QualifiedDeclRefExpr, and
use that spelling when printing ASTs. This fixes PR3493.

llvm-svn: 67283
2009-03-19 03:51:16 +00:00
Douglas Gregor e177b7254d Extend the use of QualifiedNameType to the creation of class template
specialization names. This way, we keep track of sugared types like

  std::vector<Real>

I believe we are now using QualifiedNameTypes everywhere we can. Next
step: QualifiedDeclRefExprs.

llvm-svn: 67268
2009-03-19 00:39:20 +00:00
Douglas Gregor 5253768ada Introduce a representation for types that we referred to via a
qualified name, e.g., 

  foo::x

so that we retain the nested-name-specifier as written in the source
code and can reproduce that qualified name when printing the types
back (e.g., in diagnostics). This is PR3493, which won't be complete
until finished the other tasks mentioned near the end of this commit.

The parser's representation of nested-name-specifiers, CXXScopeSpec,
is now a bit fatter, because it needs to contain the scopes that
precede each '::' and keep track of whether the global scoping
operator '::' was at the beginning. For example, we need to keep track
of the leading '::', 'foo', and 'bar' in
 
  ::foo::bar::x

The Action's CXXScopeTy * is no longer a DeclContext *. It's now the
opaque version of the new NestedNameSpecifier, which contains a single
component of a nested-name-specifier (either a DeclContext * or a Type
*, bitmangled). 

The new sugar type QualifiedNameType composes a sequence of
NestedNameSpecifiers with a representation of the type we're actually
referring to. At present, we only build QualifiedNameType nodes within
Sema::getTypeName. This will be extended to other type-constructing
actions (e.g., ActOnClassTemplateId).

Also on the way: QualifiedDeclRefExprs will also store a sequence of
NestedNameSpecifiers, so that we can print out the property
nested-name-specifier. I expect to also use this for handling
dependent names like Fibonacci<I - 1>::value.

llvm-svn: 67265
2009-03-19 00:18:19 +00:00
Sebastian Redl 0f8b23f71f Almost complete implementation of rvalue references. One bug, and a few unclear areas. Maybe Doug can shed some light on some of the fixmes.
llvm-svn: 67059
2009-03-16 23:22:08 +00:00
Anders Carlsson 27de6a5e91 Handle static_asserts when instantiating structs.
llvm-svn: 67031
2009-03-15 18:44:04 +00:00
Anders Carlsson 54b2698587 Handle dependent types/exprs in static_assert expressions.
llvm-svn: 66997
2009-03-14 00:33:21 +00:00
Anders Carlsson 5bbe1d7ba7 More static_assert work. Check that the assert expr is valid and show an error if it's false. Create the declaration and add it to the current context.
llvm-svn: 66995
2009-03-14 00:25:26 +00:00
Douglas Gregor 04e9a03e6f Fix various problems with matching out-of-line definitions of static
class members to the corresponding in-class declaration.

Diagnose the erroneous use of 'static' on out-of-line definitions of
class members. 

llvm-svn: 66740
2009-03-11 23:52:16 +00:00
Douglas Gregor 0c88030abd Move most of the checking from ActOnCXXMemberDeclarator to other, more general routines. This is a step toward separating the checking logic from Declarators, which in turn is required for template instantiation.
llvm-svn: 66734
2009-03-11 23:00:04 +00:00
Douglas Gregor 1efa437be6 Implement basic template instantiation for fields. Reshuffle checking
for FieldDecls so that the parser and the template instantiation make
use of the same semantic checking module.

llvm-svn: 66685
2009-03-11 18:59:21 +00:00
Douglas Gregor 2689746705 Add basic, hackish support for instantiation of typedefs in a class
template. More importantly, start to sort out the issues regarding
complete types and nested-name-specifiers, especially the question of:
when do we instantiate a class template specialization that occurs to
the left of a '::' in a nested-name-specifier?

llvm-svn: 66662
2009-03-11 16:48:53 +00:00
Douglas Gregor c2fd626cac Improve recovery from ill-formed scope specifiers. Fixes PR3670.
llvm-svn: 66286
2009-03-06 19:06:37 +00:00
Douglas Gregor d45b93bdd6 Implement the GNU semantics for forward declarations of enum types in
C and C++. Fixes PR3688.

llvm-svn: 66282
2009-03-06 18:34:03 +00:00
Chris Lattner d26760aecb refactor C++ bitfield checking a bit (haha)
llvm-svn: 66213
2009-03-05 23:01:03 +00:00
Chris Lattner 73bf7b42b6 fix PR3607 and a fixme, by checking bitfield constraints
more consistently.

llvm-svn: 66210
2009-03-05 22:45:59 +00:00
Douglas Gregor e62c0a45dd Improve merging of function declarations. Specifically:
- When we are declaring a function in local scope, we can merge with
    a visible declaration from an outer scope if that declaration
    refers to an entity with linkage. This behavior now works in C++
    and properly ignores entities without linkage.
  - Diagnose the use of "static" on a function declaration in local
    scope.
  - Diagnose the declaration of a static function after a non-static
    declaration of the same function.
  - Propagate the storage specifier to a function declaration from a
    prior declaration (PR3425)
  - Don't name-mangle "main"

llvm-svn: 65360
2009-02-24 01:23:02 +00:00
Chris Lattner 810d330cd3 Fix a long standard problem with clang retaining "too much" sugar
information about types.  We often print diagnostics where we say 
"foo_t" is bad, but the user doesn't know how foo_t is declared 
(because it is a typedef).  Fix this by expanding sugar when present
in a diagnostic (and not one of a few special cases, like vectors).

Before:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' and 'typeof(F)')
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

After:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

llvm-svn: 65081
2009-02-19 23:45:49 +00:00
Douglas Gregor 0f3dd9a86b Provide a proper source location when building an implicit dereference. Fixes PR3600
llvm-svn: 64993
2009-02-19 00:52:42 +00:00
Douglas Gregor 171c45ab0c Downgrade complaints about calling unavailable functions to a warning
(as GCC does), except when we've performed overload resolution and
found an unavailable function: in this case, we actually error.

Merge the checking of unavailable functions with the checking for
deprecated functions. This unifies a bit of code, and makes sure that
we're checking for unavailable functions in the right places. Also,
this check can cause an error. We may, eventually, want an option to
make "unavailable" warnings into errors.

Implement much of the logic needed for C++0x deleted functions, which
are effectively the same as "unavailable" functions (but always cause
an error when referenced). However, we don't have the syntax to
specify deleted functions yet :)

llvm-svn: 64955
2009-02-18 21:56:37 +00:00
Douglas Gregor b2809a0a1b Don't allow calls to functions marked "unavailable". There's more work
to do in this area, since there are other places that reference
FunctionDecls.

Don't allow "overloadable" functions (in C) to be declared without a
prototype.

llvm-svn: 64897
2009-02-18 06:34:51 +00:00
Douglas Gregor 5978cdb5ef Make "implicit int" an error in C++ (unless we're allowing Microsoft
extensions). This caught a couple bugs in our test suite :)

llvm-svn: 64686
2009-02-16 22:38:20 +00:00
Mike Stump 6bae7a1b2a Add expected note. Surely people test before the check in stuff.
llvm-svn: 64565
2009-02-14 20:35:19 +00:00
Cedric Venet 08438133da Add svn:eol-style=native to some files
Correct two files with inconsistent lines endings.

llvm-svn: 64564
2009-02-14 20:20:19 +00:00
Douglas Gregor 2de3e31cf8 Add test case to insure that implicit builtin declarations for C library functions aren't created in C++
llvm-svn: 64513
2009-02-14 00:37:42 +00:00
Douglas Gregor 6752502b81 Expand the definition of a complex promotion to include complex ->
complex conversions where the conversion between the real types is an
integral promotion. This is how G++ handles complex promotions for its
complex integer extension.

llvm-svn: 64344
2009-02-12 00:26:06 +00:00
Douglas Gregor 78ca74d81d Introduce _Complex conversions into the function overloading
system. Since C99 doesn't have overloading and C++ doesn't have
_Complex, there is no specification for    this. Here's what I think
makes sense.

Complex conversions come in several flavors:

  - Complex promotions:  a complex -> complex   conversion where the
    underlying real-type conversion is a floating-point promotion. GCC
    seems to call this a promotion, EDG does something else. This is
    given "promotion" rank for determining the best viable function.
  - Complex conversions: a complex -> complex conversion that is
    not a complex promotion. This is given "conversion" rank for
    determining the best viable   function.
  - Complex-real conversions: a real -> complex or complex -> real
    conversion. This is given "conversion" rank for determining the
    best viable function.

These rules are the same for C99 (when using the "overloadable"
attribute) and C++. However, there is one difference in the handling
of floating-point promotions: in C99, float -> long double and double
-> long double are considered promotions (so we give them "promotion" 
rank), while C++ considers these conversions ("conversion" rank).

llvm-svn: 64343
2009-02-12 00:15:05 +00:00
Sebastian Redl 1df2bbe7f9 Update new expression to make use of Declarator::getSourceRange().
References are not objects; implement this in Type::isObjectType().

llvm-svn: 64152
2009-02-09 18:24:27 +00:00
Sebastian Redl df0913ba70 Fix redundant errors with missing default arguments in member declarations.
llvm-svn: 64085
2009-02-08 14:56:26 +00:00
Sebastian Redl aa400d83e6 Make the test cases failing due to exact diagnostic matching XFAIL.
llvm-svn: 64080
2009-02-08 10:28:44 +00:00
Sebastian Redl 2175b6a767 Make one expected-diag directive match exactly one actual diagnostic.
This uncovers some bugs, so several test cases now fail.

llvm-svn: 64025
2009-02-07 19:52:04 +00:00
Sebastian Redl f3b5e27fee Make const-initialized const integral variables I-C-Es in C++.
llvm-svn: 64015
2009-02-07 13:06:23 +00:00
Sebastian Redl 9c3b4b1bc5 Add negative test cases and fix diagnostics for member pointer dereferencing.
llvm-svn: 63987
2009-02-07 00:41:42 +00:00
Sebastian Redl 112a976616 Implement dereferencing of pointers-to-member.
llvm-svn: 63983
2009-02-07 00:15:38 +00:00
Douglas Gregor 8af63e42e3 Diagnose attempts to define a namespace member out-of-line when no
matching member exists. Thanks to Piotr Rak for reporting the problem!

llvm-svn: 63939
2009-02-06 17:46:57 +00:00
Douglas Gregor 700792c4e4 Improvements and fixes for name lookup with using directives, from Piotr Rak!
Also, put Objective-C protocols into their own identifier
namespace. Otherwise, we find protocols when we don't want to in C++
(but not in C).

llvm-svn: 63877
2009-02-05 19:25:20 +00:00
Douglas Gregor fc4f8a1834 Implement semantic analysis for the GNU flexible array initialization
extension. The interaction with designated initializers is a
bit... interesting... but we follow GNU's lead and don't permit too
much crazy code in this area.

Also, make the "excess initializers" error message a bit more
informative.

Addresses PR2561: http://llvm.org/bugs/show_bug.cgi?id=2561

llvm-svn: 63785
2009-02-04 22:46:25 +00:00
Sebastian Redl 18f8ff62a3 Implement taking address of member functions, including overloaded ones.
llvm-svn: 63779
2009-02-04 21:23:32 +00:00
Douglas Gregor 8a6be5ec64 Diagnose ambiguities in getTypeName. Fixes http://llvm.org/bugs/show_bug.cgi?id=3475
llvm-svn: 63737
2009-02-04 17:00:24 +00:00
Douglas Gregor 94eabf3355 Bring operator name lookup (as required for C++ operator overloading)
into the general name-lookup fold. This cleans up some ugly,
not-quite-working code in the handling of operator overloading.

llvm-svn: 63735
2009-02-04 16:44:47 +00:00
Douglas Gregor b8a9a41dd6 Fix our semantic analysis of
unqualified-id '('

in C++. The unqualified-id might not refer to any declaration in our
current scope, but declarations by that name might be found via
argument-dependent lookup. We now do so properly.

As part of this change, CXXDependentNameExpr, which was previously
designed to express the unqualified-id in the above constructor within
templates, has become UnresolvedFunctionNameExpr, which does
effectively the same thing but will work for both templates and
non-templates.

Additionally, we cope with all unqualified-ids, since ADL also applies
in cases like

  operator+(x, y)

llvm-svn: 63733
2009-02-04 15:01:18 +00:00
Douglas Gregor e254f90d94 Initial implementation of argument dependent lookup (a.k.a. ADL,
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
2009-02-04 00:32:51 +00:00
Sebastian Redl 3d3f75a995 Allow taking the address of data members, resulting in a member pointer.
Pointers to functions don't work yet, and pointers to overloaded functions even less. Also, far too much illegal code is accepted.

llvm-svn: 63655
2009-02-03 20:19:35 +00:00
Douglas Gregor 9554952264 Remove a fixed FIXME
llvm-svn: 63648
2009-02-03 19:26:44 +00:00
Douglas Gregor 4489e9465f When looking for a tag name via unqualified name lookup, only look in
scopes where the name would be considered a redeclaration if we know
that we're declaring or defining that tag.

llvm-svn: 63647
2009-02-03 19:26:08 +00:00
Douglas Gregor 889ceb752d Semantic analysis, ASTs, and unqualified name lookup support for C++
using directives, from Piotr Rak!

llvm-svn: 63646
2009-02-03 19:21:40 +00:00
Douglas Gregor bb2e688396 Steve set me straight on this one. GCC was right, EDG was wrong: the
direct-initialization following a user-defined conversion can select
any constructor; it just can't employ any user-defined
conversions. So we ban those conversions and classify the constructor
call based on the relationship between the "from" and "to" types in
the conversion.

llvm-svn: 63554
2009-02-02 22:11:10 +00:00
Douglas Gregor a5c9e1ae93 Check value-initializations that occur when an initializer list
provides too few elements.

llvm-svn: 63525
2009-02-02 17:43:21 +00:00
Douglas Gregor 576e98cc1e Improve our handling of the second step in a user-defined conversion
sequence. Previously, we weren't permitting the second step to call
copy constructors, which left user-defined conversion sequences
surprisingly broken.

Now, we perform overload resolution among all of the constructors, but
only accept the result if it makes the conversion a standard
conversion. Note that this behavior is different from both GCC and EDG
(which don't agree with each other, either); I've submitted a core
issue on the matter.

llvm-svn: 63450
2009-01-30 23:27:23 +00:00
Douglas Gregor d42a0fb41b Upgrade the "excess elements in array initializer" warning to an
error, since both C99 and C++ consider it an error. For reference, GCC
makes this a warning while G++ makes it an error.

llvm-svn: 63435
2009-01-30 22:26:29 +00:00
Douglas Gregor d14247a9e5 Implement and test aggregate initialization in C++. Major changes:
- Support initialization of reference members; complain if any
  reference members are left uninitialized.
  - Use C++ copy-initialization for initializing each element (falls
  back to constraint checking in C)
  - Make sure we diagnose when one tries to provide an initializer
  list for a non-aggregate.
  - Don't complain about empty initializers in C++ (they are permitted)
  - Unrelated but necessary: don't bother trying to convert the
  decl-specifier-seq to a type when we're dealing with a C++
  constructor, destructor, or conversion operator; it results in
  spurious warnings.

llvm-svn: 63431
2009-01-30 22:09:00 +00:00
Sebastian Redl ed8f200318 Implement pointer to member handling in static_cast.
Fix a stupid mistake in UnwrapSimilarPointers that made any two member pointers compatible as long as the pointee was the same.
Make a few style corrections as suggested by Chris.

llvm-svn: 63215
2009-01-28 18:33:18 +00:00
Douglas Gregor fb03466388 Complete semantic checking for typedef redeclarations in C++. The
rules are slightly different than in C, and now we handle both
dialects properly.

llvm-svn: 63211
2009-01-28 17:15:10 +00:00
Sebastian Redl a5a77a6dc6 Add handling of member pointers to reinterpret_cast.
llvm-svn: 63150
2009-01-27 23:18:31 +00:00
Sebastian Redl b44ab5f25d Add support for member pointers to const_cast.
llvm-svn: 63055
2009-01-26 22:19:12 +00:00
Sebastian Redl a7bc8473a3 Remove an implemented FIXME and extend test cases. Follow-up on Doug's review.
llvm-svn: 63032
2009-01-26 19:54:48 +00:00
Sebastian Redl 72b597d6b6 Implement implicit conversions for pointers-to-member.
llvm-svn: 62971
2009-01-25 19:43:20 +00:00
Sebastian Redl c6d52f5dfb Make tentative parsing of pointer-to-member decls work, and fix other stuff pointed out by Doug.
llvm-svn: 62944
2009-01-24 23:29:36 +00:00
Sebastian Redl 9ed6efdd75 Add support for declaring pointers to members.
Add serialization support for ReferenceType.

llvm-svn: 62934
2009-01-24 21:16:55 +00:00
Sebastian Redl 634b6581ec Add missing test case for operator ! result type.
llvm-svn: 62532
2009-01-19 21:37:51 +00:00
Douglas Gregor dd430f7ec9 Centralize error reporting of improper uses of incomplete types in the
new DiagnoseIncompleteType. It provides additional information about
struct/class/union/enum types when possible, either by pointing to the
forward declaration of that type or by pointing to the definition (if
we're in the process of defining that type). 
Fixes <rdar://problem/6500531>.

llvm-svn: 62521
2009-01-19 19:26:10 +00:00
Douglas Gregor dee1be8e95 Teach DeclContext how to find the primary declaration for any TagDecl
even when we are still defining the TagDecl. This is required so that
qualified name lookup of a class name within its definition works (see
the new bits in test/SemaCXX/qualified-id-lookup.cpp).

As part of this, move the nested redefinition checking code into
ActOnTag. This gives us diagnostics earlier (when we try to perform
the nested redefinition, rather than when we try to complete the 2nd
definition) and removes some code duplication.

llvm-svn: 62386
2009-01-17 00:42:38 +00:00
Douglas Gregor 225b321a85 Fix <rdar://problem/6502934>. We were creating an ImplicitCastExpr
with reference type (it should be an lvalue with non-reference type).

llvm-svn: 62345
2009-01-16 19:38:23 +00:00
Douglas Gregor dd04d33e3a Part one of handling C++ functional casts. This handles semantic
analysis and AST-building for the cases where we have N != 1
arguments. For N == 1 arguments, we need to finish the C++
implementation of explicit type casts (C++ [expr.cast]).

llvm-svn: 62329
2009-01-16 18:33:17 +00:00
Douglas Gregor 71def4416f Add test case for member name lookup
llvm-svn: 62324
2009-01-16 17:06:33 +00:00
Anders Carlsson a7d069d63c Use a single function for doing vararg argument promotion. Also, make sure to do the promotion before checking the type - fixes PR3340.
llvm-svn: 62323
2009-01-16 16:48:51 +00:00
Douglas Gregor 6bd18af3a3 Add test for contextual conversion to bool, and enable some FIXME'd tests
llvm-svn: 62302
2009-01-16 03:02:29 +00:00
Douglas Gregor 3407432644 Refactor name lookup.
This change refactors and cleans up our handling of name lookup with
LookupDecl. There are several aspects to this refactoring:

  - The criteria for name lookup is now encapsulated into the class
  LookupCriteria, which replaces the hideous set of boolean values
  that LookupDecl currently has.

  - The results of name lookup are returned in a new class
  LookupResult, which can lazily build OverloadedFunctionDecls for
  overloaded function sets (and, eventually, eliminate the need to
  allocate member for OverloadedFunctionDecls) and contains a
  placeholder for handling ambiguous name lookup (for C++).

  - The primary entry points for name lookup are now LookupName (for
    unqualified name lookup) and LookupQualifiedName (for qualified
    name lookup). There is also a convenience function
    LookupParsedName that handles qualified/unqualified name lookup
    when given a scope specifier. Together, these routines are meant
    to gradually replace the kludgy LookupDecl, but this won't happen
    until after we have base class lookup (which forces us to cope
    with ambiguities).

  - Documented the heck out of name lookup. Experimenting a little
    with using Doxygen's member groups to make some sense of the Sema
    class. Feedback welcome!

  - Fixes some lingering issues with name lookup for
  nested-name-specifiers, which now goes through
  LookupName/LookupQualifiedName. 

llvm-svn: 62245
2009-01-14 22:20:51 +00:00
Douglas Gregor cba844dae6 Test explicit constructor
llvm-svn: 62237
2009-01-14 18:02:48 +00:00
Douglas Gregor 5fb5397238 Introduce support for C++0x explicit conversion operators (N2437)
Small cleanup in the handling of user-defined conversions. 

Also, implement an optimization when constructing a call. We avoid
recomputing implicit conversion sequences and instead use those
conversion sequences that we computed as part of overload resolution.

llvm-svn: 62231
2009-01-14 15:45:31 +00:00
Anders Carlsson 6393773c4b Warn when someone tries to pass a variable with a non-POD type to a varargs function/method/block.
llvm-svn: 62148
2009-01-13 05:48:52 +00:00
Douglas Gregor 02a0acd0bc Fix argument-passing bugs in a call to object
llvm-svn: 62147
2009-01-13 05:10:00 +00:00
Douglas Gregor c5e61070f6 Add the proper restrictions on the left-hand argument of a built-in
assignment operator candidate (C++ [over.match.oper]p4).

llvm-svn: 62128
2009-01-13 00:52:54 +00:00
Douglas Gregor f399ef43c7 Make sure we don't name a constructor or destructor with a qualified
type. It leads to very weird errors.

llvm-svn: 62124
2009-01-13 00:11:19 +00:00
Douglas Gregor ae5e28578c Update C++ status and add a few more tests of overloading for member function calls
llvm-svn: 62121
2009-01-12 23:20:38 +00:00
Douglas Gregor c6f58fe266 Implement support for anonymous structs and unions in C. Both C and
C++ handle anonymous structs/unions in the same way. Addresses several
bugs:

  <rdar://problem/6259534>
  <rdar://problem/6481130>
  <rdar://problem/6483159>

The test case in PR clang/1750 now passes with -fsyntax-only, but
CodeGen for inline assembler still fails.

llvm-svn: 62112
2009-01-12 22:49:06 +00:00
Douglas Gregor 658b9550bb When we see a reference to a struct, class, or union like "struct X"
that is neither a definition nor a forward declaration and where X has
not yet been declared as a tag, introduce a declaration
into the appropriate scope (which is likely *not* to be the current
scope). The rules for the placement of the declaration differ slightly
in C and C++, so we implement both and test the various corner
cases. This implementation isn't 100% correct due to some lingering
issues with the function prototype scope (for a function parameter
list) not being the same scope as the scope of the function
definition. Testcase is FIXME'd; this probably isn't an important issue.

Addresses <rdar://problem/6484805>.

llvm-svn: 62014
2009-01-09 22:42:13 +00:00
Sebastian Redl 6079525591 Very basic support for pure virtual functions.
llvm-svn: 62003
2009-01-09 19:57:06 +00:00
Douglas Gregor 82ac25e4a7 Unify the code for defining tags in C and C++, so that we always
introduce a Scope for the body of a tag. This reduces the number of
semantic differences between C and C++ structs and unions, and will
help with other features (e.g., anonymous unions) in C. Some important
points:

  - Fields are now in the "member" namespace (IDNS_Member), to keep
    them separate from tags and ordinary names in C. See the new test
    in Sema/member-reference.c for an example of why this matters. In
    C++, ordinary and member name lookup will find members in both the
    ordinary and member namespace, so the difference between
    IDNS_Member and IDNS_Ordinary is erased by Sema::LookupDecl (but
    only in C++!). 
  - We always introduce a Scope and push a DeclContext when we're
    defining a tag, in both C and C++. Previously, we had different
    actions and different Scope/CurContext behavior for enums, C
    structs/unions, and C++ structs/unions/classes. Now, it's one pair
    of actions. (Yay!)

There's still some fuzziness in the handling of struct/union/enum
definitions within other struct/union/enum definitions in C. We'll
need to do some more cleanup to eliminate some reliance on CurContext
before we can solve this issue for real. What we want is for something
like this:

  struct X {
    struct T { int x; } t;
  };

to introduce T into translation unit scope (placing it at the
appropriate point in the IdentifierResolver chain, too), but it should
still have struct X as its lexical declaration
context. PushOnScopeChains isn't smart enough to do that yet, though,
so there's a FIXME test in nested-redef.c

llvm-svn: 61940
2009-01-08 20:45:30 +00:00
Douglas Gregor f325278799 Fix PR clang/3291
llvm-svn: 61886
2009-01-07 21:36:02 +00:00
Douglas Gregor f4d332797b Finished semantic analysis of anonymous unions in C++.
Duplicate-member checking within classes is still a little messy, and
anonymous unions are still completely broken in C. We'll need to unify
the handling of fields in C and C++ to make this code applicable in
both languages.

llvm-svn: 61878
2009-01-07 19:46:03 +00:00
Douglas Gregor 4bba1ed9bc Test case for anonymous unions in C++
llvm-svn: 61860
2009-01-07 16:22:09 +00:00
Douglas Gregor 8d973111a8 When determining whether a variable is a file-scoped variable, check
out its lookup context (to see through linkage
specifications). Addresses <rdar://problem/6477142>.

llvm-svn: 61848
2009-01-07 02:48:43 +00:00
Douglas Gregor c7acfdfe9a Add QualifiedDeclRefExpr, which retains additional source-location
information for declarations that were referenced via a qualified-id,
e.g., N::C::value. We keep track of the location of the start of the
nested-name-specifier. Note that the difference between
QualifiedDeclRefExpr and DeclRefExpr does have an effect on the
semantics of function calls in two ways:
  1) The use of a qualified-id instead of an unqualified-id suppresses
     argument-dependent lookup
  2) If the name refers to a virtual function, the qualified-id
  version will call the function determined statically while the
  unqualified-id version will call the function determined dynamically
  (by looking up the appropriate function in the vtable).

Neither of these features is implemented yet, but we do print out
qualified names for QualifiedDeclRefExprs as part of the AST printing.

llvm-svn: 61789
2009-01-06 05:10:23 +00:00
Sebastian Redl baad4e765f PODness and Type Traits
Make C++ classes track the POD property (C++ [class]p4)
Track the existence of a copy assignment operator.
Implicitly declare the copy assignment operator if none is provided.
Implement most of the parsing job for the G++ type traits extension.
Fully implement the low-hanging fruit of the type traits:
__is_pod: Whether a type is a POD.
__is_class: Whether a type is a (non-union) class.
__is_union: Whether a type is a union.
__is_enum: Whether a type is an enum.
__is_polymorphic: Whether a type is polymorphic (C++ [class.virtual]p1).

llvm-svn: 61746
2009-01-05 20:52:13 +00:00
Douglas Gregor 3bdc895818 Add forgotten test case for linkage specifications
llvm-svn: 61737
2009-01-05 19:50:09 +00:00
Douglas Gregor 07665a69e8 Introduce support for "transparent" DeclContexts, which are
DeclContexts whose members are visible from enclosing DeclContexts up
to (and including) the innermost enclosing non-transparent
DeclContexts. Transparent DeclContexts unify the mechanism to be used
for various language features, including C enumerations, anonymous
unions, C++0x inline namespaces, and C++ linkage
specifications. Please refer to the documentation in the Clang
internals manual for more information.

Only enumerations and linkage specifications currently use transparent
DeclContexts.

Still to do: use transparent DeclContexts to implement anonymous
unions and GCC's anonymous structs extension, and, later, the C++0x
features. We also need to tighten up the DeclContext/ScopedDecl link
to ensure that every ScopedDecl is in a single DeclContext, which
will ensure that we can then enforce ownership and reduce the memory
footprint of DeclContext.

llvm-svn: 61735
2009-01-05 19:45:36 +00:00
Chris Lattner c69537feb5 Fix a bug where we'd try to look beyond the current cached tokens when
not in backtracking mode.  This was just using the wrong predicate.

llvm-svn: 61666
2009-01-05 01:42:04 +00:00
Chris Lattner 6fead6e33b add a testcase
llvm-svn: 61660
2009-01-05 00:59:08 +00:00
Sebastian Redl a2b5e31cb1 Diagnose declarations that don't declare anything, and fix PR3020.
Examples:
int;
typedef int;

llvm-svn: 61454
2008-12-28 15:28:59 +00:00
Douglas Gregor 1dc9826a46 Add support for out-of-line definitions of conversion functions and member operators
llvm-svn: 61442
2008-12-26 15:00:45 +00:00
Douglas Gregor 583540360c Correct the order in which we cope with end-of-class-definition
semantics and improve our handling of default arguments. Specifically,
we follow this order:

  - As soon as the see the '}' in the class definition, the class is
  complete and we add any implicit declarations (default constructor,
  copy constructor, etc.) to the class.
  - If there are any default function arguments, parse them
  - If there were any inline member function definitions, parse them

As part of this change, we now keep track of the the fact that we've
seen unparsed default function arguments within the AST. See the new
ParmVarDecl::hasUnparsedDefaultArg member. This allows us to properly
cope with calls inside default function arguments to other functions
where we're making use of the default arguments.

Made some C++ error messages regarding failed initializations more
specific. 

llvm-svn: 61406
2008-12-24 00:01:03 +00:00
Sebastian Redl ccd251b88f Merge pr-3188.cpp into constructor.cpp.
llvm-svn: 61370
2008-12-23 16:41:32 +00:00
Sebastian Redl 45f11a9b05 Guard against the return of PR3188
llvm-svn: 61348
2008-12-22 21:43:13 +00:00
Sebastian Redl 9b244a8797 Full AST support and better Sema support for C++ try-catch.
llvm-svn: 61346
2008-12-22 21:35:02 +00:00
Sebastian Redl 54c04d4700 Partial AST and Sema support for C++ try-catch.
llvm-svn: 61337
2008-12-22 19:15:10 +00:00
Douglas Gregor 97fd6e24c4 Add support for calls to overloaded member functions. Things to note:
- Overloading has to cope with having both static and non-static
    member functions in the overload set.
  - The call may or may not have an implicit object argument,
    depending on the syntax (x.f() vs. f()) and the context (static
    vs. non-static member function).
  - We now generate MemberExprs for implicit member access expression.
  - We now cope with mutable whenever we're building MemberExprs.

llvm-svn: 61329
2008-12-22 05:46:06 +00:00
Anders Carlsson 39def3adc8 Add codegen support for __null
llvm-svn: 61314
2008-12-21 22:39:40 +00:00
Douglas Gregor 2eedc3aa1c Add support for member references (E1.E2, E1->E2) with C++ semantics,
which can refer to static data members, enumerators, and member
functions as well as to non-static data members.

Implement correct lvalue computation for member references in C++. 
Compute the result type of non-static data members of reference type properly.

llvm-svn: 61294
2008-12-20 23:49:58 +00:00
Sebastian Redl e10c2c32af Implement checks for bool in increment and decrement.
llvm-svn: 61275
2008-12-20 09:35:34 +00:00
Douglas Gregor 55ad91fecb Ultrasimplistic sketch for the parsing of C++ template-ids. This won't
become useful or correct until we (1) parse template arguments
correctly, (2) have some way to turn template-ids into types,
declarators, etc., and (3) have a real representation of templates.

llvm-svn: 61208
2008-12-18 19:37:40 +00:00
Chris Lattner 0cb00d66ea This is valid in C++.
void foo() { return foo(); }

llvm-svn: 61188
2008-12-18 02:03:48 +00:00
Douglas Gregor 19b8c4fffa Delay semantic analysis of the C++ names casts when the subexpression is type-dependent or the destination type is dependent.
llvm-svn: 61165
2008-12-17 22:52:20 +00:00
Douglas Gregor ec8806e8ec Removed the warning
warning: statement was disambiguated as declaration

because it is currently firing in cases where the declaration would
not actually parse as a statement. We'd love to bring this warning
back if we can make it more accurate.

llvm-svn: 61137
2008-12-17 16:19:15 +00:00
Nuno Lopes 5773a1be41 fix PR 3222: allow one to get the address of a global function in C++
llvm-svn: 61111
2008-12-16 22:58:26 +00:00
Douglas Gregor 4d87df5853 Delay parsing of default arguments of member functions until the class
is completely defined (C++ [class.mem]p2).

Reverse the order in which we process the definitions of member
functions specified inline. This way, we'll get diagnostics in the
order in which the member functions were declared in the class.

llvm-svn: 61103
2008-12-16 21:30:33 +00:00
Douglas Gregor 195002917e Partial fix for qualified name lookup, such that the lookup of N in
N::X only skips those entities specified in C++ [basic.lookup.qual]p1.

Note that both EDG and GCC currently get this wrong. EDG has confirmed
that the bug will be fixed in a future version.

llvm-svn: 61079
2008-12-16 06:37:47 +00:00
Douglas Gregor 29e174cc58 Make name lookup when we're inside a declarator's scope, such as ClassName::func, work with the new unqualified name lookup code. Test it with default arguments in out-of-line member definitions
llvm-svn: 61060
2008-12-16 00:38:16 +00:00