Commit Graph

251 Commits

Author SHA1 Message Date
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