Clang error: cannot decompose ... member B of D (err_decomp_decl_inaccessible_field)
Jump to navigation
Jump to search
Text |
(since 8.0) | ||||||
---|---|---|---|---|---|---|---|
Type | Error | ||||||
Category | Semantic Issue (since 8.0) | ||||||
Internal Id | err_decomp_decl_inaccessible_field (since 8.0) | ||||||
Internal Message | cannot decompose %select{private|protected}0 member %1 of %3 (since 8.0)
| ||||||
Regular Expression | (?:error|fatal error)\: cannot decompose (?:private|protected) member (.*?) of (.*?)
| ||||||
First Commit | 2018-09-26 5c9b3b757623 P0969R0: allow structured binding of accessible members, not only public members. |
Description
Example
Flags | -xc++ -std=c++17
|
|
---|---|---|
Source |
// Class with private member
class C {
private:
int x;
};
int main() {
C c;
// Attempt to decompose private member
auto [a] = c;
}
| |
Compiler Output |
<source>:10:9: error: cannot decompose private member 'x' of 'C' <source>:4:7: note: declared private here |
Clang Internals (17.0.6)
Git Commit Message
P0969R0: allow structured binding of accessible members, not only public members. llvm-svn: 343036
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaAccess.cpp (line 1772)
/// Checks implicit access to a member in a structured binding.
Sema::AccessResult Sema::CheckStructuredBindingMemberAccess(SourceLocation UseLoc, CXXRecordDecl *DecomposedClass, DeclAccessPair Field) {
// ...
Entity.setDiag(diag::err_decomp_decl_inaccessible_field);
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/CXX/dcl.decl/dcl.decomp/p4.cpp
- clang/test/CXX/dcl.decl/dcl.decomp/p4.cpp:28:11: error: cannot decompose protected member 'a' of 'NonPublicMembers::NonPublic1'
- clang/test/CXX/dcl.decl/dcl.decomp/p4.cpp:29:11: error: cannot decompose private member 'a' of 'NonPublicMembers::NonPublic2'
- clang/test/CXX/dcl.decl/dcl.decomp/p4.cpp:31:11: error: cannot decompose private member 'a' of 'NonPublicMembers::NonPublic2'
- clang/test/CXX/dcl.decl/dcl.decomp/p4.cpp:232:18: error: cannot decompose protected member 'y' of 'p0969r0::C'
- clang/test/CXX/dcl.decl/dcl.decomp/p4.cpp:239:15: error: cannot decompose protected member 'y' of 'p0969r0::C'