aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaAccess.cpp
AgeCommit message (Collapse)AuthorFilesLines
11 days[Clang][AST][NFC] (`RecordDecl` -> `CXXRecordDecl`)`::isInjectedClassName` ↵Yanzuo Liu1-1/+2
(#148195) Move `RecordDecl::isInjectedClassName` to `CXXRecordDecl::isInjectedClassName`. C language doesn't have the term "injected class name". Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
2025-05-25[Sema] Remove unused includes (NFC) (#141419)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-01[clang] Add scoped enum support to `StreamingDiagnostic` (#138089)Vlad Serebrennikov1-6/+3
This patch adds templated `operator<<` for diagnostics that pass scoped enums, saving people from `llvm::to_underlying()` clutter on the side of emitting the diagnostic. This eliminates 80 out of 220 usages of `llvm::to_underlying()` in Clang. I also backported `std::is_scoped_enum_v` from C++23.
2025-03-21Reland: [clang] preserve class type sugar when taking pointer to member ↵Matheus Izvekov1-8/+18
(#132401) Original PR: #130537 Originally reverted due to revert of dependent commit. Relanding with no changes. This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the base class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntatically, and they represent the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements.
2025-03-20Revert "Reland: [clang] preserve class type sugar when taking pointer to ↵Matheus Izvekov1-18/+8
member" (#132280) Reverts llvm/llvm-project#132234 Needs to be reverted due to dependency. This blocks reverting another PR, see here: https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-20Reland: [clang] preserve class type sugar when taking pointer to member ↵Matheus Izvekov1-8/+18
(#132234) Original PR: #130537 Reland after updating lldb too. This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the base class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntatically, and they represent the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements.
2025-03-20Revert "[clang] improve class type sugar preservation in pointers to ↵Matheus Izvekov1-18/+8
members" (#132215) Reverts llvm/llvm-project#130537 This missed updating lldb, which we didn't notice due to lack of pre-commit CI.
2025-03-20[clang] improve class type sugar preservation in pointers to members (#130537)Matheus Izvekov1-8/+18
This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntactically, and it also represents the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements, and removing some duplications, for example CheckBaseClassAccess is deduplicated from across SemaAccess and SemaCast.
2025-03-19[clang] NFC: Unify implementations of CheckMemberPointerConversion (#131966)Matheus Izvekov1-15/+12
This deduplicates the implementation of CheckMemberPointerConversion accross SemaCast and SemaOverload.
2025-03-17[Clang] Fix an incorrect assumption on getTemplatedDecl() (#131559)Younan Zhang1-2/+2
Since a68d20e98, we've been calling HandleDelayedAccessCheck() for concept declarations when the declaration contains invalid member accesses. However, a concept declaration is TemplateDecl such that doesn't contain any TemplatedDecl. Fixes https://github.com/llvm/llvm-project/issues/131530
2024-11-16[Sema] Remove unused includes (NFC) (#116461)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-07-01[clang][NFC] Move documentation of `Sema` functions into `Sema.h`Vlad Serebrennikov1-39/+0
This patch moves documentation of `Sema` functions from `.cpp` files to `Sema.h` when there was no documentation in the latter, or it can be trivially subsumed. More complicated cases when there's less trivial divergence between documentation attached to declaration and the one attached to implementation are left for a later PR that would require review. It appears that doxygen can find the documentation for a function defined out-of-line even if it's attached to an implementation, and not declaration. But other tools, e.g. clangd, are not as powerful. So this patch significantly improves autocompletion experience for (at least) clangd-based IDEs.
2024-05-10[Clang][Sema] access checking of friend declaration should not be delayed ↵Qizhi Hu1-5/+25
(#91430) attempt to fix https://github.com/llvm/llvm-project/issues/12361 Consider this example: ```cpp class D { class E{ class F{}; friend void foo(D::E::F& q); }; friend void foo(D::E::F& q); }; void foo(D::E::F& q) {} ``` The first friend declaration of foo is correct. After that, the second friend declaration delayed access checking and set its previous declaration to be the first one. When doing access checking of `F`(which is private filed of `E`), we put its canonical declaration(the first friend declaration) into `EffectiveContext.Functions`. Actually, we are still checking the first one. This is incorrect due to the delayed checking. Creating a new scope to indicate we are parsing a friend declaration and doing access checking in time.
2024-04-12[clang][NFC] Refactor `CXXSpecialMember`Vlad Serebrennikov1-5/+9
In preparation for `SemaCUDA`, which requires this enum to be forward-declarable.
2023-05-18[NFC][Clang][Coverity] Fix Static Code Analysis Concerns with copy without ↵Manna, Soumi1-0/+10
assign This patch adds copy/move assignment operator to the class which has user-defined copy/move constructor. Reviewed By: tahonermann, NoQ, aaronpuchert Differential Revision: https://reviews.llvm.org/D150411
2023-05-01[clang] Fix overly aggressive lifetime checks for parenthesized aggregate ↵Alan Zhao1-1/+2
initialization Before this patch, initialized class members would have the LifetimeKind LK_MemInitializer, which does not allow for binding a temporary to a reference. Binding to a temporary however is allowed in parenthesized aggregate initialization, even if it leads to a dangling reference. To fix this, we create a new EntityKind, EK_ParenAggInitMember, which has LifetimeKind LK_FullExpression. This patch does *not* attempt to diagnose dangling references as a result of using this feature. This patch also refactors TryOrBuildParenListInitialization(...) to accomodate creating different InitializedEntity objects. Fixes #61567 [0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D148274
2023-01-11Perform access checking to private members in simple requirement.Utkarsh Saxena1-0/+2
> Dependent access checks. Fixes: https://github.com/llvm/llvm-project/issues/53364 We previously ignored dependent access checks to private members. These are visible only to the `RequiresExprBodyExpr` (through `PerformDependentDiagnositcs`) and not to the individual requirements. --- > Non-dependent access checks. Fixes: https://github.com/llvm/llvm-project/issues/53334 Access to members in a non-dependent context would always yield an invalid expression. When it appears in a requires-expression, then this is a hard error as this would always result in a substitution failure. https://eel.is/c++draft/expr.prim.req#general-note-1 > Note 1: If a requires-expression contains invalid types or expressions in its requirements, and it does not appear within the declaration of a templated entity, then the program is ill-formed. — end note] > If the substitution of template arguments into a requirement would always result in a substitution failure, the program is ill-formed; no diagnostic required. The main issue here is the delaying of the diagnostics. Use a `ParsingDeclRAIIObject` creates a separate diagnostic pool for diagnositcs associated to the `RequiresExprBodyDecl`. This is important because dependent diagnostics should not be leaked/delayed to higher scopes (Eg. inside a template function or in a trailing requires). These dependent diagnostics must be attached to the `DeclContext` of the parameters of `RequiresExpr` (which is the `RequiresExprBodyDecl` in this case). Non dependent diagnostics, on the other hand, should not delayed and surfaced as hard errors. Differential Revision: https://reviews.llvm.org/D140547
2022-02-08[C++2b] Implement multidimentional subscript operatorCorentin Jabot1-8/+27
Implement P2128R6 in C++23 mode. Unlike GCC's implementation, this doesn't try to recover when a user meant to use a comma expression. Because the syntax changes meaning in C++23, the patch is *NOT* implemented as an extension. Instead, declaring an array with not exactly 1 parameter is an error in older languages modes. There is an off-by-default extension warning in C++23 mode. Unlike the standard, we supports default arguments; Ie, we assume, based on conversations in WG21, that the proposed resolution to CWG2507 will be accepted. We allow arrays OpenMP sections and C++23 multidimensional array to coexist: [a , b] multi dimensional array [a : b] open mp section [a, b: c] // error The rest of the patch is relatively straight forward: we take care to support an arbitrary number of arguments everywhere.
2021-10-11[Sema] Use llvm::is_contained (NFC)Kazu Hirata1-1/+1
2021-06-07[clang][NFC] Break out BaseUsingDecl from UsingDeclNathan Sidwell1-10/+11
This is a pre-patch for adding using-enum support. It breaks out the shadow decl handling of UsingDecl to a new intermediate base class, BaseUsingDecl, altering the decl hierarchy to def BaseUsing : DeclNode<Named, "", 1>; def Using : DeclNode<BaseUsing>; def UsingPack : DeclNode<Named>; def UsingShadow : DeclNode<Named>; def ConstructorUsingShadow : DeclNode<UsingShadow>; Differential Revision: https://reviews.llvm.org/D101777
2021-05-19Treat implicit deduction guides as being equivalent to theirRichard Smith1-0/+14
corresponding constructor for access checking purposes.
2020-11-13[clang] Fix an assertion crash in delayed access check.Haojian Wu1-1/+2
`TD->getTemplatedDecl()` might not be a DeclContext variant, which can trigger an assertion inside `isa<>`. Differential Revision: https://reviews.llvm.org/D91380
2019-12-10[c++20] Delete defaulted comparison functions if they would invoke anRichard Smith1-10/+13
inaccessible comparison function.
2019-10-07Sema - silence static analyzer getAs<> null dereference warnings. NFCI.Simon Pilgrim1-1/+1
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<> directly and if not assert will fire for us. llvm-svn: 373911
2019-10-03Silence static analyzer getAs<RecordType> null dereference warnings. NFCI.Simon Pilgrim1-2/+2
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<RecordType> directly and if not assert will fire for us. llvm-svn: 373584
2019-03-31Range-style std::find{,_if} -> llvm::find{,_if}. NFCFangrui Song1-2/+1
llvm-svn: 357359
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-05[CodeComplete] Fix a crash in access checks of inner classesIlya Biryukov1-2/+0
Summary: The crash was introduced in r348135. Reviewers: kadircet Reviewed By: kadircet Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55260 llvm-svn: 348387
2018-12-03[CodeComplete] Cleanup access checking in code completionIlya Biryukov1-9/+20
Summary: Also fixes a crash (see the added 'accessibility-crash.cpp' test). Reviewers: ioeric, kadircet Reviewed By: kadircet Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55124 llvm-svn: 348135
2018-09-25P0969R0: allow structured binding of accessible members, not only public ↵Richard Smith1-0/+16
members. llvm-svn: 343036
2018-07-30Remove trailing spaceFangrui Song1-18/+18
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-07-19[CodeComplete] Fix accessibilty of protected members from base class.Eric Liu1-12/+15
Summary: Currently, protected members from base classes are marked as inaccessible when completing in derived class. This patch fixes the problem by setting the naming class correctly when looking up results in base class according to [11.2.p5]. Reviewers: aaron.ballman, sammccall, rsmith Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49421 llvm-svn: 337453
2018-05-09Remove \brief commands from doxygen comments.Adrian Prantl1-1/+1
This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
2018-02-16Revert r325321 "[Sema] Take into account the current context when checking the"Hans Wennborg1-5/+0
This broke the Chromium build, see https://crbug.com/813017 > accessibility of a class member. > > This fixes PR32898. > > rdar://problem/33737747 > > Differential revision: https://reviews.llvm.org/D36918 llvm-svn: 325335
2018-02-16[Sema] Take into account the current context when checking theAkira Hatanaka1-0/+5
accessibility of a class member. This fixes PR32898. rdar://problem/33737747 Differential revision: https://reviews.llvm.org/D36918 llvm-svn: 325321
2016-06-28P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:Richard Smith1-9/+17
Replace inheriting constructors implementation with new approach, voted into C++ last year as a DR against C++11. Instead of synthesizing a set of derived class constructors for each inherited base class constructor, we make the constructors of the base class visible to constructor lookup in the derived class, using the normal rules for using-declarations. For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived class that tracks the requisite additional information. We create shadow constructors (not found by name lookup) in the derived class to model the actual initialization, and have a new expression node, CXXInheritedCtorInitExpr, to model the initialization of a base class from such a constructor. (This initialization is special because it performs real perfect forwarding of arguments.) In cases where argument forwarding is not possible (for inalloca calls, variadic calls, and calls with callee parameter cleanup), the shadow inheriting constructor is not emitted and instead we directly emit the initialization code into the caller of the inherited constructor. Note that this new model is not perfectly compatible with the old model in some corner cases. In particular: * if B inherits a private constructor from A, and C uses that constructor to construct a B, then we previously required that A befriends B and B befriends C, but the new rules require A to befriend C directly, and * if a derived class has its own constructors (and so its implicit default constructor is suppressed), it may still inherit a default constructor from a base class llvm-svn: 274049
2016-06-01[Sema] Fix incorrect enum token namespaceEtienne Bergeron1-3/+3
Summary: This patch fix the scoping of enum literal. They were not resolving to the right type. It was not causing any problem as one is a copy of the other one. The literal in the switch are resolving to Sema.h:5527 ``` enum AccessResult { AR_accessible, AR_inaccessible, AR_dependent, AR_delayed }; ``` Instead of SemaAccess.cpp:27 ``` /// A copy of Sema's enum without AR_delayed. enum AccessResult { AR_accessible, AR_inaccessible, AR_dependent }; ``` This issue was found by a new clang-tidy check (still on-going). Reviewers: rsmith, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D20773 llvm-svn: 271431
2016-03-23Make SemaAccess smarter about determining when a dependent class mightRichard Smith1-10/+5
instantiate to match a friend class declaration. It's still pretty dumb, though. llvm-svn: 264189
2016-03-08Fix crash in access check for aggregate initialization of base classes. It'sRichard Smith1-1/+5
not obvious how to access-check these, so pick a conservative rule until we get feedback from CWG. llvm-svn: 262966
2015-08-12-Wdeprecated: SavedInstanceContext is returned by value but isn't really ↵David Blaikie1-3/+8
copyable, but it can be made movable llvm-svn: 244826
2015-07-29[SemaAccess] Provide meaningful message when we hit llvm_unreachable().Davide Italiano1-1/+1
llvm-svn: 243571
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko1-2/+2
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko1-2/+2
The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
2015-05-17[Sema] Improve llvm_unreachable() message.Davide Italiano1-1/+1
llvm-svn: 237532
2014-12-17Don't assume friended C++ method decls have qualifiersReid Kleckner1-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. llvm-svn: 224471
2014-05-28Consolidate some note diagnosticsAlp Toker1-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. llvm-svn: 209728
2014-05-26[C++11] Use 'nullptr'. Sema edition.Craig Topper1-12/+13
llvm-svn: 209613
2014-03-13[C++11] Replacing CXXRecordDecl iterators friend_begin() and friend_end() ↵Aaron Ballman1-4/+1
with iterator_range friends(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203815
2014-03-13[C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with ↵Aaron Ballman1-9/+5
iterator_range bases(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203803
2014-03-07[C++11] Replacing DeclBase iterators decls_begin() and decls_end() with ↵Aaron Ballman1-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. llvm-svn: 203278