Douglas Gregor [Thu, 27 Jan 2011 01:40:17 +0000 (01:40 +0000)]
When we run into a template parameter that should have a default
argument but doesn't (because previous template parameters had default
arguments), clear out all of the default arguments so that we maintain
the invariant that a template parameter has a default argument only if
subsequence template parameters also have default arguments.
Fixes a crash-on-invalid <rdar://problem/8913649>.
Douglas Gregor [Thu, 27 Jan 2011 00:58:17 +0000 (00:58 +0000)]
Fix a horrible bug in our handling of C-style casting, where a C-style
derived-to-base cast that also casts away constness (one of the cases
for static_cast followed by const_cast) would be treated as a bit-cast
rather than a derived-to-base class, causing miscompiles and
heartburn.
Douglas Gregor [Wed, 26 Jan 2011 21:20:37 +0000 (21:20 +0000)]
Implement the restriction that a function with a ref-qualifier cannot
overload a function without a ref-qualifier (C++0x
[over.load]p2). This, apparently, completes the implementation of
rvalue references for *this.
Douglas Gregor [Wed, 26 Jan 2011 20:35:32 +0000 (20:35 +0000)]
Improve the extension warning for the use of ref-qualifiers, to
distinguish them from rvalue references. Using the rvalue-references
warning was weird when the ref-qualifier was '&'.
Douglas Gregor [Wed, 26 Jan 2011 19:41:18 +0000 (19:41 +0000)]
Rvalue references for *this: explicitly keep track of whether a
reference binding is for the implicit object parameter of a member
function with a ref-qualifier. My previous comment, that we didn't
need to track this explicitly, was wrong: we do in fact get
rvalue-references-prefer-rvalues overloading with ref-qualifiers.
Douglas Gregor [Wed, 26 Jan 2011 19:30:28 +0000 (19:30 +0000)]
Rvalue references for *this: implement the implicit conversion rules
for the implicit object argument to a non-static member function with
a ref-qualifier (C++0x [over.match.funcs]p4).
Douglas Gregor [Wed, 26 Jan 2011 17:47:49 +0000 (17:47 +0000)]
Rvalue references for *this: allow functions to be overloaded based on
the presence and form of a ref-qualifier. Note that we do *not* yet
implement the restriction in C++0x [over.load]p2 that requires either
all non-static functions with a given parameter-type-list to have a
ref-qualifier or none of them to have a ref-qualifier.
Douglas Gregor [Wed, 26 Jan 2011 17:36:28 +0000 (17:36 +0000)]
Rvalue references for *this: add name mangling for ref-qualifiers,
using rules that I just made up this morning. This encoding has now
been proposed to the Itanium C++ ABI group for inclusion, but of
course it's still possible that the mangling will change.
Douglas Gregor [Wed, 26 Jan 2011 15:36:03 +0000 (15:36 +0000)]
Clean up the C++0x __has_feature tests. Specifically:
- Don't publicize a C++0x feature through __has_feature if we aren't
in C++0x mode (even if the feature is available only with a
warning).
- "auto" is not implemented well enough for its __has_feature to be
turned on.
- Fix the test of C++0x __has_feature to actually test what we're
trying to test. Searching for the substring "foo" when our options
are "foo" and "no_foo" doesn't work :)
Douglas Gregor [Wed, 26 Jan 2011 05:01:58 +0000 (05:01 +0000)]
Rvalue references for *this:
- Add ref-qualifiers to the type system; they are part of the
canonical type. Print & profile ref-qualifiers
- Translate the ref-qualifier from the Declarator chunk for
functions to the function type.
- Diagnose mis-uses of ref-qualifiers w.r.t. static member
functions, free functions, constructors, destructors, etc.
- Add serialization and deserialization of ref-qualifiers.
Ted Kremenek [Wed, 26 Jan 2011 04:49:52 +0000 (04:49 +0000)]
Teach -Wreturn-type that destructors can appear
after a 'return' in a CFGBlock. This accidentally
was working before, but the false assumption that
'return' always appeared at the end of the block
was uncovered by a recent change.
John McCall [Wed, 26 Jan 2011 04:00:11 +0000 (04:00 +0000)]
Better framework for conditional cleanups; untested as yet.
I'm separately committing this because it incidentally changes some
block orderings and minor IR issues, like using a phi instead of
an unnecessary alloca.
[analyzer] Enable the self-init checker under command-line option '-analyzer-check-objc-self-init' which by default
is enabled by the driver for '--analyze'.
Ted Kremenek [Tue, 25 Jan 2011 22:50:47 +0000 (22:50 +0000)]
Fix regression in -Wreturn-type caused by not
handling all CFGElement kinds. While writing
the test case, it turned out that return-noreturn.cpp
wasn't actually testing anything since it has the wrong -W
flag. That uncovered another regression with
the handling of destructors marked noreturn. WIP.
Douglas Gregor [Tue, 25 Jan 2011 22:19:32 +0000 (22:19 +0000)]
Speculatively implement a tweak to the C++0x overload resolution rules
for reference binding (C++ [over.rank.ics]p3b1sb4), so that we prefer
the binding of an lvalue reference to a function lvalue over the
binding of an rvalue reference. This change resolves the ambiguity
with std::forward and lvalue references to function types in a way
that seems consistent with the original rvalue references proposal.
My proposed wording for this change is shown in
isBetterReferenceBindingKind(); we'll try to get this change adopted
in the C++0x working paper as well.
Jeffrey Yasskin [Tue, 25 Jan 2011 20:08:12 +0000 (20:08 +0000)]
Add an attribute to forbid temporary instances of a type. This allows class
authors to write
class __attribute__((forbid_temporaries)) Name { ... };
when they want to force users to name all variables of the type. This protects
people from doing things like creating a scoped_lock that only lives for a
single statement instead of an entire scope.
The warning produced by this attribute can be disabled by
-Wno-forbid-temporaries.
Douglas Gregor [Tue, 25 Jan 2011 19:39:31 +0000 (19:39 +0000)]
Fix the ranking of reference bindings during overload resolution
(C++0x [over.ics.rank]p3) when one binding is an lvalue reference and
the other is an rvalue reference that binds to an rvalue. In
particular, we were using the predict "is an rvalue reference" rather
than "is an rvalue reference that binds to an rvalue", which was
incorrect in the one case where an rvalue reference can bind to an
lvalue: function references.
This particular issue cropped up with std::forward, where Clang was
picking an std::forward overload while forwarding an (lvalue)
reference to a function. However (and unfortunately!), the right
answer for this code is that the call to std::forward is
ambiguous. Clang now gets that right, but we need to revisit the
std::forward implementation in libc++.
Ted Kremenek [Tue, 25 Jan 2011 19:13:54 +0000 (19:13 +0000)]
Recycle memory for GRStates that are never referenced
by ExplodedNodes. This leads to about a 4-8%
reduction in memory footprint when analyzing
functions in sqlite3.
Douglas Gregor [Tue, 25 Jan 2011 17:51:48 +0000 (17:51 +0000)]
Be a bit more defensive about setting the temporary base location
during template instantiation. This code needs to eventually die, but
this little tweak fixes PR8629, where bad location information slipped
through to the location of a class template instantiation.
Douglas Gregor [Tue, 25 Jan 2011 17:19:08 +0000 (17:19 +0000)]
Implement the rvalue-reference deduction transformation (from T&& ->
T) when taking the address of an overloaded function or matching a
specialization to a template (C++0x [temp.deduct.type]p10). Fixes
PR9044.
Douglas Gregor [Tue, 25 Jan 2011 02:17:32 +0000 (02:17 +0000)]
Downgrade the error about rvalue references to an extension warning
and turn on __has_feature(cxx_rvalue_references). The core rvalue
references proposal seems to be fully implemented now, pending lots
more testing.
[analyzer] Introduce ExprEngine::VisitObjCMessage for handling general ObjCMessages (both message expressions and property access)
and use it in ExprEngine::VisitObjCMessageExpr.
[analyzer] Introduce ObjCMessage which represents both explicit ObjC message expressions and implicit
messages that are sent for handling properties in dot syntax.
Replace all direct uses of ObjCMessageExpr in the checkers and checker interface with ObjCMessage.
Nick Lewycky [Mon, 24 Jan 2011 19:01:04 +0000 (19:01 +0000)]
Enhance the diagnostic for referring to a typedef with an elaborated name to be
as useful in a templated context as it is without templates. Fixes PR8755!
Douglas Gregor [Mon, 24 Jan 2011 18:44:28 +0000 (18:44 +0000)]
Eliminate the use of getTypeForDecl from clang_getCursorType() and
clang_getDeclObjCTypeEncoding(); use ASTContext's methods instead,
which will (lazily) create the type as needed. Otherwise, we can end
up with null QualTypes.
Douglas Gregor [Mon, 24 Jan 2011 16:14:37 +0000 (16:14 +0000)]
Re-instate r123977/r123978, my updates of the reference-binding
implementation used by overload resolution to support rvalue
references. The original commits caused PR9026 and some
hard-to-reproduce self-host breakage.
The only (crucial!) difference between this commit and the previous
commits is that we now properly check the SuppressUserConversions flag
before attempting to perform a second user-defined conversion in
reference binding, breaking the infinite recursion chain of
user-defined conversions.
Rvalue references should be working a bit better now.
Axel Naumann [Mon, 24 Jan 2011 15:44:00 +0000 (15:44 +0000)]
Check whether DependentScopeDeclRefExpr's NestedNameSpecifier exists before accessing it, both for consistency (see StmtPrinter::VisitDeclRefExpr()) and for other use cases of dependent types.