Commit Graph

63 Commits

Author SHA1 Message Date
Douglas Gregor 5be1eb8daf Revert r111609, which is failing its new test.
llvm-svn: 111611
2010-08-20 03:26:10 +00:00
John McCall a189f2eb0a Detect efforts to declare a template member friend and explicitly ignore them.
Avoids a crash.

llvm-svn: 111609
2010-08-20 01:40:01 +00:00
Douglas Gregor c3a6ade0bb Move Sema's headers into include/clang/Sema, renaming a few along the way.
llvm-svn: 110945
2010-08-12 20:07:10 +00:00
Chandler Carruth 2d69ec7a72 Partial fix for PR7267 based on comments by John McCall on an earlier patch.
This is more targeted, as it simply provides toggle actions for the parser to
turn access checking on and off. We then use these to suppress access checking
only while we parse the template-id (included scope specifier) of an explicit
instantiation and explicit specialization of a class template. The
specialization behavior is an extension, as it seems likely a defect that the
standard did not exempt them as it does explicit instantiations.

This allows the very common practice of specializing trait classes to work for
private, internal types. This doesn't address instantiating or specializing
function templates, although those apparently already partially work.

The naming and style for the Action layer isn't my favorite, comments and
suggestions would be appreciated there.

llvm-svn: 106993
2010-06-28 08:39:25 +00:00
Jeffrey Yasskin caa710dfd2 PR7245: Make binding a reference to a temporary without a usable copy
constructor into an extension warning into the error that C++98 requires.

llvm-svn: 105529
2010-06-07 15:58:05 +00:00
Douglas Gregor ed2540d205 When we complain about a member being inaccessible due to a constraint
along an access path, add another note pointing at the member we
actually found.

llvm-svn: 104937
2010-05-28 04:34:55 +00:00
John McCall 9720514f3b An access is permitted if the current template instantiates to the appropriate
class.  Add some conservative support for the idea.  Fixes PR 7024.

llvm-svn: 102999
2010-05-04 05:11:27 +00:00
Anders Carlsson 11373b5277 Add another 'catch all' access diagnostic.
llvm-svn: 102169
2010-04-23 03:41:35 +00:00
John McCall 8c12dc4351 Use the naming class from the overloaded lookup when access-checking an
address of overloaded function, instead of assuming that a nested name
specifier was used.  A nested name specifier is not required for static
functions.

Fixes PR6886.

llvm-svn: 102107
2010-04-22 18:44:12 +00:00
Anders Carlsson 05bf00938b Re-land the patch that merges two diagnostics into one now that it passes self-host :)
llvm-svn: 102050
2010-04-22 05:40:53 +00:00
Daniel Dunbar e448942b76 Revert "Unify two diagnostics into one.", it breaks with an assertion failure on bootstrap.
llvm-svn: 102043
2010-04-22 02:35:33 +00:00
Anders Carlsson 046bb5cc3f Unify two diagnostics into one.
llvm-svn: 102040
2010-04-22 01:17:32 +00:00
Anders Carlsson 4bb6e92902 Diagnose access to fields with private constructors.
llvm-svn: 102025
2010-04-21 20:28:29 +00:00
Anders Carlsson 43c64af5f0 Keep tack of whether a base in an InitializedEntity is an inherited virtual base or not. Use this in CheckConstructorAccess.
llvm-svn: 102020
2010-04-21 19:52:01 +00:00
Anders Carlsson a01874bf44 Pass the InitializedEntity to Sema::CheckConstructorAccess and use it to report different diagnostics depending on which entity is being initialized.
llvm-svn: 102010
2010-04-21 18:47:17 +00:00
Chandler Carruth aad3007fe5 Fix the access checking of function and function template argument types,
return types, and default arguments. This fixes PR6855 along with several
similar cases where we rejected valid code.

llvm-svn: 101706
2010-04-18 08:23:21 +00:00
John McCall 8e36d53e34 Check access for the implicit calls to destructors that occur when we
have a temporary object in C++.

Also fix a tag mismatch that Doug noticed.

llvm-svn: 100593
2010-04-07 00:41:46 +00:00
John McCall a8ae222d0e Implement the protected access restriction ([class.protected]), which requires
that protected members be used on objects of types which derive from the
naming class of the lookup.  My first N attempts at this were poorly-founded,
largely because the standard is very badly worded here.

llvm-svn: 100562
2010-04-06 21:38:20 +00:00
John McCall d79b4d8173 Correct the calculation of access to more closely model the wording in
the standard.

llvm-svn: 100155
2010-04-02 00:03:43 +00:00
John McCall b493d53424 Fix an oversight with access control for address-of-function.
llvm-svn: 99942
2010-03-30 22:20:00 +00:00
John McCall 16df1e59f2 Propagate the "found declaration" (i.e. the using declaration instead of
the underlying/instantiated decl) through a lot of API, including "intermediate"
MemberExprs required for (e.g.) template instantiation.  This is necessary
because of the access semantics of member accesses to using declarations:
only the base class *containing the using decl* need be accessible from the
naming class.

This allows us to complete an access-controlled selfhost, if there are no
recent regressions.

llvm-svn: 99936
2010-03-30 21:47:33 +00:00
Douglas Gregor 8933623b91 Optimize PartialDiagnostic's memory-allocation behavior by placing a
cache of PartialDiagnostic::Storage objects into an allocator within
the ASTContext. This eliminates a significant amount of malloc
traffic, for a 10% performance improvement in -fsyntax-only wall-clock
time with 403.gcc's combine.c.

Also, eliminate the RequireNonAbstractType hack I put in earlier,
which was but a symptom of this larger problem.

Fixes <rdar://problem/7806091>.

llvm-svn: 99849
2010-03-29 23:34:08 +00:00
John McCall 3dc81f77f6 Accumulate all functions and classes that the effective context is
nested within, and suddenly local classes start working.  Wouldn't be
necessary if I hadn't used local classes in Clang in the first place.
Or, well, wouldn't be necessary yet. :)

llvm-svn: 99709
2010-03-27 06:55:49 +00:00
John McCall e0b2ddb492 Reapply r99596 with a fix: link an instantiated friend function to its
pattern if it has a body.

llvm-svn: 99610
2010-03-26 04:53:08 +00:00
John McCall 1a78217721 Apparently that didn't work. Reverting for now.
llvm-svn: 99601
2010-03-26 02:38:45 +00:00
John McCall a5beaf6958 Properly instantiate and link in friend function templates.
llvm-svn: 99596
2010-03-26 02:05:14 +00:00
John McCall 27e70baa55 Fix a very minor oversight in privileges-elevation: we were only considering
friendship for a derived class if the base class specifier was non-public,
and thus not considering friendship for non-public members of public bases.

llvm-svn: 99554
2010-03-25 21:39:55 +00:00
John McCall 15ad0962dc Preserve type-source information in friend declarations.
llvm-svn: 99525
2010-03-25 18:04:51 +00:00
John McCall 598b4405a6 Properly instantiate friend class template declarations and link them into
the redeclaration chain.  Recommitted from r99477 with a fix:  we need to
merge in default template arguments from previous declarations.

llvm-svn: 99496
2010-03-25 06:39:04 +00:00
Bob Wilson 63d45e51fb Revert 99477 since it appears to be breaking the clang-x86_64-darwin10-fnt
buildbot.  The tramp3d test fails.
--- Reverse-merging r99477 into '.':
U    test/SemaTemplate/friend-template.cpp
U    test/CXX/temp/temp.decls/temp.friend/p1.cpp
U    lib/Sema/SemaTemplateInstantiateDecl.cpp
U    lib/Sema/SemaAccess.cpp

llvm-svn: 99481
2010-03-25 04:40:43 +00:00
John McCall ac418d44ed Properly instantiate and link in friend-class-template declarations.
llvm-svn: 99477
2010-03-25 02:56:08 +00:00
John McCall 69f7586c5b Walk out of enums when determining effective context.
llvm-svn: 99391
2010-03-24 09:04:37 +00:00
John McCall 816d75b701 Support friend function specializations.
llvm-svn: 99389
2010-03-24 07:46:06 +00:00
John McCall c62bb64c65 Implement a framework for the delay of arbitrary diagnostics within
templates.  So delay access-control diagnostics when (for example) the target
of a friend declaration is a specific specialization of a template.

I was surprised to find that this was required for an access-controlled selfhost.

llvm-svn: 99383
2010-03-24 05:22:00 +00:00
John McCall a0296f7987 Remember the "found declaration" for an overload candidate, which is the
entity (if applicable) which was actually looked up.  If a candidate was found
via a using declaration, this is the UsingShadowDecl;  otherwise, if
the candidate is template specialization, this is the template;  otherwise,
this is the function.

The point of this exercise is that "found declarations" are the entities
we do access control for, not their underlying declarations.  Broadly speaking,
this patch fixes access control for using declarations.

There is a *lot* of redundant code calling into the overload-resolution APIs;
we really ought to clean that up.

llvm-svn: 98945
2010-03-19 07:35:19 +00:00
John McCall a332b953e8 When elevating access along an inheritance path, initialize the computed
access to the (elevated) access of the accessed declaration, if applicable,
rather than plunking that access onto the end after we've calculated the
inheritance access.

Also, being a friend of a derived class gives you public access to its
members (subject to later modification by further inheritance);  it does
not simply ignore a single location of restricted inheritance.

Also, when computing the best unprivileged path to a subobject, preserve
the information that the worst path might be AS_none (forbidden) rather
than a minimum of AS_private.

llvm-svn: 98899
2010-03-18 23:49:19 +00:00
John McCall fb6f52671a from code inspection, we were treating placement news with one argument as
non-placement news when selecting the corresponding operator delete;  this is
fixed.
Access and ambiguity control for calls to operator new and delete.  Also AFAICT

llvm-svn: 98818
2010-03-18 08:19:33 +00:00
John McCall 39e8288b40 Implement non-dependent friend functions and classes.
llvm-svn: 98764
2010-03-17 20:01:29 +00:00
John McCall fb803d7dcb Grant nested classes the access privileges of their enclosing classes.
llvm-svn: 98710
2010-03-17 04:58:56 +00:00
John McCall ab8c273b4f Access control for implicit calls to copy assignment operators and copy
constructors from implicitly-defined members.

llvm-svn: 98614
2010-03-16 06:11:48 +00:00
John McCall 1064d7ef29 Perform access control for the implicit base and member destructor calls
required when emitting a destructor definition.

llvm-svn: 98609
2010-03-16 05:22:47 +00:00
John McCall 16927f6274 Implement basic support for friend types and functions in non-dependent
contexts.

llvm-svn: 98321
2010-03-12 01:19:31 +00:00
John McCall 5b0829a321 Improve access control diagnostics. Perform access control on member-pointer
conversions.  Fix an access-control bug where privileges were not considered
at intermediate points along the inheritance path.  Prepare for friends.

llvm-svn: 95775
2010-02-10 09:31:12 +00:00
John McCall 03c4848bf4 Mark dtors for parameter variables and eliminate some redundant type munging.
llvm-svn: 95079
2010-02-02 09:10:11 +00:00
John McCall 6781b05a92 Access control for implicit destructor calls. Diagnostic could be orders of
magnitude clearer.

llvm-svn: 95078
2010-02-02 08:45:54 +00:00
John McCall 760af170ff Access checking for implicit user-defined conversions.
llvm-svn: 94971
2010-02-01 03:16:54 +00:00
John McCall b3a4400554 Access checking for overloaded operators.
llvm-svn: 94725
2010-01-28 01:42:12 +00:00
John McCall 86121519ca Implement access-check delays for out-of-line member definitions
using the same framework we use for deprecation warnings.

llvm-svn: 94659
2010-01-27 03:50:35 +00:00
John McCall 58cc69d4c1 Implement access control for overloaded functions. Suppress access control
diagnostics in "early" lookups, such as during typename checks and when building
unresolved lookup expressions.

llvm-svn: 94647
2010-01-27 01:50:18 +00:00
John McCall 553c0796ee Implement elementary access control.
llvm-svn: 94268
2010-01-23 00:46:32 +00:00