Commit Graph

246 Commits

Author SHA1 Message Date
John McCall 553c0796ee Implement elementary access control.
llvm-svn: 94268
2010-01-23 00:46:32 +00:00
Douglas Gregor 9de54ea41b Reimplement constructor declarator parsing to cope with template-ids
that name constructors, the endless joys of out-of-line constructor
definitions, and various other corner cases that the previous hack
never imagined. Fixes PR5688 and tightens up semantic analysis for
constructor names.

Additionally, fixed a problem where we wouldn't properly enter the
declarator scope of a parenthesized declarator. We were entering the
scope, then leaving it when we saw the ")"; now, we re-enter the
declarator scope before parsing the parameter list.

Note that we are forced to perform some tentative parsing within a
class (call it C) to tell the difference between

  C(int); // constructor

and

  C (f)(int); // member function

which is rather unfortunate. And, although it isn't necessary for
correctness, we use the same tentative-parsing mechanism for
out-of-line constructors to improve diagnostics in icky cases like:

  C::C C::f(int); // error: C::C refers to the constructor name, but
                  // we complain nicely and recover by treating it as
                  // a type.

llvm-svn: 93322
2010-01-13 17:31:36 +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
Douglas Gregor d615026e8d C++0x [dcl.typedef]p4, take 3, where we actually figure out what "that
is not also a typedef-name" actually means. For anyone keeping score,
that's John: 2, Doug: 0.

llvm-svn: 93196
2010-01-11 22:30:10 +00:00
Douglas Gregor 323ade5ac8 Use isa<ElaboratedType> rather than getAs<ElaboratedType>, since the
latter may (eventually) perform multiple levels of desugaring (thus
breaking the newly-added tests) and the former is faster. Thanks, John!

llvm-svn: 93192
2010-01-11 22:04:54 +00:00
Douglas Gregor 9dd13ab202 Allow redefinitions of typedef-names within class scope when the type
they redefine is a class-name but not a typedef-name, per C++0x
[dcl.typedef]p4. The code in the test was valid C++98 and is valid
C++0x, but an unintended consequence of DR56 made it ill-formed in
C++03 (which we were luck enough to implement). Fixes PR5455.

llvm-svn: 93188
2010-01-11 21:54:40 +00:00
Douglas Gregor b90b66178e When resolving a single function template specialization to a
function, be sure to adjust the resulting argument type to a pointer
(if necessary). Fixes PR5910 and PR5949.

llvm-svn: 93178
2010-01-11 19:55:36 +00:00
Douglas Gregor 0662b16ad2 Test case for naming of conversion function template specializations
llvm-svn: 93177
2010-01-11 19:52:23 +00:00
John McCall 64fe233704 When parsing an identifier as an expression in C++, only try to annotate it
as a type or scope token if the next token requires it.

This eliminates a lot of redundant lookups in C++, but there's room for
improvement;  a better solution would do a single lookup whose kind and
results would be passed through the parser.

llvm-svn: 92930
2010-01-07 19:29:58 +00:00
Douglas Gregor b3d8deecbf Add test from PR5913, which has already been fixed
llvm-svn: 92863
2010-01-06 22:09:05 +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 936dc5638c Make sure to use ASTContext::getAs*ArrayType() when decomposing array
types. Fixes APFloat.cpp compilation failure.

llvm-svn: 92523
2010-01-04 22:11:45 +00:00
John McCall 0e21fccfae Tweak the text of several main() diagnostics and punch a hole specifically for
Darwin's sekrit fourth argument.  This should probably be factored to
let targets make target-specific decisions about what main() should look like.

Fixes rdar://problem/7414990
or if different platforms have radically different ideas of what they want in

llvm-svn: 92128
2009-12-24 09:58:38 +00:00
Douglas Gregor b6ea60872d Switch Sema::AddCXXDirectInitializerToDecl over to InitializationSequence
llvm-svn: 91927
2009-12-22 22:17:25 +00:00
Douglas Gregor 613bf10470 Enter the scope of an initializer for direct-initialization as well as
for copy-initialization.

llvm-svn: 91909
2009-12-22 17:47:17 +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
Eli Friedman 9025ec2ee5 Fix for PR5840: fix the kind of name lookup used for classes in
Sema::getTypeName.

"LookupNestedNameSpecifierName" isn't quite the right kind of lookup, though; 
it doesn't ignore namespaces.  Someone more familiar with the lookup code
should fix this properly.

llvm-svn: 91809
2009-12-21 01:42:38 +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 1c7e6ec27b Don't inject the class name until that magical lbrace.
Because of the rules of base-class lookup* and the restrictions on typedefs, it
was actually impossible for this to cause any problems more serious than the
spurious acceptance of
  template <class T> class A : B<A> { ... };
instead of
  template <class T> class A : B<A<T> > { ... };
but I'm sure we can all agree that that is a very important restriction which
is well worth making another Parser->Sema call for.

(*) n.b. clang++ does not implement these rules correctly;  we are not ignoring
    non-type names

llvm-svn: 91792
2009-12-20 07:58:13 +00:00
John McCall bffb990c23 Test the lookup I wasn't sure would be done properly after the last patch.
Clang reasonably adds all the base specifiers in one pass;  this is now required
for correctness to prevent lookup from going mad.  But this has the advantage of
establishing the correct context when looking up base specifiers, which will be
important for access control.

llvm-svn: 91791
2009-12-20 05:57:29 +00:00
John McCall 2d814c305e Parse base specifiers within the scope of the class. This is possibly not
quite right;  I'll come back to it later.  It does fix PR 5741.

llvm-svn: 91789
2009-12-19 21:48:58 +00:00
John McCall 6df5fef637 Refactor to remove more dependencies on PreDeclaratorDC. I seem to have made
the redeclaration problems in the [temp.explicit]p3 testcase worse, but I can
live with that;  they'll need to be fixed more holistically anyhow.

llvm-svn: 91771
2009-12-19 10:49:29 +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 5103effb1d A CXXExprWithTemporaries expression is an lvalue if its subexpression
is an lvalue. Fixes PR5787.

llvm-svn: 91765
2009-12-19 07:07:47 +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
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 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
John McCall 0db42252f7 Successive anonymous namespaces name the same scope. I misinterpreted the
standard the last time.  Fixes PR5766.

llvm-svn: 91493
2009-12-16 02:06:49 +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 906db8a546 Fix some diagnostic-related FIXMEs, from Nicola Gigante
llvm-svn: 91433
2009-12-15 16:44:32 +00:00
John McCall 9003406096 Diagnose the use of typedefs for template specialization types in the scope
specifiers for out-of-line declarations, e.g.
  typedef Temp<int> MyTemp;
  template <> MyTemp::foo;

llvm-svn: 91395
2009-12-15 02:19:47 +00:00
Anders Carlsson f5056f8545 Fix test.
llvm-svn: 91245
2009-12-13 18:30:34 +00:00
Anders Carlsson 7e0b207e54 More improvements to checking allocation and deallocation functions.
llvm-svn: 91244
2009-12-13 17:53:43 +00:00
Anders Carlsson e363c8e1df Correctly diagnose [basic.stc.dynamic.allocation]p1
llvm-svn: 91190
2009-12-12 00:32:00 +00:00
Anders Carlsson 12308f41e7 Improve diagnostics for malformed delete operator function declarations.
llvm-svn: 91180
2009-12-11 23:23:22 +00:00
John McCall 0048c5115d Test member template using hiding.
llvm-svn: 91099
2009-12-11 02:55:56 +00:00
John McCall a17e83e437 Check if the target of a using decl is already declared in this scope before
doing any of the other redeclaration checks.  We were missing a few cases.
Fixes PR 5752.

llvm-svn: 91096
2009-12-11 02:33:26 +00:00
John McCall a009726ce3 Implement access declarations. Most of the work here is parsing them, which
is difficult because they're so terribly, terribly ambiguous.


We implement access declarations in terms of using declarations, which is
quite reasonable.  However, we should really persist the access/using
distinction in the AST and use the appropriate name in diagnostics.  This
isn't a priority, so I'll just file a PR and hope someone else does it. :)

llvm-svn: 91095
2009-12-11 02:10:03 +00:00
John McCall 7a2865a217 Actually try to trigger the last diagnostic in the declaration-collision test case.
Surprisingly, we *do* diagnose one of them.  Since we don't really track scopes into
instantiation, this has to signal some kind of bug.

llvm-svn: 91063
2009-12-10 21:17:25 +00:00
John McCall e29c5cd239 Improve the diagnostic when a new declaration conflicts with a using shadow
declaration.  Rename note_using_decl to note_using, which is possibly less confusing.
Add a test for non-class-scope using decl collisions and be sure to note the case
we can't diagnose yet.

llvm-svn: 91057
2009-12-10 19:51:03 +00:00
Douglas Gregor 51e77d5ab0 Move initialization via initializer list over to InitializationSequences.
llvm-svn: 91050
2009-12-10 17:56:55 +00:00
John McCall 84d8767c15 Implement redeclaration checking and hiding semantics for using declarations. There
are a couple of O(n^2) operations in this, some analogous to the usual O(n^2)
redeclaration problem and some not.  In particular, retroactively removing
shadow declarations when they're hidden by later decls is pretty unfortunate.
I'm not yet convinced it's worse than the alternative, though.

llvm-svn: 91045
2009-12-10 09:41:52 +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 3a60c87a59 Handle unresolved using decls in bare lookups. These are not being adequately
tested.  Fixes PR5727.

llvm-svn: 90893
2009-12-08 22:45:53 +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
Douglas Gregor 70dd094105 Remove empty test cases
llvm-svn: 90749
2009-12-07 06:11:34 +00:00