Douglas Gregor [Fri, 21 May 2010 23:18:07 +0000 (23:18 +0000)]
Improve parser recovery when we encounter a dependent template name
that is missing the 'template' keyword, e.g.,
t->getAs<T>()
where getAs is a member of an unknown specialization. C++ requires
that we treat "getAs" as a value, but that would fail to parse since T
is the name of a type. We would then fail at the '>', since a type
cannot be followed by a '>'.
This is a very common error for C++ programmers to make, especially
since GCC occasionally allows it when it shouldn't (as does Visual
C++). So, when we are in this case, we use tentative parsing to see if
the tokens starting at "<" can only be parsed as a template argument
list. If so, we produce a diagnostic with a fix-it that states that
the 'template' keyword is needed:
test/SemaTemplate/dependent-template-recover.cpp:5:8: error: 'template' keyword
is required to treat 'getAs' as a dependent template name
t->getAs<T>();
^
template
This is just a start of this patch; I'd like to apply the same
approach to everywhere that a template-id with dependent template name
can be parsed.
Nick Lewycky [Fri, 21 May 2010 23:14:51 +0000 (23:14 +0000)]
Outdent this file by 2 spaces per the coding standards, and also clean up
whitespace at the end of lines since I'm already touching the whole file
anyways.
Douglas Gregor [Fri, 21 May 2010 20:29:55 +0000 (20:29 +0000)]
Use CanQualType to enforce the use of a canonical type argument to
CXXBasePaths::isAmbiguous(), rather than just asserting that we have a
canonical type. Fixes PR7176.
Douglas Gregor [Fri, 21 May 2010 17:55:12 +0000 (17:55 +0000)]
When generating the call arguments in a thunk to call the thunkee, do
not make copies non-POD arguments or arguments passed by reference:
just copy the pointers directly. This eliminates another source of the
dreaded memcpy-of-non-PODs. Fixes PR7188.
Chandler Carruth [Fri, 21 May 2010 10:29:57 +0000 (10:29 +0000)]
Teach the RecursiveASTVisitor to enter parts of the AST previously missed.
Factor its implementation to ease the addition of these custom edges to
traverse. With this patch we get initializer expressions, block bodies, type
source info, and function argument, result, and exception types. There are
probably still some more missed edges.
While we're here, clean up and flesh out a bunch of comments.
Patch by Zhanyong Wan; I've done a cursory review, but further review
appreciated. This is fast becoming one of the most important public APIs to the
AST.
John McCall [Fri, 21 May 2010 04:11:14 +0000 (04:11 +0000)]
Allocate space in a block record for implicit references to the Objective C
'self' variable arising from uses of the 'super' keyword. Also reorganize
some code so that BlockInfo (now CGBlockInfo) can be opaque outside of
CGBlocks.cpp.
John McCall [Fri, 21 May 2010 01:18:57 +0000 (01:18 +0000)]
When emitting an lvalue for an anonymous struct or union member during
class initialization, drill down through an arbitrary number of anonymous
records.
Douglas Gregor [Fri, 21 May 2010 00:31:19 +0000 (00:31 +0000)]
When instantiating anonymous structs/unions within a function, make
sure that the anonymous struct/union record declaration gets
instantiated before the variable declaration, and that it and its
fields (recursively) get entries in the local instantiation map. Fixes
PR7088.
John McCall [Thu, 20 May 2010 23:23:51 +0000 (23:23 +0000)]
Be sure to apply initializers to members of anonymous structs and unions
recursively, e.g. so that members of anonymous unions inside anonymous structs
still get initialized. Also generate default constructor calls for anonymous
struct members when necessary.
Douglas Gregor [Thu, 20 May 2010 22:12:02 +0000 (22:12 +0000)]
Add a new failure kind, FK_Incomplete, to InitializationSequence, to
capture failures when we try to initialize an incomplete
type. Previously, we would (ab)use FK_ConversionFailed, then
occasionally dereference a null pointer when trying to diagnose the
failure. Fixes <rdar://problem/7959007>.
Douglas Gregor [Thu, 20 May 2010 20:58:56 +0000 (20:58 +0000)]
Reinstate r104117, Chandler Carruth's change that "[provides] a naming
class for UnresolvedLookupExprs, even when occuring on template
names" along with a fix for an Objective-C++ crasher it introduced.
Douglas Gregor [Thu, 20 May 2010 15:39:01 +0000 (15:39 +0000)]
Assert that we do not try to memcpy a non-POD class type in C++. This
particular issue was the cause of the Boost.Interprocess failures, and
in general will lead to horrendous, hard-to-diagnose miscompiles. The
assertion itself has survives self-host and a full Boost build, so we
are close to eradicating this problem in C++.
Note that the assertion is *not* turned on for Objective-C++, where we
still have problems with introducing memcpy's of non-POD class
types. That part of the assertion will go away as soon as we fix the
known issues in Objective-C++.
Douglas Gregor [Thu, 20 May 2010 08:36:28 +0000 (08:36 +0000)]
Rework our handling of binding a reference to a temporary
subobject. Previously, we could only properly bind to a base class
subobject while extending the lifetime of the complete object (of a
derived type); for non-static data member subobjects, we could memcpy
(!) the result and bind to that, which is rather broken.
Now, we pull apart the expression that we're binding to, to figure out
which subobject we're accessing, then construct the temporary object
(adding a destruction if needed) and, finally, dig out the subobject
we actually meant to access.
This fixes yet another instance where we were memcpy'ing rather than
doing the right thing. However, note the FIXME in references.cpp:
there's more work to be done for binding to subobjects, since the AST
is incorrectly modeling some member accesses in base classes as
lvalues when they are really rvalues.
Douglas Gregor [Thu, 20 May 2010 05:54:35 +0000 (05:54 +0000)]
When creating a this-adjustment thunk where the return value is of C++
class type (that uses a return slot), pass the return slot to the
callee directly rather than allocating new storage and trying to copy
the object. This appears to have been the cause of the remaining two
Boost.Interprocess failures.
Douglas Gregor [Thu, 20 May 2010 02:24:22 +0000 (02:24 +0000)]
Various small fixes for construction/destruction of Objective-C++
instance variables:
- Use isRecordType() rather than isa<RecordType>(), so that we see
through typedefs in ivar types.
- Mark the destructor as referenced
- Perform C++ access control on the destructor
Chris Lattner [Thu, 20 May 2010 00:25:36 +0000 (00:25 +0000)]
switch TemplateArgumentListBuilder to hold its flat argument list in a smallvector
instead of new[]'d. This greatly reduces the number of new[]'s, and guess what,
they were all leaked.
where test/SemaTemplate/variadic-class-template-2.cpp is accessing the vector
out of range and NumPackArgs is negative. I assume variadic template args are
completely hosed.
Chris Lattner [Thu, 20 May 2010 00:19:09 +0000 (00:19 +0000)]
fix the TemplateArgumentList copy constructor to not
be a copy constructor (since it isn't one semantically)
and fix the ownership bits it sets to be correct!
Douglas Gregor [Wed, 19 May 2010 23:40:50 +0000 (23:40 +0000)]
When a conditional operator is an rvalue of class type, we need to
create a temporary copy of both the "true" and "false" results. Fixes
the Boost.Interprocess failures.
Daniel did all the hard work of tracking down the issue, I get to type
up the trivial fix for this horrible miscompile.
Daniel Dunbar [Wed, 19 May 2010 21:07:14 +0000 (21:07 +0000)]
Revert r104117, "Provide a naming class for UnresolvedLookupExprs, even when
occuring on..." which breaks some Objective-C code. Working on getting a test
case...
Douglas Gregor [Wed, 19 May 2010 18:39:18 +0000 (18:39 +0000)]
Cache the linkage of a type within its canonical type, eliminating
some seriously non-linear performance with deeply nested template
instantiations, as shown in PR6998.
Chandler Carruth [Wed, 19 May 2010 09:39:06 +0000 (09:39 +0000)]
Provide a naming class for UnresolvedLookupExprs, even when occuring on
template names. We were completely missing naming classes for many unqualified
lookups, but this didn't trigger code paths that need it. This removes part of
an optimization that re-uses the template name lookup done by the parser to
determine if explicit template arguments actually form a template-id.
Unfortunately the technique for avoiding the duplicate lookup lost needed data
such as the class context in which the lookup succeeded.
Douglas Gregor [Wed, 19 May 2010 04:13:23 +0000 (04:13 +0000)]
Profile type-dependent uses of overloaded operators in C++ the same
way regardless of whether some overloaded operator functions were
found by name lookup within the template. Fixes PR6851.
Chandler Carruth [Wed, 19 May 2010 02:12:56 +0000 (02:12 +0000)]
Fix a GCC warning about inline functions not being defined. Until r104081, only
the same .cpp file as provided the definitions referenced these functions,
hiding the issue. However, they are clearly no longer inline. Let me know if
there is a reason to move their definitions to the header and make them truly
inline.
Douglas Gregor [Tue, 18 May 2010 22:42:18 +0000 (22:42 +0000)]
Implement C++ support for vector and extended vector types. This
involves extending implicit conversion sequences to model vector
conversions and vector splats, along with teaching the C++ conditional
operator-checking code about vector types.
Ted Kremenek [Tue, 18 May 2010 22:32:15 +0000 (22:32 +0000)]
Add function 'clang_isTagDeclDefinition()' to allow clients of libclang to distinguish between
forward declarations and definitions of structs/classes/enums.
Ted Kremenek [Tue, 18 May 2010 21:09:07 +0000 (21:09 +0000)]
Teach CursorVisitor about duplicate ObjCPropertyDecls that can arise because of a current
design limitation in how we handle Objective-C class extensions. This was causing the CursorVisitor
to essentially visit an @property twice (once in the @interface, the other in the class extension).
Fixes <rdar://problem/7410145>.
Anders Carlsson [Tue, 18 May 2010 16:51:41 +0000 (16:51 +0000)]
Correctly initialize bases with member pointers. This should fix PR6441 but that test case is a bit weird and I'd like to investigate further before closing that bug.
Douglas Gregor [Tue, 18 May 2010 16:30:22 +0000 (16:30 +0000)]
Give a slight edge to the context-sensitive keyword 'super' over
non-function-local declarations with names similar to what the user
typed. For example, this allows us to correct 'supper' to 'super' in
an Objective-C message send, even though the C function 'isupper' has
the same edit distance.
Douglas Gregor [Tue, 18 May 2010 16:14:23 +0000 (16:14 +0000)]
Tweak typo-correction logic a bit regarding "super", so that we
consider "super" as a candidate whenever we're parsing an expression
within an Objective-C method in an interface that has a superclass. At
some point, we'd like to give "super" a little edge over non-local
names; that will come later.
Douglas Gregor [Tue, 18 May 2010 05:47:04 +0000 (05:47 +0000)]
"The attached patch allows clang to find the headers
for Visual Studio 2010. It also adds a registry search
for the Express edition,", from Steven Watanabe!
Douglas Gregor [Tue, 18 May 2010 05:45:02 +0000 (05:45 +0000)]
I hate this commit.
Revert much of the implementation of C++98/03 [temp.friend]p5 in
r103943 and its follow-ons r103948 and r103952. While our
implementation was technically correct, other compilers don't seem to
implement this paragraph (which forces the instantiation of friend
functions defined in a class template when a class template
specialization is instantiated), and doing so broke a bunch of Boost
libraries.
Since this behavior has changed in C++0x (which instantiates the
friend function definitions when they are used), we're going to skip
the nowhere-implemented C++98/03 semantics and go straight to the
C++0x semantics.
This commit is a band-aid to get Boost up and running again. It
doesn't really fix PR6952 (which this commit un-fixes), but it does
deal with the way Boost.Units abuses this particular paragraph.