summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaAccess.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Don't assume friended C++ method decls have qualifiersReid Kleckner2014-12-171-2/+2
| | | | | | | | | | | There are a few cases where unqualified lookup can find C++ methods. Unfortunately, none of them seem to have illegal access paths, so I can't excercise the diagnostic source range code that I am changing here. Fixes PR21851, which was a crash on valid. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224471 91177308-0d34-0410-b5e6-96231b3b80d8
* Consolidate some note diagnosticsAlp Toker2014-05-281-1/+2
| | | | | | | | | These note diags have the same message and can be unified further but for now let's just bring them together. Incidental change: Display a source range in the final attr diagnostic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209728 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Use 'nullptr'. Sema edition.Craig Topper2014-05-261-12/+13
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209613 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Replacing CXXRecordDecl iterators friend_begin() and friend_end() ↵Aaron Ballman2014-03-131-4/+1
| | | | | | with iterator_range friends(). Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203815 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with ↵Aaron Ballman2014-03-131-9/+5
| | | | | | iterator_range bases(). Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203803 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Replacing DeclBase iterators decls_begin() and decls_end() with ↵Aaron Ballman2014-03-071-5/+3
| | | | | | iterator_range decls(). The same is true for the noload versions of these APIs. Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203278 91177308-0d34-0410-b5e6-96231b3b80d8
* Move the -fms-compatibility using decl check after real access checkingReid Kleckner2014-02-081-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This avoids false positives from -Wmicrosoft when name lookup would normally succeed in standard C++. This triggered on a common CRTP pattern in clang, where a derived class would have a private using decl to pull in members of a dependent base: class Verifier : InstVisitor<Verifier> { private: using InstVisitor<Verifier>::visit; ... void anything() { visit(); // warned here } }; Real access checks pass here because we're in the context of the Verifier, but the -Wmicrosoft extension was just looking for the private access specifier. Reviewers: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2679 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201019 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename getResultType() on function and method declarations to getReturnType()Alp Toker2014-01-251-3/+2
| | | | | | | | | | | | | | | A return type is the declared or deduced part of the function type specified in the declaration. A result type is the (potentially adjusted) type of the value of an expression that calls the function. Rule of thumb: * Declarations have return types and parameters. * Expressions have result types and arguments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200082 91177308-0d34-0410-b5e6-96231b3b80d8
* Change a dyn_cast from r199794 to a straight castAlp Toker2014-01-221-1/+1
| | | | | | It's guaranteed to be a CXXMethodDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199795 91177308-0d34-0410-b5e6-96231b3b80d8
* Introduce and use Decl::getAsFunction() to simplify templated function checksAlp Toker2014-01-221-14/+8
| | | | | | | | | | | | | | Lift the getFunctionDecl() utility out of the parser into a general Decl::getAsFunction() and use it to simplify other parts of the implementation. Reduce isFunctionOrFunctionTemplate() to a simple type check that works the same was as the other is* functions and move unwrapping of shadowed decls to callers so it doesn't get run twice. Shuffle around canSkipFunctionBody() to reduce virtual dispatch on ASTConsumer. There's no need to query when we already know the body can't be skipped. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199794 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename FunctionProtoType accessors from 'arguments' to 'parameters'Alp Toker2014-01-201-5/+4
| | | | | | | | | | | | | | | | | Fix a perennial source of confusion in the clang type system: Declarations and function prototypes have parameters to which arguments are supplied, so calling these 'arguments' was a stretch even in C mode, let alone C++ where default arguments, templates and overloading make the distinction important to get right. Readability win across the board, especially in the casting, ADL and overloading implementations which make a lot more sense at a glance now. Will keep an eye on the builders and update dependent projects shortly. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199686 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename language option MicrosoftMode to MSVCCompatAlp Toker2014-01-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | There's been long-standing confusion over the role of these two options. This commit makes the necessary changes to differentiate them clearly, following up from r198936. MicrosoftExt (aka. fms-extensions): Enable largely unobjectionable Microsoft language extensions to ease portability. This mode, also supported by gcc, is used for building software like FreeBSD and Linux kernel extensions that share code with Windows drivers. MSVCCompat (aka. -fms-compatibility, formerly MicrosoftMode): Turn on a special mode supporting 'heinous' extensions for drop-in compatibility with the Microsoft Visual C++ product. Standards-compilant C and C++ code isn't guaranteed to work in this mode. Implies MicrosoftExt. Note that full -fms-compatibility mode is currently enabled by default on the Windows target, which may need tuning to serve as a reasonable default. See cfe-commits for the full discourse, thread 'r198497 - Move MS predefined type_info out of InitializePredefinedMacros' No change in behaviour. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199209 91177308-0d34-0410-b5e6-96231b3b80d8
* When performing a delayed access check, use the surrounding lexical context forRichard Smith2013-12-111-5/+4
| | | | | | | any local extern declaration, not just a local extern function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197000 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix init-captures for generic lambdas.Faisal Vali2013-12-051-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For an init capture, process the initialization expression right away. For lambda init-captures such as the following: const int x = 10; auto L = [i = x+1](int a) { return [j = x+2, &k = x](char b) { }; }; keep in mind that each lambda init-capture has to have: - its initialization expression executed in the context of the enclosing/parent decl-context. - but the variable itself has to be 'injected' into the decl-context of its lambda's call-operator (which has not yet been created). Each init-expression is a full-expression that has to get Sema-analyzed (for capturing etc.) before its lambda's call-operator's decl-context, scope & scopeinfo are pushed on their respective stacks. Thus if any variable is odr-used in the init-capture it will correctly get captured in the enclosing lambda, if one exists. The init-variables above are created later once the lambdascope and call-operators decl-context is pushed onto its respective stack. Since the lambda init-capture's initializer expression occurs in the context of the enclosing function or lambda, therefore we can not wait till a lambda scope has been pushed on before deciding whether the variable needs to be captured. We also need to process all lvalue-to-rvalue conversions and discarded-value conversions, so that we can avoid capturing certain constant variables. For e.g., void test() { const int x = 10; auto L = [&z = x](char a) { <-- don't capture by the current lambda return [y = x](int i) { <-- don't capture by enclosing lambda return y; } }; If x was not const, the second use would require 'L' to capture, and that would be an error. Make sure TranformLambdaExpr is also aware of this. Patch approved by Richard (Thanks!!) http://llvm-reviews.chandlerc.com/D2092 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196454 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix typo correction usage of SemaAccess.cpp.Eli Friedman2013-10-011-5/+3
| | | | | | | | | | When we check access for lookup results, make sure we propagate the result's access to the access control APIs; this can be different from the natural access of the declaration depending on the path used by the lookup. PR17394. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191726 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach typo correction to look inside of classes like it does namespaces.Kaelyn Uhrain2013-09-261-0/+2
| | | | | | | | | | | | | | | Unlike with namespaces, searching inside of classes requires also checking the access to correction candidates (i.e. don't suggest a correction to a private class member for a correction occurring outside that class and its methods or friends). Included is a small (one line) fix for a bug, that was uncovered while cleaning up the unit tests, where the decls from a TypoCorrection candidate were preserved in new TypoCorrection candidates that are derived (copied) from the old TypoCorrection--notably when creating a new candidate by changing the NestedNameSpecifier associated with the base idenitifer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191449 91177308-0d34-0410-b5e6-96231b3b80d8
* Switch the semantic DeclContext for a block-scope declaration of a function orRichard Smith2013-09-201-1/+3
| | | | | | | | | | | | | | | variable from being the function to being the enclosing namespace scope (in C++) or the TU (in C). This allows us to fix a selection of related issues where we would build incorrect redeclaration chains for such declarations, and fail to notice type mismatches. Such declarations are put into a new IdentifierNamespace, IDNS_LocalExtern, which is only found when searching scopes, and not found when searching DeclContexts. Such a declaration is only made visible in its DeclContext if there are no non-LocalExtern declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191064 91177308-0d34-0410-b5e6-96231b3b80d8
* Use pop_back_val() instead of both back() and pop_back().Robert Wilhelm2013-08-231-2/+1
| | | | | | | No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189112 91177308-0d34-0410-b5e6-96231b3b80d8
* OpenMP: basic support for #pragma omp parallelAlexey Bataev2013-07-191-0/+15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186647 91177308-0d34-0410-b5e6-96231b3b80d8
* Test commitSerge Pavlov2013-05-071-3/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181332 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement DR580: access checks for template parameters of a class template areRichard Smith2013-04-291-9/+9
| | | | | | | performed within the context of that class template. Patch by Ismail Pazarbasi! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180707 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't crash when diagnosing path-constrained protectedJohn McCall2013-02-271-104/+153
| | | | | | | | access to a private member to which we have special access. rdar://12926092 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176146 91177308-0d34-0410-b5e6-96231b3b80d8
* Only suppress instance context if a member is actuallyJohn McCall2013-02-221-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | accessible in its declaring class; otherwise we might fail to apply [class.protected] when considering accessibility in derived classes. Noticed by inspection; <rdar://13270329>. I had an existing test wrong. Here's why it's wrong: Follow the rules (and notation) of [class.access]p5. The naming class (N) is B and the context (R) is D::getX. - 'x' as a member of B is protected, but R does not occur in a member or friend of a class derived from B. - There does exist a base class of B, A, which is accessible from R, and 'x' is accessible at R when named in A because 'x' as a member of A is protected and R occurs in a member of a class, D, that is derived from A; however, by [class.protected], the class of the object expression must be equal to or derived from that class, and A does not derive from D. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175858 91177308-0d34-0410-b5e6-96231b3b80d8
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-3/+3
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169237 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert 'Fix a typo 'iff' => 'if''. iff is an abreviation of if and only if. ↵Sylvestre Ledru2012-09-271-1/+1
| | | | | | See: http://en.wikipedia.org/wiki/If_and_only_if Commit 164766 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164769 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a typo 'iff' => 'if'Sylvestre Ledru2012-09-271-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164766 91177308-0d34-0410-b5e6-96231b3b80d8
* When computing the effective context for access control,John McCall2012-08-241-5/+10
| | | | | | | | make sure we walk up the DC chain for the current context, rather than allowing ourselves to get switched over to the canonical DC chain. Fixes PR13642. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162616 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a few -Wdocumentation warnings.Dmitri Gribenko2012-08-241-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162506 91177308-0d34-0410-b5e6-96231b3b80d8
* Check access to friend declarations. There's a number of differentJohn McCall2012-08-101-19/+38
| | | | | | | | | | | | | | things going on here that were problematic: - We were missing the actual access check, or rather, it was suppressed on account of being a redeclaration lookup. - The access check would naturally happen during delay, which isn't appropriate in this case. - We weren't actually emitting dependent diagnostics associated with class templates, which was unfortunate. - Access was being propagated incorrectly for friend method declarations that couldn't be matched at parse-time. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161652 91177308-0d34-0410-b5e6-96231b3b80d8
* Drop the ASTContext.h include from Stmt.h and fix up transitive users.Benjamin Kramer2012-07-041-2/+4
| | | | | | | | | | | | | | This required moving the ctors for IntegerLiteral and FloatingLiteral out of line which shouldn't change anything as they are usually called through Create methods that are already out of line. ASTContext::Deallocate has been a nop for a long time, drop it from ASTVector and make it independent from ASTContext.h Pass the StorageAllocator directly to AccessedEntity so it doesn't need to have a definition of ASTContext around. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159718 91177308-0d34-0410-b5e6-96231b3b80d8
* Diagnostics cleanup: Fixing \params to match the code.James Dennett2012-06-221-3/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158981 91177308-0d34-0410-b5e6-96231b3b80d8
* Change how we suppress access control in explicit instantiationsJohn McCall2012-05-071-3/+0
| | | | | | | | | | so that we actually accumulate all the delayed diagnostics. Do this so that we can restore those diagnostics to good standing if it turns out that we were wrong to suppress, e.g. if the tag specifier is actually an elaborated type specifier and not a declaration. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156291 91177308-0d34-0410-b5e6-96231b3b80d8
* There is no reason for these methods to be out-of-line.John McCall2012-05-071-12/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156290 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a comment.Francois Pichet2012-04-191-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155107 91177308-0d34-0410-b5e6-96231b3b80d8
* As per John McCall comment:Francois Pichet2012-04-181-4/+4
| | | | | | | | Follow up to r154924: check that we are in a static CMethodDecl to enable the Microsoft bug emulation regarding access to protected member during PTM creation. Not just any static function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154982 91177308-0d34-0410-b5e6-96231b3b80d8
* Emulate a MSVC bug where the creation of pointer-to-member to protected ↵Francois Pichet2012-04-171-0/+7
| | | | | | | | | member of base class is allowed but only from a static function. This fixes a regression when parsing MFC code with clang. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154924 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix the access check performed as part of the determination of whetherJohn McCall2012-04-091-0/+23
| | | | | | | | to define a special member function as deleted so that it properly establishes an object context for the accesses to the base subobject members. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154343 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix several problems with protected access control:John McCall2012-04-071-48/+140
| | | | | | | | | | | | | | | | | | | | | - The [class.protected] restriction is non-trivial for any instance member, even if the access lacks an object (for example, if it's a pointer-to-member constant). In this case, it is equivalent to requiring the naming class to equal the context class. - The [class.protected] restriction applies to accesses to constructors and destructors. A protected constructor or destructor can only be used to create or destroy a base subobject, as a direct result. - Several places were dropping or misapplying object information. The standard could really be much clearer about what the object type is supposed to be in some of these accesses. Usually it's easy enough to find a reasonable answer, but still, the standard makes a very confident statement about accesses to instance members only being possible in either pointer-to-member literals or member access expressions, which just completely ignores concepts like constructor and destructor calls, using declarations, unevaluated field references, etc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154248 91177308-0d34-0410-b5e6-96231b3b80d8
* Unify naming of LangOptions variable/get function across the Clang stack ↵David Blaikie2012-03-111-12/+12
| | | | | | | | | | (Lex to AST). The member variable is always "LangOpts" and the member function is always "getLangOpts". Reviewed by Chris Lattner git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152536 91177308-0d34-0410-b5e6-96231b3b80d8
* Introduce a new initialization entity for lambda captures, andDouglas Gregor2012-02-151-0/+7
| | | | | | | specialize location information and diagnostics for this entity. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150588 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove unused variables.Benjamin Kramer2012-01-201-2/+0
| | | | | | Found by clang's own static analyzer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148542 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove unreachable code in Clang. (replace with llvm_unreachable where ↵David Blaikie2012-01-171-4/+0
| | | | | | appropriate or when GCC requires it) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148292 91177308-0d34-0410-b5e6-96231b3b80d8
* De-virtualize getPreviousDecl() and getMostRecentDecl() when we knowDouglas Gregor2012-01-141-4/+4
| | | | | | | | | | | | | we have a redeclarable type, and only use the new virtual versions (getPreviousDeclImpl() and getMostRecentDeclImpl()) when we don't have that type information. This keeps us from penalizing users with strict type information (and is the moral equivalent of a "final" method). Plus, settle on the names getPreviousDecl() and getMostRecentDecl() throughout. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148187 91177308-0d34-0410-b5e6-96231b3b80d8
* Change the diagnostics which said 'accepted as an extension' to instead sayRichard Smith2011-12-291-1/+1
| | | | | | | | 'is an extension'. The former is inappropriate and confusing when building with -Werror/-pedantic-errors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147357 91177308-0d34-0410-b5e6-96231b3b80d8
* Replace all comparisons between ObjCInterfaceDecl pointers with callsDouglas Gregor2011-12-151-1/+1
| | | | | | | | | to declaresSameEntity(), as a baby step toward tracking forward declarations of Objective-C classes precisely. Part of <rdar://problem/10583531>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146618 91177308-0d34-0410-b5e6-96231b3b80d8
* When we're checking access in a dependent context, don't try to lookDouglas Gregor2011-11-141-0/+3
| | | | | | | at the bases of an undefined class. Fixes <rdar://problem/10438657>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144582 91177308-0d34-0410-b5e6-96231b3b80d8
* Extend IsSimplyAccessible to check for Objective-C instance variableDouglas Gregor2011-11-031-1/+41
| | | | | | | accessibility. Fixes <rdar://problem/3727335>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143635 91177308-0d34-0410-b5e6-96231b3b80d8
* Class can't be null in this contextDouglas Gregor2011-11-031-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143618 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactor Sema::IsSimplyAccessible slightly, to work on a DeclContext rather ↵Douglas Gregor2011-11-031-11/+16
| | | | | | than a class git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143615 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't crash in Sema::IsSimplyAccessible if the declaration is not a C++ ↵Douglas Gregor2011-10-101-1/+1
| | | | | | class member. Fixes PR11108. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141600 91177308-0d34-0410-b5e6-96231b3b80d8