Clang error: subscript of pointer to ... type B (err_subscript_incomplete_or_sizeless_type)
Jump to navigation
Jump to search
Text |
(since 11.0) | ||||||
---|---|---|---|---|---|---|---|
Type | Error | ||||||
Category | Semantic Issue (since 11.0) | ||||||
Internal Id | err_subscript_incomplete_or_sizeless_type (since 11.0) | ||||||
Internal Message | subscript of pointer to %select{incomplete|sizeless}0 type %1 (since 11.0)
| ||||||
Regular Expression | (?:error|fatal error)\: subscript of pointer to (?:incomplete|sizeless) type (.*?)
| ||||||
First Commit | 2019-12-21 931fcd3ba011 [WebAssembly] Improve clang diagnostics for wasm attributes |
Description
Example
Flags | -xc++
|
|
---|---|---|
Source |
#include <memory>
struct S; // Forward declaration
int main() {
std::unique_ptr<S[]> p(new S[10]); // Allocation
auto o = p[0]; // Error: S is incomplete
}
| |
Compiler Output |
<source>:4:30: error: allocation of incomplete type 'S' <source>:2:8: note: forward declaration of 'S' <source>:5:8: error: variable has incomplete type 'S' <source>:2:8: note: forward declaration of 'S' In file included from <source>:1: In file included from /opt/compiler-explorer/gcc-13.2.0/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/memory:78: /opt/compiler-explorer/gcc-13.2.0/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/bits/unique_ptr.h:725:9: error: subscript of pointer to incomplete type 'S' <source>:5:13: note: in instantiation of member function 'std::unique_ptr<S[]>::operator[]' requested here <source>:2:8: note: forward declaration of 'S' |
Clang Internals (17.0.6)
Git Commit Message
[WebAssembly] Improve clang diagnostics for wasm attributes This patch addresses the review comments on r352930: - Removes redundant diagnostic checking code - Removes errnoneous use of diag::err_alias_is_definition, which turned out to be ineffective anyway since functions can be defined later in the translation unit and avoid detection. - Adds a test for various invalid cases for import_name and import_module. Differential Revision: https://reviews.llvm.org/D59520
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/SemaExpr.cpp (line 6025)
ExprResult Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, Expr *Idx, SourceLocation RLoc) {
// ...
} else if (!ResultType->isDependentType() && !ResultType.isWebAssemblyReferenceType() && RequireCompleteSizedType(LLoc, ResultType, diag::err_subscript_incomplete_or_sizeless_type, BaseExpr))
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/Sema/crash-invalid-array.c
- clang/test/Sema/crash-invalid-array.c:13:9: error: subscript of pointer to incomplete type 'int[]'